Exchange - where the messages are published
Queue - where the messages are consumed
Binding - distribution rules from exchanges to queues
There are a lot of client implementations : Java, .Net, PHP, Go, Ruby, Python, Scala, Perl...
In Java, several possibilities :
Official docker image available on Docker Hub
docker run --rm -d --hostname my-rabbit --name rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management
Management console : http://localhost:15672
Built on top of Spring Boot and Spring Integration, it is used to build easily message/event-driven microservices.
It supports bindings with RabbitMQ and Apache Kafka brokers.
It allows minimal configuration and connexion code, thanks to annotations, to focus on business code.
@EnableBinding on class declaration
@StreamListener on method declaration to consume messages
@SendTo on method declaration (+ return type) to publish messages
@EnableBinding(Sink.class)
public class MessageHandler {
@StreamListener(Sink.INPUT)
public void handle(MyEvent myEvent) {
// do what you have to do with the message
...
}
}
- Start RabbitMQ ! Play with the UI localhost:15672
- Create the 1st project ShippingService which will consume some order events. (Can use Spring Initializr through https://start.spring.io or directly in IDE)
This one is publisher and consumer : a processor (source + sink)
It should connect to same exchange than shipping-service
You can extend Processor interface...
It needs to code the message sending
@Autowired
private BinderAwareChannelResolver resolver;
...
resolver
.resolveDestination("nameofchannel")
.send(MessageBuilder.withPayload(messagePayload).build());
@StreamListener(target=Processor.INPUT, condition = "headers['bu-id']=='1'")
public void receiveForBu1() {
// ...
}
@StreamListener(target=Processor.INPUT, condition = "headers['bu-id']!='1'")
public void receiveForBuNot1() {
// ...
}
This is not compatible with @SendTo annotation ☹