Part 2 - Using JBOSS Messaging from GlassfishESB
Thursday Oct 30, 2008
Overview
In my last blog, I described how to send JMS messages with JBOSS Messaging from a JavaCAPS-GA BPEL module.
In this one, we will switch to 
Environment Setup
Download from https://open-esb.dev.java.net/Downloads.html GlassfishESB (nightly build from October 30th October)Download from http://www.jboss.org/download/
- JBOSS 4.2.3 GA : http://sourceforge.net/project/showfiles.php?group_id=22866&package_id=16942&release_id=614346
- JBOSS Messaging 1.4.0 SP3 : http://www.jboss.org/jbossmessaging/downloads/
Step 1 : Test GlassfishESB/Netabeans6.1 to JBOSS Messaging connectivity
The following Sender & Listener Main Java classes are useful to test your setup.
The JARs to be added :
Sender.java
| /* Use source code downloads, example commands, and any other techniques at your own risk. No warranty is provided. */ import java.util.Properties; import javax.jms.JMSException; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicPublisher; import javax.jms.TopicSession; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class Sender { String url_; String name_; TopicConnection conn = null; TopicSession session = null; Topic topic = null; public Sender(String url, String name) throws JMSException, NamingException { url_ = url; name_ = name; this.initializeSender(); } private void initializeSender() throws JMSException, NamingException { Properties props = new Properties(); props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory" ;props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming" ;props.setProperty("java.naming.provider.url", url_); Context context = new InitialContext(props); TopicConnectionFactory tcf = (TopicConnectionFactory) context.lookup("ConnectionFactory" ;conn = tcf.createTopicConnection(); topic = (Topic) context.lookup(name_); session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); conn.start(); } public void send(String text) throws JMSException, NamingException { // Send a text msg TopicPublisher send = session.createPublisher(topic); TextMessage tm = session.createTextMessage(text); send.publish(tm); send.close(); } public void disconnect() throws JMSException { if(conn != null) { conn.stop(); } if(session != null) { session.close(); } if(conn != null) { conn.close(); } } public String getTopicName() { return name_; } public String getTopicURL() { return url_; } public static void main(String args[]) throws Exception { System.out.println("Starting JMS Example Sender" ;Sender sender = new Sender("localhost:1099", "topic/example" ;System.out.println("Sending list of Adam Sandler Movies" ;sender.send("Billy Madison 1995" ;sender.send("Happy Gilmore 1996" ;sender.send("The Waterboy 1998" ;sender.send("Bid Daddy 1999" ;sender.send("Mr.Deeds 2002" ;sender.send("Eight Crazy Nights 2002" ;sender.send("Anger Management 2003" ;sender.disconnect(); System.out.println("JMS Example Sender Complete - list sent" ;} } |
Listener.java
| /* Use source code downloads, example commands, and any other techniques at your own risk. No warranty is provided. */ import java.util.Properties; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class Listener implements MessageListener { String url_; String name_; TopicConnection conn = null; TopicSession session = null; Topic topic = null; public Listener(String url, String name) { super(); url_ = url; name_ = name; try { this.initializeListener(); } catch (Exception e) { System.out.println("Error creating listener: " + e); e.printStackTrace(); } } public void onMessage(Message msg) { TextMessage tm = (TextMessage) msg; try { System.out.println("Incoming message: " + tm.getText()); } catch (Exception e) { e.printStackTrace(); } } private void initializeListener() throws JMSException, NamingException { Properties props = new Properties(); props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory" ;props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming" ;props.setProperty("java.naming.provider.url", url_); Context context = new InitialContext(props); System.out.println("performing lookup..." ;Object tmp = context.lookup("ConnectionFactory" ;System.out.println("lookup completed, making topic" ;TopicConnectionFactory tcf = (TopicConnectionFactory) tmp; conn = tcf.createTopicConnection(); topic = (Topic) context.lookup(name_); session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); conn.start(); TopicSubscriber recv = session.createSubscriber(topic); recv.setMessageListener(this); } public void disconnect() throws JMSException { if(conn != null) { conn.stop(); } if(session != null) { session.close(); } if(conn != null) { conn.close(); } } public static void main(String args[]) { System.out.println("Starting JMS Example Listener" ;System.out.println("Program will be active for 1 minute." ;//change these values to your situtation: Listener listener = new Listener("localhost:1099", "topic/example" ;//leave it open for 2 minutes: try { Thread.sleep(120000); } catch(Exception e) { System.out.println("Error sleeping: " + e); e.printStackTrace(); } try { listener.disconnect(); } catch(Exception e) { System.out.println("Error terminating listener JMS objects: " + e); e.printStackTrace(); } System.out.println("Done listening" ;} } |
Step 2 :Create a GlassfishESB-BPEL to send JMS messages to JBOSS messaging
At the time of writing, a patch to JMS BC is required to get this stuff up & running with GlassfishESB. This patch should be integrated into the next GlassfishESB nightly builds.
Develop a BPEL module such as :
The key points are :
- deploy the JARs in GlassfishESB appserver
- define the JBOSS wsld as
The definition of the JMS:ADDRESS is a little bit different. Pay attention.
The JDNI name to be used are stored in the JBOSS configuration file : C:\jboss\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\server\default\deploy\jms\jvm-il-service.xml
| <definitions name="newJBOSSWSDL" targetNamespace="http://j2ee.netbeans.org/wsdl/Jboss/newJBOSSWSDL" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns sd="http://www.w3.org/2001/XMLSchema" xmlns:jms="http://schemas.sun.com/jbi/wsdl-extensions/jms/" xmlns:tns="http://j2ee.netbeans.org/wsdl/Jboss/newJBOSSWSDL" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"> <types/> <message name="JMSInputMessage"> <part name="part1" type="xsd:string"/> </message> <portType name="JMSInPortType"> <operation name="JMSInOperation"> <input name="input1" message="tns:JMSInputMessage"/> </operation> </portType> <binding name="JMSInBinding" type="tns:JMSInPortType"> <jms:binding/> <operation name="JMSInOperation"> <jms:operation destination="example" destinationType="Topic" transaction="NoTransaction" subscriptionDurability="NonDurable" concurrencyMode="cc" maxConcurrentConsumers="1"/> <input name="input1"> <jms:message messageType="TextMessage" textPart="part1"/> </input> </operation> </binding> <service name="JMSInService"> <port name="newJBOSSWSDL_InPort" binding="tns:JMSInBinding"> <jms:address connectionURL="jndi://"> <jms:jmsjcaOptions><![CDATA[ #For JNDI (ConnectionURL=jndi://) JMSJCA.UnifiedCF=java:/ConnectionFactory JMSJCA.TopicCF=java:/ConnectionFactory JMSJCA.QueueCF=java:/ConnectionFactory java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces #java.naming.security.principal= #java.naming.security.credentials= ]]> </jms:jmsjcaOptions> </jms:address> </port> </service> <plnk:partnerLinkType name="newJBOSSWSDL"> <!-- A partner link type is automatically generated when a new port type is added. Partner link types are used by BPEL processes. In a BPEL process, a partner link represents the interaction between the BPEL process and a partner service. Each partner link is associated with a partner link type. A partner link type characterizes the conversational relationship between two services. The partner link type can have one or two roles.--> <plnk:role name="JMSInPortTypeRole" portType="tns:JMSInPortType"/> </plnk:partnerLinkType> </definitions> |
Build, Deploy & Run.
It should be OK.
;
sd=









