Using TIBCO Enterprise Message Service With WebLogic Server


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:

Table 1 TIBCO Enterprise Message Service and WebLogic Server JMS implementations
Provider
javax.jms.implementation in:
Implementation Name
TIBCO Enterprise Message Service
java/tibjms.jar
com.tibco.tibjms
WebLogic Server
lib/weblogic.jar
weblogic.jms.*

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:

  1. The associated JNDI context is retrieved.
  2. The JMS ConnectionFactory is looked up in that context.
  3. A connection, session, queue, producer and sender are created.
  4. A TIBCO Enterprise Message Service message is created.
  5. The message is sent and received using TIBCO Enterprise Message Service.
  6. The same message and sent and received using WebLogic Server.
  7. The message is then sent and received again using TIBCO Enterprise Message Service.
The Sample Program

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; 
      } 
   } 
} 
Configure WebLogic Server for the Test Program
  1. If you do not already have WebLogic Server, download and install WebLogic Server 6.1 with Service Pack 1. You can retrieve the latest version (and a 30-day trial license, if needed) from http://commerce.bea.com/downloads/weblogic_server.jsp#wls. Select the Microsoft Windows NT/2000 platform (one executable file to download and run). When installing WebLogic Server, choose the default WebLogic Administration Domain Name: mydomain, default server name: myserver, and default port: 7001.
  2. Set up the WebLogic Server configuration to run JMS. In 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:
  3.  
       <JMSServer Name="TestJMSServer" Targets="myserver"> 
         <JMSQueue Name="TestQueue1" JNDIName="jms.queue.TestQueue1"/>  
       </JMSServer> 
    
Configure TIBCO Enterprise Message Service within WebLogic Server
  1. In 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:
  2.  
       @rem next line added for TIBCO Enterprise Message Service 
       set TIBJMS_ROOT=\tibco\JMS 
       @rem next line modified for TIBCO Enterprise Message Service 
       set    CLASSPATH=%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% 
    
  3. In this same directory, modify startWebLogic.cmd as follows:
  4.  
       @rem next line added for TIBCO Enterprise Message Service 
       set TIBJMS_ROOT=\tibco\JMS 
       @rem next line modified for TIBCO Enterprise Message Service  
       set CLASSPATH=.;.\lib\weblogic_sp.jar;.\lib\weblogic.jar; 
       %TIBJMS_ROOT%\java\jms.jar;%TIBJMS_ROOT%\java\jndi.jar; 
       %TIBJMS_ROOT%\java\tibjms.jar 
    
Running WebLogic Server, TIBCO Enterprise Message Service, and the Test Program
  1. To set the environment, change directory to C:\bea\wlserver6.1\config\mydomain. Then run setEnv.cmd.
  2. Compile the program, t.java using: javac t.java.
  3. 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.

  4. Edit C:\Tibco\EMS\bin\queues.conf and add the following line at the end:
  5.  
       myQueue 
     

    This allows queue myQueue to be created.

  6. Start TIBCO Enterprise Message Service by selecting Start > Programs > TIBCO Enterprise Message Service 4.3 > Start JMS Server from the Windows Start menu.
  7. Start the TIBCO Enterprise Message Service administration tool by selecting Start > Programs > TIBCO Enterprise Message Service 4.3 > Start EMS Administration Tool from the Windows Start menu. Enter the following commands at the prompt:
  8.  
       > connect 
       > create factory QueueConnectionFactory queue 
       > create queue myQueue 
       > commit 
    
  9. Start WebLogic Server by selecting Start > Programs > BEA WebLogic E-Business Platform > Weblogic Server 6.1 > Start Default Server from the Windows Start menu, and enter the administrator password.
  10. Run the test program by typing 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