Send Receive Message via RabbitMQ using Spring Cloud Stream - vidyasekaran/current_learning GitHub Wiki
Spring Cloud Stream internally uses spring integration as per udemy course - Spring microservices indepth using domain driven design
I learnt to send and receive message between 2 microservices i.e producer and receiver thru RabbitMQ using spring cloud stream D:\Udemy_springms_domaindrivendesign\micro-2020-april\micro-2020-april\microws2020\
Steps to Setup RabbitMQ
https://www.javainuse.com/misc/rabbitmq-hello-world
Installed rabbitmq using choco start/stop using Windows -> RabbitMQ Service Start-Stop http://localhost:15672 (guest/guest)
for Producer you need to create exchange and queue Login RabbitMq - go to exchange and add new exachange : helloexchange go to queue - add new queue - helloq
Producer and Consumer Code (workspace - E:\event_driven_microservice)
Below - publishes a message to hellooutchannel D:\Udemy_springms_domaindrivendesign\micro-2020-april\micro-2020-april\microws2020\01-message-producer-start
spring: cloud: stream: bindings: hellooutchannel: destination: helloexchange #group: router binder: rabbit1
Below - receives message from helloexchange and publishes a message in hellooutchannel (adapterexchange) D:\Udemy_springms_domaindrivendesign\micro-2020-april\micro-2020-april\microws2020\01-message-consumer-start
spring: cloud: stream: bindings: helloinchannel: destination: helloexchange group: router binder: rabbit1
hellooutchannel:
destination: adapterexchange
group: adapter
binder: rabbit1
@StreamListener("helloinchannel") public void processGreeting(Greeting greeting) { greeting.setMessage(greeting.getMessage()+"Transformation done"); System.err.println("Recevied Greeting with message ===="+greeting.getMessage()); source.myoutput().send(MessageBuilder.withPayload(greeting).build());
}
Below - receives message from helloinchannel (adapterexchange)
Created an exchange in rabbitmq named - adapterexchange and a queue adapter D:\Udemy_springms_ddd\micro-2020-april\micro-2020-april\microws2020\01-message-consumer-start -2nd
spring: cloud: stream: bindings: helloinchannel: destination: adapterexchange group: adapter binder: rabbit1
@StreamListener("helloinchannel")
public void processGreeting(Greeting greeting) {
System.out.println("Recevied Greeting with message ===="+greeting.getMessage());
}
Configure producer/consumer based on document below. Document Steps - D:\Udemy_springms_domaindrivendesign\micro-2020-april\micro-2020-april\micro-lab-docs\01-mdm.doc