Was this helpful?

This topic pertains to Apigee Edge on-premises only.

 

Overview

If you use Java Message Service (JMS) with Java Naming and Directory Interface (JNDI), you can make RESTful calls from JMS to backend services through Apigee Edge. JMS support is available only in Edge on-premises.

This document describes how to configure Edge to work with a JMS host and how to create an API proxy that handles incoming JMS messages.

Regardless of the JMS provider you use—for example, whether you’re using Apache ActiveMQ or JBoss HornetQ (or neither)—the Edge supports only Java Naming and Directory Interface (JNDI) to connect to the JMS provider. If a JMS provider doesn’t support JNDI, it can't be used with Edge.

Use Case

You can send messages from JMS queues to an Edge API resource. For example, you might need an API proxy endpoint to handle incoming JMS messages from multiple JMS queues, apply logic to convert JMS messages to HTTP, forward the request to a target endpoint, and return the response as JMS.

Creating a JMS Host

To use JMS with Edge, you configure the JMS connection details by creating a JMS host . The JMS host then can be referenced from JMS API proxy endpoints by using the <JMSHost> or <JMSResponseHost> tags. All JMS API proxies share the same JMS host.

Create a JMS host with the following API call to your Edge on-premises management environment:

curl –H “Content-Type: application/xml” –u : –X POST “http://{host}:8080/v1/organizations/environments/jmshosts" –d
“<JMSHost name="jmshost1"> 
<Description></Description> 
<ConnectionFactoryClass>org.apache.activemq.jndi.Active
</ConnectionFactoryClass> 
<ConnectionFactory>FooFactory</ConnectionFactory>
<ConnectionURL>tcp://172.16.1.94:61616</ConnectionURL>
<Context>JmsContext</Context> 
<ContextUsername>abc</ContextUsername> 
<ContextPassword>password</ContextPassword> 
<ConnectionUsername>admin</ConnectionUsername> 
<ConnectionPassword>password</ConnectionPassword> 
<Connections>10</Connections> 
</JMSHost>”

Request payload elements

Name Description
name Name of the JMS host.
Description Description of the JMS host.
ConnectionFactoryClass Provider specific implementation of JMS Connection factory class.
ConnectionFactory Property used to select the registry service provider as the initial context and specifies the class name of the initial context factory for the provider. Note that it is not used by the provider.
ConnectionURL URL of the JNDI provider.
Context Initial JNDI context and values are specific to JMS provider.
ContextUsername User name to access the JNDI context.
ContextPassword Password to access the JNDI context.
ConnectionUsername User name to access the JMS provider.
ConnectionPassword Password to access the JMS provider.
Connection Number of physical TCP connections toward JMS provider.

You might need to remove a JMS host associated with an environment. To do this, execute the following API call:

curl –u : “http://{host}:8080/v1/organizations/environments/jmshosts/{jmshost_name}” -X DELETE

Creating a JMS proxy endpoint

The ProxyEndpoint and JmsProxyConnection elements define a set of JMS transport properties. These properties can be used to set network configurations to connect to the JMS provider.

The Edge JMS API proxy endpoint supports only receiving messages to a JMS queue. Other JMS operations are not supported.

Properties are set on a JMS API proxy as follows:

<ProxyEndpoint name=”default” proxyType="jmsConnection"> 
<!-- "proxyType” is mandatory if you want to create JMS endpoints --> 
  <JmsProxyConnection state=”on”> 
    <JMSHost>defaultHost</JMSHost> <!-- this is the JMS host created in prev section --> 
    <Destination type="queue">dynamicQueues/myqueue</Destination> 
    <MessageSelector></MessageSelector> 
    <DefaultResponseQueue>dynamicQueues/defaultResponseQueue</DefaultResponseQueue> 
    <JMSResponseHost>defaultResponseHost</JMSResponseHost>
  </JmsProxyConnection> 
</ProxyEndpoint> 

Ensure that you define the attribute proxyType="jmsConnection" in order to create JMS proxy endpoints.

Also, ensure that you have the JMS provider-specific client library in the classpath.

Property description

The following table provides the description of all JmsProxyConnection properties that are available for JMS implementation.

Property name Description Required?
JmsProxyConnection JMS network details associated with the API proxy. You can dynamically set to subscribe/unsubscribe to a given queue by defining an attribute state=”on/off”. By default it is “on”. Yes
JMSHost JMS host defined for the JMS proxy. Yes
Destination Queue path to which the subscribe listens to the messages. Yes
MessageSelector Selector pattern on queues based on JMS headers. No
DefaultResponseQueue Name of the JMS queue where response from target is published. No
JMSResponseHost JMS response host defined for the JMS proxy. If specified, all responses are sent to the queues over this host. No

All HTTP headers matching standard JMS headers will be set “as is” and other HTTP headers will be set as JMS properties in the response message used by the JMS proxy.

Setting JMS headers

You can use the AssignMessage policy to specify the following headers in a JMS proxy.

  • X-Apigee-Ignore-JMSResponse - By default, the API proxy puts the response on the JMS response queue specified in the JMSReplyTo header. However, if you want the backend service to handle putting the response on the queue specified in JMSReplyTo—or something else outside of the API proxy such as a Java callout or another API proxy—add the X-Apigee-Ignore-JMSResponse header and set it to true:
     
    <Header name="X-Apigee-Ignore-JMSResponse">true</Header>

    Where to set the header: If the proxy is calling a backend service, the header must be set after the backend service is called. If there is no backend service, such as when you use a Java callout or another API proxy to put the message on the response queue, the header can be set anywhere in the flow of the API proxy (the API proxy you don't want putting the response on the queue).
    For more information about API proxy flows, see Flow configurations.

For messages placed in the ResponseQueue:

  • JMSExpiration - Time in milliseconds after which the message expires.
  • JMSDeliveryMode - A value of 1 (non-persistent) or 2 (persistent).

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)