Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] How to use HornetQ as a broker

This article explains how to use HornetQ as a JMS broker in Talend Open Studion 5.2.x for ESB.
The example mediation route used in this example is simple:
* Consume message from a queue
* Print contents of message to log
I've use HornetQ 2.2.14 for this example and deployed a queue named "queue1" to the broker. The (default) JNP port used under HornetQ is 1099, I've changed this to 1199 to prevent conflicts with local JBoss instances running. You can use the default 1099, just update the source code listed below.
1. In TOS, change to Mediation perspective
2. Create a new route in the studio
3. Drag from the palette the cJMS, cJMSConnectionFactory and cLog into the route designer
4. Connect the cJMS component via "Row"--> "Route" to cLog
Now you should have the same setup as shown in TOS_ESB_HornetQ_ExampleRoute.png
5. Configure the cJMSConnectionFactory by selecting the MQ Server type to "Customized".
6. In the code field, copy and paste the java sourcecode listed below: (update if necessary your JNP port):

java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1199");
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming 0683p000009MA5A.pngrg.jnp.interfaces ");

javax.naming.Context ctx;
jmsConnectionFactory = null;

try {
ctx = new javax.naming.InitialContext(env);
jmsConnectionFactory = (javax.jms.ConnectionFactory) ctx.lookup("/ConnectionFactory");

} catch (javax.naming.NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
7. Add the libraries listed below from your HornetQ_INSTALL_DIR/lib to the cJMSConnectionFactory component:
* jnp-client.jar
* hornetq-core-client.jar
* hornetq-jms-client.jar
* netty.jar
8. If everything went well, you have the same component setup as shown in TOS_ESB_HornetQ_ConnectionFactory.png
9. Configure the cJMS component by selecting your Customized cJMSConnectionFactory
10. Configure the cJMS component by naming the queue "queue1".
That's it!
As with all things, it is simple as long as you know how to do it!
Robin Huiser
\
0683p000009MDRL.png 0683p000009MDDl.png 0683p000009MDIk.png
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

For all people needing a username and password you can define this in
javax.jms.Connection connection = jmsConnectionFactory.createConnection("username", "password");
Also:
You need to edit uil2-service.xml, and change the binding address from ${jboss.bind.address} to your IP address. The default binding 0.0.0.0 does not work.

reference (in the comments)
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/Q_20995081.html

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Hi Robin
Good articles, thanks for sharing your valuable experience to community!
Shong
Anonymous
Not applicable
Author

For all people needing a username and password you can define this in
javax.jms.Connection connection = jmsConnectionFactory.createConnection("username", "password");
Also:
You need to edit uil2-service.xml, and change the binding address from ${jboss.bind.address} to your IP address. The default binding 0.0.0.0 does not work.

reference (in the comments)
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/Q_20995081.html
Anonymous
Not applicable
Author

Hi,
I did what you said, bu when I deploy my exported .kar file, I got the exception at runtime (in the TalendESB/Runtime_ESB/container) :
java.lang.NoClassDefFoundError: javax/jms/JMSSecurityRuntimeException
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2499)
at java.lang.Class.getDeclaredField(Class.java:1951)
at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1659)
at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:72)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:480)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:468)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:602)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:78)
at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:42)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at p_esb.route_order_status_test_0_1.route_order_status_test$1.getCamelContextMap(route_order_status_test.java:149)
at org.apache.camel.main.MainSupport.postProcessContext(MainSupport.java:394)
at org.apache.camel.main.Main.doStart(Main.java:108)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:147)
at p_esb.route_order_status_test_0_1.route_order_status_test.run(route_order_status_test.java:184)
at p_esb.route_order_status_test_0_1.route_order_status_test.runJobInTOS(route_order_status_test.java:270)
at org.talend.esb.job.controller.internal.RouteAdapter.run(RouteAdapter.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSSecurityRuntimeException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:455)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 37 more

I think I got a conflict with another JMS jar (other than the jboss-jms-api.jar, which is a JMS 2.0 spec).
How did you solve this ?