Integrate Any JMS-Compliant Message Broker

In this procedure, you will learn how the jms service allows you to configure Kaazing Gateway to connect to any back-end JMS-compliant message broker.

JMS broker implementations provide a factory class in their JAR files. (For example, the Apache ActiveMQ factory class that ships in the Kaazing Gateway bundle is org.apache.activemq.jndi.ActiveMQInitialContextFactory in the JAR file activemq-client-5.10.0.jar.) To use the jms service with a JMS-compliant message broker, you would copy the jar file to GATEWAY_HOME/lib/ext and specify the name of the factory class in the service configuration element.

Note: Java Naming and Directory Interface (JNDI) is a Java API for looking up objects by name (a directory service). With the Gateway, you use JNDI in two ways: 1. to set up the initial context and call the Kaazing Gateway JMS Client Library from your JMS client or 2. to connect from the Gateway to your JMS-compliant message broker and lookup topics and queues. This section focuses on the latter, where you want to configure the Gateway to communicate with your message broker. For information about setting up JMS clients, see the appropriate client developer topics in For Developers.

For information on integrating the Gateway with specific JMS-Compliant Message Brokers, see:

To Integrate Any JMS-Compliant Message Broker

To use the jms service, you must perform the following steps:

  1. Copy the JMS-compliant message broker’s client-specific JAR files to GATEWAY_HOME/lib/ext.
  2. Configure a jms service on the Gateway with the properties and values for the JNDI initial context factory. The Gateway creates an initial context with a set of properties, which are specific to the JMS-compliant message broker. These properties may vary based on the configuration of your message broker, and may involve references to LDAP systems. These properties map to the env.* properties listed in jms; when you use these properties, the Gateway uses their values to create the initial context.
  3. Configure the connection factory name to connect to your JMS-compliant message broker. The Gateway creates the initial context, then uses it to obtain a connection factory by looking up the name you enter here. The name you enter here should be one of the classes included in the broker JAR file that you placed into the /lib directory in Step 1.
  4. Configure the context lookup topic format and context lookup queue format to inform jms service what format to use when looking up topics and queues in the broker. The Gateway follows this format when it attempts to fetch the reference to a topic or queue from the initial context.

    Note: For brokers that do not use destination lookups through JNDI (such as Informatica Ultra Messaging), you can add another property to the jms section in the gateway-config.xml file called destination.strategy, and set its value to session. This configuration instructs the Gateway to obtain Topic and Queue objects using the createTopic() and createQueue() JMS API methods instead of performing JNDI lookups.

  5. Once you have configured the jms service for the Gateway with the appropriate initial context properties and the connection factory name, save the gateway-config.xml and restart the Gateway. The Gateway then creates the connection using the connection factory.

    Note: Additional env.java.naming properties can be specified. Refer to the summary in https://docs.oracle.com/javase/jndi/tutorial/beyond/env/source.html and https://docs.oracle.com/javase/8/docs/api/javax/naming/Context.html for a complete list. The Gateway does not enforce any of these property values; it just passes them to the JMS API.

The following is an example of a service element of type jms.

<service>
  <accept>ws://localhost:8000/jms</accept>
  <accept>wss://localhost:9000/jms</accept>

  <type>jms</type>

  <properties>
    <connection.factory.name>ConnectionFactory</connection.factory.name>

    <env.java.naming.factory.initial>
      org.apache.activemq.jndi.ActiveMQInitialContextFactory
    </env.java.naming.factory.initial>
    <env.java.naming.provider.url>
      tcp://localhost:61616
    </env.java.naming.provider.url>
    <destination.strategy>session</destination.strategy>
  </properties>

  <cross-site-constraint>
    <allow-origin>http://localhost:8000</allow-origin>
  </cross-site-constraint>
  <cross-site-constraint>
    <allow-origin>https://localhost:9000</allow-origin>
  </cross-site-constraint>
</service>

Notes

See Also