Setting up WebSphere ESB to Consume Messages from JBoss
April 15, 2008 6 Comments
Let’s look at how to pick up messages from an external JMS messaging provider (in this example, we’ll use JBoss), using the new Generic JMS Binding support in WebSphere ESB 6.1.
Firstly, create a JMS connection factory and queue (destination) in JBoss, or your external messaging provider.
Then, you need to set up the generic JMS provider administratively in WebSphere. Open the Admin Console for your server, and navigate to Resources / JMS / JMS Providers. Create a new JMS Provider at the scope that’s relevant to you. Give it a name (something simple – in this case, we’ll call it JBoss), and specify the initial context factory and the external provider URL. In our case, these are org.jnp.interfaces.NamingContextFactory and jnp://our.jboss.server.name:1099/. To find out what these are, you’ll need to consult the documentation for your JMS provider.
Next, you’ll next to make sure that the class you specify is available to the WebSphere server. Locate the JAR that contains it (in our case, it is called jbossall-client.jar and is distributed by JBoss). Place that JAR in the lib/ext/ directory of your server (and make sure to restart it).
Next, let’s create the mediation module. Start up WebSphere Integration Developer, and create a new Mediation Module. In our case, we’ll assume that the messages we are picking up from JBoss are JMS Bytes messages, so we are going to take the easy route and use the Simple JMS Bytes Data Binding. You could, of course, use a custom data binding.
Create a Library, and add the ‘Schema for Simple JMS Data Bindings’ to it. Make sure the mediation module depends on the library. Next, create an interface, and give it a single one-way operation, with a single parameter of type JMSBytesBody. This means that the interface will correspond to what the data binding we will use expects.
Add an export to the mediation module, and add the interface you just created to it. Now right-click, and select ‘Generate Binding / Message Binding / Generic JMS Binding…’. Leave the default of ‘Configure new messaging provider resources’. Don’t be fooled, you still need to create everything but the listener port. For ‘Generic JMS provider name’, enter the name you entered earlier in the Admin Console. For the connection factory and recieve destination, enter the JNDI values defined for these resources in JBoss. Add a data binding (as mentioned, in our case we are using the ‘Simple JMS BytesMessage Data Binding’), and a function selector. The default function selector will use the TargetFunctionName JMS header as the native method name – you can write a different function selector by implementing the commonj.connector.runtime.FunctionSelector interface, as we did for our example. Select OK to create the binding. Make sure your method bindings match the behaviour of your function selector.
You’ll probably want to connect your export to a mediation flow – initially, you can just display the SMO to see whether it’s working as intended.
Now, deploy the mediation module to your server. You should find it starts consuming messages from your JMS provider.