Messaging - RabbitMQ - JSON Payload based correlation scheme explained with an Example

Document created by Sankar Natarajan Employee on Mar 5, 2019Last modified by Sankar Natarajan Employee on Mar 5, 2019
Version 2Show Document
  • View in full screen mode

Scenario: Customer uses AppTest to test their backend service that has RabbitMQ as broker. JSON payload is used for request and response

Main Issues: 

                1. Customer wants to use an ID attribute in request and response for Correlation. Customer needs help and direction on how to set such a correlation scheme. Our documentation severely lack examples on this front

                2. RabbitMQ Receive step reads all the messages in a given queue if 'Correlation Scheme' flag is checked though it returns the correct message

In this post I am attempting to answer the first question, I will explain part 2 in another separate post.

Setting up JSON PAYLOAD CORRELATION SCHEME with RabbitMQ

 

Request
Response
Requirement

{
"Type": "Request", 
"provisioningOrderId": "MRXFDJJDOC01",
"salesInfo": {
"senderSystemId": "METRO",
"salesChannel": "METRO",
"applicationId": "AAM",
"partnerOrderld": "000055106001"
},
"transactionType": "UPDATEFEATURE",
"creationTime": "2019-02-21T10:49:54.689-0",
"customerProfile": {
"customerId": "CMPCS60216318051",
"firstName": "John",
"familyName": "Doe",
"middleName": "ABC",
"preferredLanguage": "en",
"securityProfileId": "760216819051",
"accounts": [
{
"accountNumber": "51HPC560216811",
"billingType": "PREPAID",
"biliCycleDay": 8
}
]
}
}

{
"Type":"Response", 
"provisioningOrderId": "MRXFDJJDOC01",
"salesInfo": {
"senderSystemId": "METRO",
"salesChannel": "METRO",
"applicationId": "AAM",
"partnerOrderld": "000055106001"
},
"transactionType": "UPDATEFEATURE",
"creationTime": "2019-02-28T10:49:54",
"provisioningLines": [
{
"phoneNumber": "2816873852",
"lifeNumber": "0091260790980934304",
"brand": "ABBCC",
"ssid": "35422142475211",
"ssip": "35422142475211",
"details": [
{
"detailsId": "WW1",
"actionCode": "ADD",
"size": "5"
},
],
"lineType": "AG",
"portIndication": false
}
}

Customer wants to use the field 'provisioningOrderId' as correlation scheme as the backend service returns the same value in response

The screenshot below shows how to configure RabbitMQ Send/Receive step. It is important to understand how this works. Read the text below the screenshot:

 

  1. First things first, correlation scheme is always defined as part of 'Receive Step'
  2. 'RabbitMQ Payload's is used for correlation scheme since the 'correlation' field is part of the JSON Payload
  3. Note that our tool has deep functionliaty as we have the option to generate a correlation ID by the tool, (an UUID). If you wish Devtest tool to create a correlation ID for the message, just set the flag 'Auto Generate' to YES. In the current defect, customer fills the value for field 'provisioningOrderId' and hence this flag has been set to NO
  4. The flag 'Reuse ID' has a meaning only if 'Auto Generate' is set to YES. WIth auto generated correlation ID, the 'Reuse ID' flag means that the same correlation ID is used for the duration of entire test otherwise a new ID is generated every time
  5. The interesting point to note here is that if you choose 'Auto Generate' YES, then the REQUEST payload is modified to include the auto-generated UUID. See the example below:
  6. FOR NEXT POINT, SCROLL DOWN BELOW THIS SCREENSHOT
PAYLOAD in SEND STEP
PAYLOAD MODIFIED BY DEVTEST TO INCLUDE AUTO-GENERTED CORRELATION ID
Inference

{
"Type": "Request", 
"provisioningOrderId": "MRXFDJJDOC03",
"salesInfo": {
"senderSystemId": "METRO",
"salesChannel": "METRO",
"applicationId": "AAM",
"partnerOrderld": "000055106001"
},
"transactionType": "UPDATEFEATURE",
"creationTime": "2019-02-21T10:49:54.689-0",
"customerProfile": {
"customerId": "CMPCS60216318051",
"firstName": "John",
"familyName": "Doe",
"middleName": "ABC",
"preferredLanguage": "en",
"securityProfileId": "760216819051",
"accounts": [
{
"accountNumber": "51HPC560216811",
"billingType": "PREPAID",
"biliCycleDay": 8
}
]
}
}

{ 
"Type": "Request", 
"provisioningOrderId":A87426CD3B6911E9A918E89EB42804A2, 
"salesInfo": { 
"senderSystemId": "METRO", 
"salesChannel": "METRO", 
"applicationId": "AAM", 
"partnerOrderld": "000055106001" 
}, 
"transactionType": "UPDATEFEATURE", 
"creationTime": "2019-02-21T10:49:54.689-0", 
"customerProfile": { 
"customerId": "CMPCS60216318051", 
"firstName": "John", 
"familyName": "Doe", 
"middleName": "ABC", 
"preferredLanguage": "en", 
"securityProfileId": "760216819051", 
"accounts": [ 
{ 
"accountNumber": "51HPC560216811", 
"billingType": "PREPAID", 
"biliCycleDay": 8 
} 
] 
} 
}

Devtest 'RabbitMQ Send' step inserts a new Correlation ID precisely at the place pointed by 'Request Rege' and 'Request Group'

7. Next step is to set the REGEX pattern to use for REQUEST as well as RESPONSE

           In this case, since the correlation ID is the same for both REQUEST and RESPONSE, we use the following expression

                 (?:"provisioningOrderId":)(.*?".*?")

This expression was arrived at with the help of an ONLINE REGEX TESTER https://www.regextester.com/99141  Over here, you can just provide your JSON content and play with REGEX expression to choose what you want to be matched, NOTE HERE CAREFULLY THAT THE 

TOOL SUPPORT THE CONCEPT OF GROUPS. THAT MEANS, THE ATTRIBUTE NAME IS GROUP0 AND ATTRIBUTE VALUE IS GROUP1, SINCE WE USE THE VALUE OF provisioningOrderId as correlation ID, we need to choose group 1.

 

Hope it is clear as to how to frame the REGEX that matches a specific attribute in a JSON REQUESE and RESPONSE

Next, lets understand certain IMPORTANT functional aspects that I understood, Unfortunately these details are not documented at all.

If ASYNCHRONOUS flag is chosen in RECEIVE step, then instead of reading a single message, all the messges are consumed, though in SEND/RECEIVE STEP Response, you would see only one message.

This is the observation and RC for the point #2 reported by customer and there are few weird things that I noticed here.

ASYNCHRONOUS FLAG
CORRELATION SCHEME
NUMBER OF MESSAGES READ BY RECEIVE STEP
FALSEFALSE1
TRUEFALSEALL
FALSETRUEALL
TRUETRUEALL

 

rabbitmq

messaging

Outcomes