Demo repo for rabbit-mq session.
-
Running rabbit-mq in local - docker-compose up
Rabbit mq ui - http://localhost:15672
Username - guest
Password - guest -
Run producer
cd producer && ./gradlew bootRun
-
Publish a message using
POST http://localhost:8081/order/create
(this is needed because queues will only be created after the request to rabbit-mq) -
Run consumer
cd consumer && ./gradlew bootRun
-
See the logs in consumer service logs
Publishing messages -
- Generate CreateOrder event - POST http://localhost:8081/order/create
- Generate OrderLog event - POST http://localhost:8081/order/log
It has a working example for direct exchange
Exchange -
- OrderCreatedEvent
@Bean("OrderCreatedEvent")
fun orderCreatedEventDirectExchange(): Exchange = ExchangeBuilder.directExchange("OrderCreatedEvent").build()
Queues -
- order.create.queue
- order.create.log.queue
@Bean("order.create.queue")
fun orderCreateQueue(): Queue = QueueBuilder.durable("order.create.queue")
.build()
@Bean("order.create.log.queue")
fun orderCreateLogQueue(): Queue = QueueBuilder.durable("order.create.log.queue")
.build()
Bindings -
@Bean
fun orderCreateQueueBinding(
@Qualifier("order.create.queue") queue: Queue,
@Qualifier("OrderCreatedEvent") exchange: Exchange
): Binding =
BindingBuilder.bind(queue).to(exchange).with("order.create").noargs()
@Bean
fun orderCreateLogQueueBinding(
@Qualifier("order.create.log.queue") queue: Queue,
@Qualifier("OrderCreatedEvent") exchange: Exchange
): Binding =
BindingBuilder.bind(queue).to(exchange).with("order.create.log").noargs()