DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Reducing Alert Fatigue in the SOC Using Correlation Rules and Detection-as-Code
  • Scalable Support Request Analysis Using Embeddings, HDBSCAN, and Tiny LLMs
  • KV Cache Implementation Inside vLLM
  • When Retries Become a Denial-of-Wallet

Trending

  • Stop Fine-Tuning Everything: A Decision Framework for Model Adaptation
  • Designing Secure REST APIs With Spring Boot
  • Coordinating AI Agents With AWS SQS: A Practical Queue-Based Architecture
  • Building a Config-Driven SOAP/REST Integration Layer: One Service, Many Protocols

Request-Reply Pattern Using Correlation ID Mule4 Using ActiveMQ

A software architect and developer shows us how to use ActiveMQ to create and exchange a request/reply queue and then how to test that the exchange worked.

By 
Sadik Ali user avatar
Sadik Ali
·
Dec. 31, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
12.0K Views

Join the DZone community and get the full member experience.

Join For Free

Agenda

  • Introduction.
  • Create a request/reply queue.
  • Create and an exchange and bind it with the request-queue.
  • Develop a Mule 4 flow to comply with the correlation-id.

Introduction

When the requester generates a request message, it assigns a request ID to the request—an identifier that is distinct from these for all other presently outstanding requests, that is, requests that do not yet have replies. When the replier treats the request, it keeps the request ID and adds that ID to the reply as a correlation ID. When the requester processes the reply, it uses the correlation ID to identify which request the reply is for. This is called a Correlation Identifier because of the way the caller uses the identifier to associate (i.e., match, show the relationship) each reply to the request that generated it.

Create a Request/Reply Queue

Request queue is created: address-queue.

Reply queue is created: addressreply-queue.

Create an Exchange and Bind it With Request-Queue

Now bind it with the request queue as shown below.

Code for the Request-Reply Pattern in Mule 4

XML
 




x
38


 
1
<?xml version="1.0" encoding="UTF-8"?>
2

          
3
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
4
    xmlns:validation="http://www.mulesoft.org/schema/mule/validation"
5
    xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp"
6
     xmlns:http="http://www.mulesoft.org/schema/mule/http" 
7
     xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
8
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
9
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
10
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd
11
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
12
    <flow name="requestor-flow" doc:id="d8e92a34-d34d-4e1a-bce3-7405b9010241" >
13
        <http:listener doc:name="Listener" doc:id="88476dbb-04af-429d-83f3-20714be8d406" config-ref="HTTP_Listener_config" path="/address">
14
            <http:error-response statusCode="400" />
15
        </http:listener>
16
        <set-variable doc:name="Save Payload" doc:id="290893b4-3248-45ab-a168-73359123e11d" variableName="payload" value="#[payload]"/>
17
        <logger level="INFO" doc:name="Logger" doc:id="ccde0f6d-cc70-4b05-a68c-60f644381b1e" message="one correlation :  --- #[correlationId]"/>
18
        <amqp:publish-consume doc:name="Request Reply using Correlation ID" doc:id="d7d6a1ee-f3e2-4376-ac6f-68e89c6817e7" config-ref="AMQP_Config" exchangeName="${rabbitmq.addexchange}" sendCorrelationId="ALWAYS" deliveryMode="PERSISTENT">
19
            <amqp:message >
20
                <amqp:body ><![CDATA[#[payload.event.eventPayload.address.address1]]]></amqp:body>
21
                <amqp:properties replyTo="${rabbitmq.addressreplyqueue}"/>
22
            </amqp:message>
23
        </amqp:publish-consume>
24
        <ee:transform doc:name="Update and Send Response" doc:id="bfeeab27-6f01-4ea1-a46a-1a65c5aa0021" >
25
            <ee:message >
26
                <ee:set-payload ><![CDATA[%dw 2.0
27
output application/json
28
var outputJson = vars.payload
29
---
30
outputJson mapObject (value, key) -> (key):
31
        value  ++ payload]]></ee:set-payload>
32
            </ee:message>
33
        </ee:transform>
34
        <logger level="INFO" doc:name="Logger" doc:id="658ced7a-1b65-4094-ae99-4c97f4e7b59c" message="three correlation :  --- #[correlationId]"/>
35
    
36
</flow>
37
</mule>
38

          


Test the Application

Validate the Correlation ID in the Logs

Here, we can validate how our request moved from the request to reply queue with the correlation id. It helps to identify the request and respective requests.

Correlation (projective geometry) Requests

Opinions expressed by DZone contributors are their own.

Related

  • Reducing Alert Fatigue in the SOC Using Correlation Rules and Detection-as-Code
  • Scalable Support Request Analysis Using Embeddings, HDBSCAN, and Tiny LLMs
  • KV Cache Implementation Inside vLLM
  • When Retries Become a Denial-of-Wallet

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook