cancel
Showing results for 
Search instead for 
Did you mean: 

Can we send multiple JMS Response (2 or more) to different queues for one incoming JMS Request

SOLVED
ab86goel
Established Member

Can we send multiple JMS Response (2 or more) to different queues for one incoming JMS Request

Scenario:
1. SoapUI Pro sends a message to a queue1 and listens on queue2.
2. Mock Response (JMS) listens on queue1 and sends multiple response based on the incoming request in 3 different queues.
3. Response 1: Send to Queue2
4. Response 2: Send to Queue3
5. Response 3: Send to Queue4.

Can this be achieved in one mock service and for only 1 incoming request?

1 ACCEPTED SOLUTION

Accepted Solutions
sonya_m
Community Manager

Re: Can we send multiple JMS Response (2 or more) to different queues for one incoming JMS Request

Here's the solution from our support team:

>>

In ReadyAPI, this scenario is not supported out of the box, sorry. There is the corresponding enhancement request in our DB (RIA-6733), and your message has increased its rating, thanks.

In the meantime, you can try to implement the required logic via a custom script. I have found the following solution in our knowledge base and that seems to be suitable for your task (with some slight modifications), as well.

Configuration:
A JMS Virt is configured with one Request Queue and two Response Queues ("A" and "B") with the Script Dispatching Style. When it gets requests from other systems into the Request Queue, it should read out those messages and check a specific JMS Property in the Dispatching Script. Depending on the JMS Property, Response A should be sent or Responses A and B together.

Solution:
1. Create two responses - Response A (to queue A) and Response B (to queue B).
2. Configure the Script Dispatching Style to send Response A when one response should be sent and Response B when two responses should be sent.
3. For Response B, enter the Script that will manually send Response A to queue A before sending Response B (Response Script is executed before the response is sent).

The response script should look like this:

import javax.jms.*
import java.util.Properties
import javax.naming.Context
import javax.naming.InitialContext

def config = mockResponse.sendDestinationConfiguration
def message = mockResponse.mockOperation.getMockResponseByName("Response A").bindableMockResponse.messageAsString

Properties props = new Properties()
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, config.initialContextFactoryClass)
props.setProperty(Context.PROVIDER_URL, config.providerUrl)
props.setProperty("queue.firstQueue", "queueA")
Context ctx = new InitialContext(props)

QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory")
Connection connection = connectionFactory.createQueueConnection()
Session queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)
Queue queueSend = (Queue) ctx.lookup("firstQueue")
MessageProducer messageProducer = queueSession.createProducer(queueSend)
TextMessage textMessageSend = queueSession.createTextMessage()
            
textMessageSend.setText(message)
messageProducer.send(textMessageSend)

messageProducer.close()
queueSession.close()
connection.close()

<<


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

2 REPLIES 2
sonya_m
Community Manager

Re: Can we send multiple JMS Response (2 or more) to different queues for one incoming JMS Request

Hi @ab86goel ! I found your support ticket with an on-going investigation about this (00453678), please keep working with the support team and the Community would also be thankful if you provide us the final solution in this thread. Thank you.


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sonya_m
Community Manager

Re: Can we send multiple JMS Response (2 or more) to different queues for one incoming JMS Request

Here's the solution from our support team:

>>

In ReadyAPI, this scenario is not supported out of the box, sorry. There is the corresponding enhancement request in our DB (RIA-6733), and your message has increased its rating, thanks.

In the meantime, you can try to implement the required logic via a custom script. I have found the following solution in our knowledge base and that seems to be suitable for your task (with some slight modifications), as well.

Configuration:
A JMS Virt is configured with one Request Queue and two Response Queues ("A" and "B") with the Script Dispatching Style. When it gets requests from other systems into the Request Queue, it should read out those messages and check a specific JMS Property in the Dispatching Script. Depending on the JMS Property, Response A should be sent or Responses A and B together.

Solution:
1. Create two responses - Response A (to queue A) and Response B (to queue B).
2. Configure the Script Dispatching Style to send Response A when one response should be sent and Response B when two responses should be sent.
3. For Response B, enter the Script that will manually send Response A to queue A before sending Response B (Response Script is executed before the response is sent).

The response script should look like this:

import javax.jms.*
import java.util.Properties
import javax.naming.Context
import javax.naming.InitialContext

def config = mockResponse.sendDestinationConfiguration
def message = mockResponse.mockOperation.getMockResponseByName("Response A").bindableMockResponse.messageAsString

Properties props = new Properties()
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, config.initialContextFactoryClass)
props.setProperty(Context.PROVIDER_URL, config.providerUrl)
props.setProperty("queue.firstQueue", "queueA")
Context ctx = new InitialContext(props)

QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory")
Connection connection = connectionFactory.createQueueConnection()
Session queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)
Queue queueSend = (Queue) ctx.lookup("firstQueue")
MessageProducer messageProducer = queueSession.createProducer(queueSend)
TextMessage textMessageSend = queueSession.createTextMessage()
            
textMessageSend.setText(message)
messageProducer.send(textMessageSend)

messageProducer.close()
queueSession.close()
connection.close()

<<


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

New Here?
Join us and watch the welcome video: