Contact Us 1-800-596-4880

Configure an ActiveMQ Connection for JMS Connector

Anypoint Connector for JMS (JMS Connector) includes an ActiveMQ connection configuration, which provides support for ActiveMQ 5. Using this connection, you can set JMS 1.1 (default), JMS 1.0.2b, or JMS 2.0 specifications, and you can configure not only all of the general connection parameters for JMS but also the custom parameters that are present only in ActiveMQ.

Configure an ActiveMQ Connection

After you declare the ActiveMQ connection, customize Connection Factory to your desired configuration. Every parameter in the connection comes with a default value, meaning that you are required to configure only the parameters relevant for your use case. Also, the ActiveMQ connection exposes parameters that are exclusive to the ActiveMQ implementation, like Initial redelivery delay.

In the following example, you configure an ActiveMQ Connection:

  1. In Studio, navigate to the Global Elements tab.

  2. Click Create.

  3. In the filter box type jms and select JMS Config.

  4. Click OK.

  5. In the Connection field select ActiveMQ Connection.

  6. In the Factory configuration field, select Edit Inline.

  7. Set the Broker url field value to the address of the broker to connect to, for example, tcp://localhost:61616.

  8. Click OK.

ActiveMQ Connection Configuration window in Studio with Broker URL field set to tcp://localhost:61616

In the XML editor, the <jms:active-mq-connection> and <jms:factory-configuration> configuration looks like this:

 <jms:config name="JMS_Config">
  <jms:active-mq-connection >
   <jms:factory-configuration brokerUrl="tcp://localhost:61616" />
  </jms:active-mq-connection>
 </jms:config>

Configure an ActiveMQ - No Connectivity Test Connection (DEPRECATED)

There may be certain scenarios in which more than one node cannot use the credentials of a broker connection simultaneously. In these cases, Mule applications use the Primary node only field set to true to ensure listener execution on only one of the nodes. However, the connection test that is performed prior to deployment can result in a deployment error on the primary node if another node already used the credentials. For this particular case, use ActiveMQ Connection - No Connectivity Test, which is identical to the ActiveMQ Connection, except that it does not perform a connectivity test prior to deployment.

In the following example, you configure an ActiveMQ Connection - No Connectivity Test:

  1. In Studio, navigate to the Global Elements tab.

  2. Click Create.

  3. In the filter box, type jms and select JMS Config.

  4. Click OK.

  5. In the Connection field, select ActiveMQ Connection - No Connectivity Test.

  6. Set the optional Client id field.

  7. In the Factory configuration field, select Edit Inline.

  8. Set the Broker url field value to the address of the broker to connect to, for example, tcp://localhost:61616.

  9. Click OK.

ActiveMQ Connection - No Connectivity Test Configuration window in Studio with Broker URL field set to tcp://localhost:61616

In the XML editor, the <jms:active-mq-nct-connection> and <jms:factory-configuration> configuration looks like this:

 <jms:config name="JMS_Config">
  <jms:active-mq-nct-connection clientId="my-mule-cli">
   <jms:factory-configuration brokerUrl="tcp://localhost:61616" />
  </jms:active-mq-nct-connection>
 </jms:config>

Configure the Required Libraries

When you configure any connection type, you must always configure a library containing the JMS client implementation, because JMS Connector is not bound to any particular implementation. Configure ActiveMQ external libraries in the global elements view of Studio or manually add the library dependency in your pom.xml file.

  • ActiveMQ KahaDB
    The activemq-kahadb-store dependency is required only when using an persistent in-memory broker based on the VM transport (such as vm://localhost?broker.persistent=true). This dependency provides a valid org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter implementation. This dependency is also required for persistent message delivery.

    In your pom.xml file in Studio, adding the dependency looks like this:

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-kahadb-store</artifactId>
        <version>5.14.4</version>
    </dependency>
  • ActiveMQ Broker
    The activemq-broker dependency is required only when using an in-memory broker based on the VM transport (which is the one configured by default). This dependency provides a valid org.apache.activemq.broker.Broker implementation.

    In your pom.xml file in Studio, adding the dependency looks like this:

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <version>5.14.4</version>
    </dependency>
  • ActiveMQ Client
    The activemq-client dependency is always required to use ActiveMQ connections. Choose one that provides a valid org.apache.activemq.ActiveMQConnectionFactory implementation.

In your pom.xml file in Studio, adding the dependency looks like this:

+

<dependency>
     <groupId>org.apache.activemq</groupId>
     <artifactId>activemq-client</artifactId>
     <version>5.14.4</version>
 </dependency>

To configure these libraries in the Global Element view, follow these steps:

  1. In Studio, navigate to the Global Elements tab.

  2. Click Create.

  3. In the filter box, type jms and select JMS Config.

  4. Click OK.

  5. In the Connection field, select ActiveMQ Connection.

  6. In the Required Libraries section that shows the ActiveMQ KahaDB, ActiveMQ Broker and ActiveMQ Client libraries, click the Configure…​ button to install the dependency.

  7. Select any of the following install options:

    • Add recommended library Installs the recommended library.

    • Use local file Browse to a local file for the required engine library and install it.

    • Add Maven dependency Browse to the dependency and install it.

Click the Configure button to install the dependencies
Figure 1. JMS Connector Libraries configuration

Configure the In-Memory Broker

By default, Anypoint Connector for ActiveMQ (ActiveMQ Connector) uses an in-memory broker, which makes it easy to start building an application without configuring a connection against an external broker. The in-memory broker is required to configure both the ActiveMQ KahaDB and ActiveMQ Broker libraries. The default URL is:

vm://localhost?broker.persistent=false&broker.useJmx=false

To configure the in-memory broker in Studio, follow these steps:

  1. In Studio, open the JMS Config global element window.

  2. In the Connection Factory section, set the Factory configuration field to Edit inline.

  3. Set the Broker url field to the address of the broker to connect, for example, vm://localhost?broker.persistent=false&broker.useJmx=false .

  4. Click OK.

Set the Broker url field to the address of the broker to connect
Figure 2. JMS Connector In-Memory Broker Configuration

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

<jms:config name="JMS_Config" doc:name="JMS Config">
		<jms:active-mq-connection >
			<jms:factory-configuration brokerUrl="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
		</jms:active-mq-connection>
	</jms:config>

Configure Message Redelivery

When a message cannot be processed correctly, it’s not acknowledged. The message is then redelivered and probably again not processed correctly, which causes the cycle to execute indefinitely.

To prevent a message from endless redelivery, configure the Max redelivery field.
By default, JMS Connector uses a maximum redelivery value of 0, which means that messages won’t be redelivered, regardless of whether the message is recovered or rolled back from a transaction. If the message has persistent delivery set, ActiveMQ sends the message to a DLQ.QUEUE (a dead letter queue).

ActiveMQ also enables you to configure a client-side redelivery.

  • The Initial redelivery delay field enables you to configure, in milliseconds, how much time to wait before the first message redelivers.

  • The Redelivery delay field enables you to configure, in milliseconds, how much time to wait until the message is subsequently redelivered after the first redelivery.

To configure these fields in Studio, follow these steps:

  1. In Studio, open the JMS Config global element window.

  2. In the Connection Factory section, set the Factory configuration field to Edit inline.

  3. Set the Initial redelivery delay field to 1000.

  4. Set the Redelivery delay field to 100.

  5. Set the Max redelivery field to 10.

  6. Click OK.

Set the Max redelivery field to 10
Figure 3. JMS Connector Redelivery configuration

In the XML editor, the maxRedelivery,redeliveryDelay, and initialRedeliveryDelay configurations look like this:

<jms:config name="JMS_Config">
  <jms:active-mq-connection>
    <jms:factory-configuration maxRedelivery="10"
      redeliveryDelay="100"
      initialRedeliveryDelay="1000"/>
  </jms:active-mq-connection>
</jms:config>

Configure Trusted Packages

ActiveMQ versions 5.12.2, 5.13.0, and later restrict the classes that can be serialized and deserialized, helping to prevent the execution of a malicious payload on the host system.

For ActiveMQ, JMS Connector enables by default only the JDK and JRE provided classes, so if you need to exchange object messages, you must add the packages your applications use by activating the Trusted packages field.
Even though you can also enable the Trust all packages field to allow the serialization of more classes by allowing any object to be serialized and deserialized, this is not as secure as leaving it disabled in most cases. Keep this parameter disabled to improve the security and help prevent malicious attacks.

In the following example, you configure the connection to enable only users who are compliant with the com.mulesoft.someapp and com.mulesoft.someapp.model packages to consume and produce ObjectMessages:

  1. In Studio, open the JMS Config global element window.

  2. In the Connection Factory section, set the Factory configuration field to Edit inline.

  3. Select the Trusted packages field.

  4. Click the plus sign to add a new package.

  5. In the Trusted package window, set the Value field to com.mulesoft.someapp.

  6. Click Finish.

  7. Repeat Step 4.

  8. In the Trusted package window, set the Value field to com.mulesoft.someapp.model.

  9. Click Finish.

  10. Select the Trust all packages field.

  11. Click OK.

Select the Trusted packages and Trust all packages field
Figure 4. JMS Connector Trusted Packages configuration

In the XML editor, the <jms:trusted-packages> and trustAllPackages configurations look like this:

<jms:config name="JMS_Config">
  <jms:active-mq-connection>
    <jms:factory-configuration trustAllPackages="true">
      <jms:trusted-packages >
        <jms:trusted-package value="com.mulesoft.someapp" />
        <jms:trusted-package value="com.mulesoft.someapp.model" />
      </jms:trusted-packages>
    </jms:factory-configuration>
  </jms:active-mq-connection>
</jms:config>

Configure SSL Connections

JMS Connector version 1.3.0 and later enables you to configure ActiveMQ connections with SSL configurations to establish secure and encrypted connections against the ActiveMQ broker:

  1. In Studio, navigate to the Global Elements tab.

  2. Click Create.

  3. In the filter box type jms and select JMS Config.

  4. Click OK.

  5. In the Connection field select ActiveMQ Connection.

  6. Navigate to the TLS/SSL tab.

  7. In the TLS Configuration field, select Edit Inline

  8. In the Trust Store Configuration section, set the following fields:

    • Path: client.ts

    • Password: password

  9. In the Key Store Configuration section, set the following fields:

    • Path: client.ks

    • Alias: client

    • Key Password: password

    • Password: password

  10. Click OK.

SSL Configuration.
Figure 5. JMS Connector SSK Configuration

In the XML editor, the <jms:active-mq-connection>, <tls:trust-store>, and <tls:key-store> configuration looks like this:

<jms:config name="JMS_Config">
  <jms:active-mq-connection>
   <tls:context>
    <tls:trust-store
      path="client.ts"
      password="password" />
    <tls:key-store
      path="client.ks"
      password="password"
      keyPassword="password"
      alias="client" />
   </tls:context>
  </jms:active-mq-connection>
</jms:config>

JMS Connector can also reference global TLS context configurations to reuse and share the same TLS context between connectors as shown in the following example with Anypoint Connector for HTTP (HTTP Connector):

<!--  HTTP Requester Configuration -->
<http:request-config name="HTTP_Request_configuration">
  <http:request-connection tlsContext="TLS_Context" />
</http:request-config>

<!--  JMS Configuration -->
<jms:config name="JMS_Config">
  <jms:active-mq-connection tlsContext="TLS_Context"/>
</jms:config>

<!--  Reusable TLS Context -->
<tls:context name="TLS_Context">
 <tls:trust-store
  path="client.ts"
  password="password" />
<tls:key-store
  path="client.ks"
  password="password"
  keyPassword="password"
  alias="client" />
</tls:context>
View on GitHub