JMS / AMQP gateway for JBoss ESB
jbride Feb 6, 2009 9:03 PMHi,
Customer needs enterprise wide business messaging inter-operability and has selected AMQP as the path forward rather than other options such as JMS bridge or any possibilities that WS-* might offer. Subsequently, we have a need for a JMS / AMQP gateway and notifier for the JBoss SOA-P / ESB . Using the Java client bindings from the QPid project and JBESB_4_4_GA_CP2_CR4 ..... I do have a prototype AMQP gateway working. In a nutshell, the data flow in this scenario is as follows: remote message providers send AMQP messages to an exchange hosted by the C++ broker of QPid. The broker routes those messages as appropriate to queues .... and the JMS/QPid gateway (subscribed to that queue) picks up the JMS message and forwards it to a corresponding JMS listener on the ESB. Note: we continue to use JBoss Messaging as the default JMS broker for the JBoss ESB . Only this AMQP gateway will subscribe to QPid ....... all other ESB services will communicate with each-other via inVM or JBoss Messaging.
My purpose for this post is to discuss tweaks to some of the ESB code I had to make to get the gateway working with the QPid Java client bindings. It's possible that changes actually belong in the QPid Java client code-base and not the ESB. I'm hoping that experts on this forum might offer their opinion. ..... thank you!
The following is a snippet of the config for my QPid provider :
<jms-provider name="JMS" connection-factory="connectionfactory.qpidConnectionFactory"> <property name="jndi-prefixes" value="connectionfactory.,destination." /> <property name="java.naming.factory.initial" value="org.apache.qpid.jndi.PropertiesFileInitialContextFactory"/> <property name="connectionfactory.qpidConnectionFactory" value="amqp://guest:guest@clientId/virtualHost?brokerlist='tcp://ratwater:5672'"/> <property name="destination.Alpha_Co" value="direct://usmc.tracks/Alpha_Co_queue?routingkey='Alpha_Co_key'"/> <jms-bus busid="quickstartGwChannel"> <jms-message-filter dest-type="QUEUE" dest-name="destination.Alpha_Co" /> </jms-bus> </jms-provider>
The problem I encountered is that the QPid Java client binding snips off prefixes to its InitialContext keys when creating an InitialContext (ie: QPid jndiContext ends up with a key of 'qpidConnectionFactory' rather than connectionfactory.qpidConnectionFactory ) . Subsequently, when executing the lookup on the QPid InitialContext, the ESB uses the full property name from the jboss-esb.xml config (i.e.: connectionfactory.qpidConnectionFactory ) ..... as a result, a NamingException is always thrown and the ESB service bombs. Below, is a code snippet from org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java that highlights this 'snipping' that QPid is doing :
protected void createConnectionFactories(Map data, Hashtable environment) { for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = entry.getKey().toString(); if (key.startsWith(CONNECTION_FACTORY_PREFIX)) { String jndiName = key.substring(CONNECTION_FACTORY_PREFIX.length()); ConnectionFactory cf = createFactory(entry.getValue().toString()); if (cf != null) { _logger.info("createConnectionFactories() connectionFactory created at jndiName = "+jndiName+" w/ cFactory = "+entry.getValue().toString()); data.put(jndiName, cf); } else { _logger.warn("createConnectionFactories() connectionFactory not created for : "+entry.getValue().toString()); } } } }
Thus, to accommodate for the 'snipping' I had to make changes to the following files :
[jbride@ratwater rosetta]$ svn status M src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java M src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java M src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolContainer.java
Before, I get into details about the ESB code changes .... any thoughts as to who should accommodate who ?? Do other JMS client libraries snip off prefixes like this ? I'll be asking the QPid folks the same questions.
thank you !
Jeffrey Bride