Thursday, October 11, 2012

Creating a File based JMS Distributed Queue on a Weblogic Cluster for HA- PART3 (enqueue client and dequeue mdb)



…Contd
To check if the messages are distributed among the queues, we can enqueue some messages and check. Below is a sample code to enqueue some messages.
Enqueue Example

   1:  package com.redstacklogic.examples.jms;
   2:   
   3:  import java.util.Hashtable;
   4:   
   5:  import javax.jms.Queue;
   6:  import javax.jms.QueueConnection;
   7:  import javax.jms.QueueConnectionFactory;
   8:  import javax.jms.QueueSender;
   9:  import javax.jms.QueueSession;
  10:  import javax.jms.Session;
  11:  import javax.jms.TextMessage;
  12:   
  13:  import javax.naming.Context;
  14:  import javax.naming.InitialContext;
  15:   
  16:  /*
  17:   * @author: Rohith Puchalapalli
  18:   */
  19:  public class JMSEnqueuer {
  20:      public JMSEnqueuer() {
  21:          super();
  22:      }
  23:      public static void main(String[] args) throws Exception {
  24:          Hashtable env = new Hashtable();
  25:          env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  26:          env.put(Context.PROVIDER_URL, "t3://localhost:7004,localhost:7003");
  27:          InitialContext ctx = new InitialContext(env);
  28:   
  29:          QueueConnectionFactory qcf =(QueueConnectionFactory)ctx.lookup("jms/MYJMSCF");
  30:          QueueConnection qc = qcf.createQueueConnection();
  31:          QueueSession qsession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  32:          Queue q = (Queue)ctx.lookup("jms/MYDISTQUEUE");
  33:          QueueSender qs = qsession.createSender(q);
  34:          TextMessage msg = qsession.createTextMessage();
  35:          msg.setText("Message hello world");
  36:          qs.send(msg);
  37:          qs.close();
  38:          qsession.close();
  39:          qc.close();
  40:      }
  41:  }





To Dequeue the messages we will use an MDB. Below is some sample code

MDB code

   1:  package com.redstacklogic.examples.jms;
   2:   
   3:  import java.util.Hashtable;
   4:   
   5:  import javax.jms.Queue;
   6:  import javax.jms.QueueConnection;
   7:  import javax.jms.QueueConnectionFactory;
   8:  import javax.jms.QueueSender;
   9:  import javax.jms.QueueSession;
  10:  import javax.jms.Session;
  11:  import javax.jms.TextMessage;
  12:   
  13:  import javax.naming.Context;
  14:  import javax.naming.InitialContext;
  15:   
  16:  /*
  17:   * @author: Rohith Puchalapalli
  18:   */
  19:  public class JMSEnqueuer {
  20:      public JMSEnqueuer() {
  21:          super();
  22:      }
  23:      public static void main(String[] args) throws Exception {
  24:          Hashtable env = new Hashtable();
  25:          env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  26:          env.put(Context.PROVIDER_URL, "t3://localhost:7004,localhost:7003");
  27:          InitialContext ctx = new InitialContext(env);
  28:   
  29:          QueueConnectionFactory qcf =(QueueConnectionFactory)ctx.lookup("jms/MYJMSCF");
  30:          QueueConnection qc = qcf.createQueueConnection();
  31:          QueueSession qsession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  32:          Queue q = (Queue)ctx.lookup("jms/MYDISTQUEUE");
  33:          QueueSender qs = qsession.createSender(q);
  34:          TextMessage msg = qsession.createTextMessage();
  35:          msg.setText("Message hello world");
  36:          qs.send(msg);
  37:          qs.close();
  38:          qsession.close();
  39:          qc.close();
  40:      }
  41:  }





weblogic-ejb-jar.xml

   1:  <?xml version = '1.0' encoding = 'windows-1252'?>
   2:  <weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   3:                    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
   4:                    xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar">
   5:    <weblogic-enterprise-bean>
   6:      <ejb-name>TestMDB</ejb-name>
   7:      <message-driven-descriptor>
   8:        <destination-jndi-name>jms/MYDISTQUEUE</destination-jndi-name>
   9:        <connection-factory-jndi-name>jms/MYJMSCF</connection-factory-jndi-name>
  10:      </message-driven-descriptor>
  11:    </weblogic-enterprise-bean>
  12:  </weblogic-ejb-jar>





The messages are dequeued by both the servers

image



You can download the jdeveloper project from here  RedStackLogicWLSQueueExamples.zip



PREV  ….

Tuesday, October 9, 2012

Creating a File based JMS Distributed Queue on a Weblogic Cluster for HA- PART2



5.  Create a Connection Factory
a.
  • go to JMS Modules
  • Click on the JMS module where you want to create a Connection Factory
image54_thumb
b. click on configuration tab and click new
image57_thumb1
c. select connection factory and click next
image60_thumb
d. Give a name and JNDI name and click finish
image63_thumb
e. Open the connection factory you just created
f.  Make sure that the Server Affinity is disabled in the Connection factory (Load Balance) Tab
image_thumb4
g. make sure you Add Sub deployment in the connection Factory's Sub deployment tab
image_thumb3


6. Created Distributed Queues

a.
  • go to JMS Modules
  • Click on the JMS module where you want to create a Distributed Queues
image_thumb20

b. Click New
image

c. Select Distributed Queue and click Next

image
d. Give a name and JNDI Name and click next

image

e. Select Advanced Targeting
image
f.  select the previously created sub deployment and click finish
image

..  will be continued tomorrow

prev

Monday, October 8, 2012

Creating a File based JMS Distributed Queue on a Weblogic Cluster for HA- PART1



1. Create Persistent File Stores
You need to create a file store for each member of the cluster.

a. To create file store
  • go to persistent stores
  • click new
  • click  Create  FileStore.
image

  • Give a name
  • Select a Migratable target related for the first managed server
  • Give a directory
image

Similarly create another Filestore for the second migratable targetimage

2. Create JMS Servers
a.
  • Go to JMS Servers
  • Click on New
image
b. Create the JMS Server
  • Give a server Name
  • In the file store select the Persistent store we created Earlier
  • Click next.
image
c. Assign a Migratable target (Same as the FileStore we created earlier)
click finish
image
d. Similarly create another JMS Server for the second server
image
image

image

3.  Create a JMS Module
a.  Go to JMS Module and click new
image

b. give a name and click next.
image
c. Select the cluster and hit next
image

d. hit finish
image

4. Create a subdeployment
a.
  • go to JMS Modules
  • Click on the JMS module where you want to create a Connection Factory
image_thumb20_thumb
b. Click on subdeployments tab
image_thumb
c. click new
image_thumb1
d. give a name and click next
image_thumb2
e. Select the JMS Servers we created and click finish
image_thumb3


Next