You are viewing the documentation for Blueriq 16. Documentation for other versions is available in our documentation directory.
This page applies to you if you are interested in creating a custom implementation for consuming Aggregate events from the Customerdata service queue. (Example is Java with Spring)
This feature is available from Customerdata Service version 2.0.0 and up.
How to attach a custom consumer to the queue
To create a custom consumer of the queue we need a running spring application which has a connection to the queue.
Dependencies
Create a Spring application which has the following dependencies:
... <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-dependencies</artifactId> <version>Chelsea.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency> </dependencies> ...
Properties
Set the following settings in application.properties to create a connection to the queue. In this example username/password guest is used, you can create an other user. For more information, please check Security.
spring.cloud.stream.bindings.input.destination = CustomerDataService spring.cloud.stream.bindings.input.group = CustomerDataService spring.cloud.stream.bindings.input.binder = rabbit1 spring.cloud.stream.binders.rabbit1.type = rabbit spring.cloud.stream.binders.rabbit1.environment.spring.rabbitmq.host = localhost spring.cloud.stream.binders.rabbit1.environment.spring.port = 15672 spring.cloud.stream.binders.rabbit1.environment.spring.username = guest spring.cloud.stream.binders.rabbit1.environment.spring.password = guest
Code
The following piece of example code will consume all events on the queue and print the payload (see function loggerSink
)
@SpringBootApplication @EnableBinding(Sink.class) @EnableAutoConfiguration public class RabbitConsumerApplication { public static void main(String[] args) { SpringApplication.run(RabbitConsumerApplication.class, args); } @StreamListener(Sink.INPUT) public void loggerSink(String payload) { System.out.println("Received: " + payload); } }
Test if it works
Now you got a consumer connected to the queue, we need to test if it all works as expected.
Do the following to test if it all works
- Start the Spring application.
- Open the RabbitMQ management interface and navigate to the CustomerDataService queue that was previously created.
- On this page, a message can be created and put on the queue which, if all is configured well, should be picked up by the spring application. Enter the following:
- Press 'Publish message' and check the log of the application, the message should be printed.