Configuring Direct Connection

Applies to ReadyAPI 3.10, last modified on October 07, 2021

You can configure a direct connection to a virtual service from ReadyAPI without using any additional intermediaries.

Add JMS Routes

To add JMS routes to an existing virtual service, right-click the virtual service in the Navigator panel and select JMS Route.

In the subsequent dialog, select the Manual tab and configure JMS endpoint.

JMS service virtualization and API testing: Adding a new JMS route to a JMS virtual service manually

Click the image to enlarge it.

Option Description
JMS Server Select one of the JMS servers specified in the JMS dialog or select Create New to create a new JMS server.
Receive Destination JNDI Name The name of the topic or queue that ReadyAPI emulates.
Requests to it will be redirected to the virtual service.
Send Destination JNDI Name The name of the topic or queue ReadyAPI sends the response to. It can also be configured in the response editor.

Configure Virtual Service Properties

General JMS Specifics

  • Do not use the same topic (queue) for the request and its response. This may cause an infinite loop: after sending the outgoing message to the topic (or queue), the virtual service will recognize it as an incoming request and will process a reply, and the loop can repeat again and again.

  • Also, remember that in JMS, multiple consumers can subscribe to the same destination. In this case, the destination type – topic or queue – comes into play and specifies how messages are processed:

    • A message that comes to a destination of the topic type can be read by all consumers subscribed to this destination.

    • A message that comes to a queue destination will be read only by one consumer, the other subscribers will not receive it.

    When virtualizing JMS services, it is quite easy to create two or more consumers of the same queue destination. This might cause issues during testing, because your test will not receive answers to some messages. The JMS Request test step can run in an infinite waiting loop and you might think that your test has hung (see the example below). Be aware!


Direct Connection Specifics

  • You can configure each response individually to use the ReplyTo value from the incoming request or the destination configured manually. ReadyAPI can send responses to a different queue or a different JMS server. For more information about connection options, see the JMS Response Properties topic.

  • If necessary, you can use the Start script to dynamically configure JMS connection properties. To do this, you call the ConnectionFactoryProducer() method and provide the required closures. This method should create, configure and return an instance of the ActiveMQConnectionFactory class.The scripts can use the following closures:

    Callback Name Required Parameters The Callback Returns
    contextProducer JmsConnectionConfiguration, Properties An InitialContext that you use to create the JMS connection.
    connectionFactoryProducer InitialContext A ConnectionFactory object that you use in your script.
    connectionProducer ConnectionFactory A JMS Connection object that you use to create the session.
    sessionProducer javax.jms.Connection A JMS Session object that you use in your script.
    destinationProducer javax.jms.Session, String A Destination object that specifies the JMS endpoint you send requests to.

    Here is a sample script that creates a connection to Apache ActiveMQ Artemis by using the above closures:

    Show Example

See Also

JMS Virtual Services
JMS Support
Creating the Connector Plugin

Highlight search results