TIBCO Enterprise Message Service and WebLogic Server implement the same JMS interface, JMS 1.1. Because of this, ConnectionFactories from both TIBCO Enterprise Message Service and WebLogic Server can be used within the same program to create the connections, sessions, queues, producers, consumers for both JMS providers. Messages can then be sent and received between the two JMS providers.
The JMS 1.1 interfaces are defined in the J2EE specification and are provided as part of the J2EE platform in jms.jar
. Table 1 lists where the implementations of this interface are stored and the unique implementation name for both JMS providers:
In this example, only generic calls are used for creation of administrative objects, and the TIBCO Enterprise Message Service server also acts as a JNDI provider.
For both JMS providers, the sample program performs the following:
Create a file named t.java
that has the following contents:
/* * This program defines an object that works for WLS JMS and TIBCO * JMS connection factories and queues. In the sample main, it * generates a TIBCO Enterprise Message Service provider message, * sends and receives it via TIBCO Enterprise Message Service, * sends and receives it via WebLogic Server, then sends and * receives it via TIBCO Enterprise Message Service. * * Usage: java t */ import javax.jms.*; import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; public class t { public static final String TIBCOqcf = "QueueConnectionFactory"; public static final String WLSqcf = "javax.jms.QueueConnectionFactory"; public static final String TIBCOqname = "myQueue"; public static final String WLSqname = "jms.queue.TestQueue1"; public static final String TIBCOurl = "tibjmsnaming://localhost:7222"; public static final String WLSurl = "t3://localhost:7001"; public static final String TIBCOJNDIfactory = "com.tibco.tibjms.naming.TibjmsInitialContextFactory"; public static final String WLSJNDIfactory = "weblogic.jndi.WLInitialContextFactory"; public static void main(String[] args) { JMSobject TIBCOobject = null; JMSobject WLSobject = null; TextMessage msg; Context ctx; try { // Create the TIBCO Enterprise Message Service connection // factory, // connection, session, queue TIBCOobject = new JMSobject(TIBCOurl, TIBCOJNDIfactory, TIBCOqcf, TIBCOqname); // Create the WLS connection factory, connection, session, // queue WLSobject = new JMSobject(WLSurl, WLSJNDIfactory, WLSqcf, WLSqname); msg = TIBCOobject.JMSMessage("Test String"); TIBCOobject.JMSSend(msg); msg = TIBCOobject.JMSReceive(); System.out.println("Received message: "+msg); WLSobject.JMSSend(msg); msg = WLSobject.JMSReceive(); System.out.println("Received message: "+msg); TIBCOobject.JMSSend(msg); msg = TIBCOobject.JMSReceive(); System.out.println("Received message: "+msg); } catch(JMSException je) { System.out.println("Caught JMSException: "+je); Exception le = je.getLinkedException(); if (le != null) System.out.println("Linked exception: "+le); je.printStackTrace(); } catch(Exception e) { e.printStackTrace(); System.out.println("Caught Exception: "+e); } finally { try { if (TIBCOobject != null) TIBCOobject.JMSCleanup(); if (WLSobject != null) WLSobject.JMSCleanup(); } catch (Exception e) { } } } } class JMSobject { private Queue ioQueue; private QueueSession session; private QueueConnection connection; private QueueConnectionFactory factory; private QueueSender queueSender; private QueueReceiver queueReceiver; private InitialContext ctx; JMSobject(String url, String jndi, String qcf, String qname) throws Exception { // Get the initial context Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, jndi); if (url != null) env.put(Context.PROVIDER_URL, url); env.put(Context.REFERRAL, "throw"); ctx = new InitialContext(env); factory = (QueueConnectionFactory)ctx.lookup(qcf); // Create a QueueConnection, QueueSession connection = factory.createQueueConnection(); session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ioQueue = (Queue)ctx.lookup(qname); connection.start(); queueSender = session.createSender(ioQueue); queueReceiver = session.createReceiver(ioQueue); } TextMessage JMSMessage(String text) throws Exception { TextMessage msg = session.createTextMessage(); msg.setText(text); return(msg); } void JMSSend(TextMessage msg) throws Exception { System.out.println("Sending the message on queue " + ioQueue.getQueueName()); queueSender.send(msg); } TextMessage JMSReceive() throws Exception { TextMessage msg; System.out.println("Receiving the message on queue " + ioQueue.getQueueName()); msg = (TextMessage)queueReceiver.receive(1000); if (msg == null) throw new JMSException("Failed to receive message"); return(msg); } void JMSCleanup() throws Exception { if (session != null) { session.close(); session = null; } if (connection != null) { connection.close(); connection = null; } } }
mydomain
, default server name: myserver
, and default port: 7001.C:\bea\wlserver6.1\config\mydomain
(modified based on where you have installed WebLogic Server), modify config.xml
to add the following JMS objects before the final </domain>
line:C:\bea\wlserver6.1\config\mydomain
(modified based on where you have installed WebLogic Server), modify setEnv.cmd
for TIBCO Enterprise Message Service as follows:@rem next line added for TIBCO Enterprise Message Service set TIBJMS_ROOT=\tibco\JMS @rem next line modified for TIBCO Enterprise Message Service setCLASSPATH
=%JAVA_HOME%\lib\tools.jar; %WL_HOME%\lib\weblogic_sp.lar;%WL_HOME%\lib\weblogic.jar; %TIBJMS_ROOT%\java\jms.jar;%TIBJMS_ROOT%\java\jndi.jar; %TIBJMS_ROOT%\java\tibjms.jar; %CLASSPATH
%
startWebLogic.cmd
as follows:C:\bea\wlserver6.1\config\mydomain
. Then run setEnv.cmd
.t.java
using: javac t.java
.
The program is already configured with the URL, default queue connection factory, and JNDI factory of the WebLogic application server. The WebLogic queue name matches the name in the config.xml
file. The program is also configured with the URL, queue connection factory, and JNDI factory of the TIBCO Enterprise Message Service server. The TIBCO queue name matches the name for the queue that will be created in the steps below.
C:\Tibco\EMS\bin\queues.conf
and add the following line at the end: java t
at a command prompt. You should see messages indicating that the program sent and received the message by way of TIBCO Enterprise Message Service, then sent and received the same message via WebLogic Server, then sent and received the message using TIBCO Enterprise Message Service again.
TIBCO Enterprise Message Service™ Application Integration Guide Software Release 4.3, February 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |