Contact Us 1-800-596-4880

Tune JMS Connector for Performance

Performance is sometimes negatively impacted by message . The following recommendations can help you get the most of Anypoint Connector for JMS (JMS Connector) for your Mule applications.

Connections Caching Reuse

Because connections are expensive to create, reuse them as much as you can. By default, JMS Connector uses a caching strategy that reuses as many consumers and producers as possible. To avoid performance degradation, do not disable connection caching.

Increased Concurrent Messages Processing

To improve the performance of your application, increase the number of consumers that receive messages from the same destination. JMS Connector enables you to increase the number of consumers by configuring the Number of consumers field in the On New Message source. By default, this source enables four consumers to receive messages concurrently on the same destination, but you can increase this number to the one that best fits your needs.

In the following example, you increase the number of consumers receiving messages concurrently:

  1. In Studio, select the On New Message source from your flow.

  2. In the On New Message source configuration screen, set the Number of consumers field to 20.

In the On New Message configuration screen
Figure 1. JMS Connector Number of consumers Configuration

In the XML editor, the numberOfConsumers configuration looks like this:

<jms:listener config-ref="config" destination="#[vars.destination]" numberOfConsumers="20"/>

Cluster Configuration Optimization

For applications running in clusters, consider the primary node and how the connector behaves. When the app runs in a cluster, the On New Message source default behavior receives messages only in the primary node, no matter what kind of destination the app consumes.

When consuming messages from a queue, the default connector behavior is to receive messages in all the cluster’s nodes, not just the primary node. JMS Connector enables you to configure the Primary node only field in the On New Message source. When the connector consumes from a queue in a cluster, do not select the Primary node only field, which defaults to false.

In the following example, you configure the connector to receive messages in all the nodes:

  1. In Studio, select the On New Message source from your flow.

  2. In the Advanced tab, leave unselected the Primary node only field.

In the Advanced tab of the On New Message source
Figure 2. JMS Connector Primary Node only Configuration

In the XML editor, the primaryNodeOnly configuration looks like this:

<jms:listener config-ref="config" destination="${inputQueue}" primaryNodeOnly="false"/>

When consuming messages from a topic, the default connector behavior is to receive messages only in the primary node, which avoids processing the same message multiple times across the cluster.

When consuming messages from a topic in a cluster, the configuration of Primary node only unselected causes the cluster to process the same message more than once, unless you also configure shared subscriptions.
If you are using the JMS 2.0 shared subscriptions mechanism, then change the cluster configuration to consume from all the nodes, again setting the Primary node only field to false.

In the following example, you configure the connector using 2.0 spec shared-subscriptions mechanism:

  1. In Studio, select the On New Message source from your flow.

  2. In the On New Message source configuration screen, select Topic consumer.

  3. Select the Shared option.

  4. Set the Subscription name to clusteredEventListener.

  5. In the Advanced tab, leave unselected the Primary node only field.

In the Advanced tab of the On New Message source
Figure 3. JMS Connector Primary Node only Configuration

In the XML editor, the jms:topic-consumer, shared, and primaryNodeOnly configurations look like this:

<jms:listener config-ref="JMS_20_config" destination="${inputTopic}" primaryNodeOnly="false">
     <jms:consumer-type>
         <jms:topic-consumer shared="true" subscriptionName="clusteredEventListener"/>
     </jms:consumer-type>
 </jms:listener>
View on GitHub