Publishing or Consuming a Message to/from Queue in Talend

Hi,
I need to publish a message to JBOSS 7 HornetQ and consume the same message from JBOSS 7 HornetQ.I'm using Talend Studio 5.0.2.
Does tMom component helps in it?
Please suggest me to do in JBOSS 7 Queue.
Thanks
krishna
1 REPLY
One Star

Re: Publishing or Consuming a Message to/from Queue in Talend

I would advice you to consume and produce messages to HornetQ using the camel components in the studio instead of from within a Talend job directly. HornetQ is not OSGI compliant; you will run into connectivity issues when doing so from within A Talend job.
1. I would advice you to create a seperate HornetQ connection faction for your connecting from the ESB as shown below:
<connection-factory name="NettyXAConnectionFactoryESB">
<xa>true</xa>
<connectors>
<connector-ref connector-name="netty-connector"/>
</connectors>
<discovery-group-ref discovery-group-name="dg-abs_91"/>
<entries>
<entry name="/XAConnectionFactoryESB"/>
</entries>
<consumer-window-size>0</consumer-window-size>
<connection-load-balancing-policy-class-name>
org.hornetq.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy
</connection-load-balancing-policy-class-name>
</connection-factory>

2. Create a cJMSConnectionFactory in the mediation perspective and add the jars to the dependency lib:
- jnp-client.jar
- hornetq-client-core.jar
- hornetq-client-jms.jar
-netty.jar

3. Use connection factory custom code as shown below:
// Set environment for this context
String cf = "/XAConnectionFactoryESB";
String url = "jnp://ebankhost:1099";
String id = "myBrokerName";

// Obtain logger
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());

// Set naming properties
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(javax.naming.Context.PROVIDER_URL, url);
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.namingSmiley Surprisedrg.jnp.interfaces");

// Get connectionfactory from JNP endpoint(s)
javax.naming.Context ctx;
jmsConnectionFactory = null;

// Loop until succesful connection
while (jmsConnectionFactory == null) {
// Try to get a connection forever...
try {
ctx = new javax.naming.InitialContext(env);
logger.debug("Retrieving for " +
" the connectionfactory " + cf + " from JNP endpoint(s) " + url);

jmsConnectionFactory = (javax.jms.ConnectionFactory) ctx.lookup(cf);
logger.info("Connected successfully to " + id + " broker");

} catch (javax.naming.NamingException e) {
logger.warn("Cannot obtain " + id + " connectionfactory (" +
cf + ") from endpoint " + url + " due to (" + e.getMessage() + "), retrying every 5000 milliseconds...");
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
logger.error("WTF!!! Interupted?!?", e1);
}
}
}

4. Now point your cJms component to your cJMSConnectionFactory and voila.
All the best,
Robin