WSO2: Publish & Consume Message from RabbitMQ

WSO2: Publish & Consume Message from RabbitMQ

Publish and consume messages from RabbitMQ is a truly remarkable feat of modern distributed systems engineering. RabbitMQ, a powerful open-source message broker, enables the seamless exchange of data between disparate applications and services, empowering developers to build highly scalable, fault-tolerant, and decoupled architectures. The ability to publish messages to RabbitMQ and then consume them on-demand is a testament to the sophistication and flexibility of this technology.

By acting as an intermediary between producers and consumers, RabbitMQ ensures reliable message delivery, message prioritization, and message persistence, even in the face of network failures or system outages. The process of publishing a message to RabbitMQ involves crafting the message payload, specifying the appropriate exchange and routing keys, and then entrusting the broker to handle the message’s distribution to the intended consumers.

On the other side, consuming messages from RabbitMQ allows applications to receive and process the data in a highly efficient and asynchronous manner, enabling them to scale and respond to varying workloads with ease. The elegance and power of this publish-subscribe messaging paradigm, facilitated by RabbitMQ, is truly awe-inspiring. It represents a quantum leap in the way modern software systems communicate and collaborate, unlocking new levels of flexibility, resilience, and performance that were once unimaginable.

Walkthrough:

Create new project in Integration studio >> File >> New >> Integration project and give the Project name. 

Right-click on inbound-endpoints and navigate to New >> Inbound Endpoint. Select Create a New Inbound Endpoint and click Next.

  • Inbound Endpoint Name
  • Inbound Endpoint Creation Type: HTTP
  • Click Finish

Double-click the Inbound Endpoint icon to open the Properties tab.

Creating a Sequence Artifact:

  • Right-click the ESB Config project and go to New → Sequence to open the New Sequence Artifact dialog box
  • Select Create New Sequences as  Response_Seq, Error_Seq  and click Next.
  • In the Save Sequences field, specify the location to save the sequence.
  • Click Finish

Double-click the Response_Seq, Error_Seq mediator to access and review the added logic.

  • Drag and drop the Log mediator to log information about messages or events passing through.

Click on Inbound-Endpoint

  • Drag and drop the Defined Sequences

Creating Proxy Services Artifact:

  • Right-click the Proxy-services àNew à Proxy Service à Create A new proxy Service à Next.
  • Proxy Service Name
  • Proxy Service Type: Custom Proxy
  • Select the Transports: RabbitMQ

Drag and drop the property mediator.

Configure the properties:

Property Name: OUT_ONLY

Propert Data Type: String

Property Action: set

Property Scope: default

Value : Expression: true

Drag and drop the Call Mediator, and Drag and drop the Address Endpoint

  • Format: LEAVE_AS_IS
  • URL: rabbitmq:/?rabbitmq.connection.factory=AMQPConnectionFactory&rabbitmq.queue.name=DemoQueue

Drag and drop the Respond Mediator

Build and run the artifacts:

  • Right-click RabbitMQProjectConfigsCompositeExporter and click Export Project Artifacts and Run

You will see the following dialog box. Select the RabbitMQProjectConfigs folder in the artifact list select the RabbitMQProxyService and click Finish.

In Runtime Services, as shown in below image WSDL URL is generated.

Open the Postman application

Postman displays the response data sent from the server in the lower pane.

Navigate to http://127.0.0.1:15672/#/queues/%2F/DemoQueue

  • Successfully publish the message, as shown in below figure

After opening Get messages panel, here in Messages textbox you can enter the count of messages to read from the queue and click on Get Message(s) button to read messages from studio.

Following is the image after reading a message from queue in RabbitMQ web management.

This is how we can read a messages from studio

The console will display a consume message on a RabbitMQ.

For more info, Please write to [email protected].