JMS / RabbitMQ

RabbitMQ - Messaging Broker 







 




RabbitMQ Setup:


Steps to download and install RabbitMQ for Windows: https://www.rabbitmq.com/install-windows-manual.html 

Download the MQ zip file and supported Erlang exe from the above link. 

1. Install Erlang, set ERLANG_HOME and path in Environment variable. 

ERLANG_HOME: C:\Program Files\erl-24.0.4 
PATH: C:\Program Files\erl-24.0.4\bin

 2. Enable Rabbitmq management: 


C:\Program Files\rabbitmq_server-3.9.1\sbin>rabbitmq-plugins.bat enable rabbitmq_management

3. Execute the batch file to start rabbitMQ 

C:\Program Files\rabbitmq_server-3.9.1\sbin\rabbitmq-server

4. Launch the URL in the browser http://localhost:15672/  (guest/guest)



Types Of Exchanges:

  • Direct
  • Fanout
  • Topic
  • Headers

Direct:

The message will be redirected by Exchange to the specific queue based on the Key.

Do the below steps in RabbitMQ management:

1. Create Exchange (Type=direct)
2. Create Queues
3. Bind the queues with Exchange with routing key



Fanout:

The message will be redirected by Exchange to all the queues bind with it. 


Do the below steps in RabbitMQ management:

1. Create Exchange (Type=fanout)
2. Bind the queues with Exchange with routing key


Topic:


* One word
# Any number of word


1. Create Exchange (Type=topic)
2. Bind the queues with Exchange with routing key



Headers:



x-match=all   : it's like AND condition
x-match=any : it's like OR condition


1. Create Exchange (Type=headers)
2. Bind the queues with Exchange with arguments (refer to the below screenshot)



Default exchange:


Any message sending directly to queue, will be routed through Default Exchange which will be created by RabbitMQ by default. 

    channel.basicPublish("", "Queue-1", null, message.getBytes());

Pass the exchange name as empty. 


Exchange to Exchange Binding:






RabbitMQ with SpringBoot

RabbitMQ Template - for publishing message
RabbitMQ Listener  - for consumer


All the Example codes are available here https://github.com/vthangar0202/RabbitMQ




Comments

Popular posts from this blog

Java Design Patterns