1 Reply Latest reply on May 3, 2011 8:07 AM by gaohoward

    JBoss Settings for MDB Client ?

    shptlucky

      I have made message driven bean.

      I have made a producer class.

      I am using Netbeans

      Producer Class is sending message to local host and i am recieving it.

      but i am not getting settings to be done for remote connection.

       

      I am striving for last three weeks on it. Please anyone help and tell me what settings is required on client side or server for Remote JMS message retrieving. Code is here under:

       

      For Sending

       

       

      package com;

       

      import java.util.Hashtable;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      import javax.jms.TopicConnectionFactory;

      import javax.jms.TopicConnection;

      import javax.jms.TopicSession;

      import javax.jms.TopicPublisher;

      import javax.jms.Topic;

      import javax.jms.TextMessage;

      import javax.jms.Session;

      import javax.jms.JMSException;

       

      /**

      * <p>Simple JMS client, publish text messages to testTopic Topic.

      * </p>

      *

      * <p><b>NOTE</b>This code is a showcase only. It may not provide

      * a stable production example.</p>

      * @author Peter Antman

      * @version $Revision: 3.1 $

      */

      public class NewClass {

       

          /**

           * Topic connection, hold on to this so you may close it.

           */

          TopicConnection topicConnection;

          /**

           * Topic session, hold on to this so you may close it.

           * Also used to create messages.

           */

          TopicSession topicSession;

          /**

           * Use this to publish messages.

           */

          TopicPublisher topicPublisher;

          /**

           * Destination where to publish.

           */

          Topic topic;

       

          /**

           * Sets up all the JMS fixtures.

           *

           * Use close() when finished with object.

           *

           * @param factoryJNDI name of the topic connection factory to look up.

           * @param topicJNDI name of the topic destination to look up

           */

          public NewClass(String factoryJNDI, String topicJNDI)

                  throws JMSException, NamingException {

       

              // Populate with needed properties

                  Hashtable props = new Hashtable();

                  props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                  props.put(Context.PROVIDER_URL, "192.168.1.218:1099");

                  props.put("java.naming.rmi.security.manager", "yes");

                  props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

       

                  // Get the initial context with given properties

                  Context context = new InitialContext(props);

       

                  System.out.println(factoryJNDI);

       

              // Get the initial context

             // Context context = new InitialContext();

       

              // Get the connection factory

              TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup("java:/XAConnectionFactory");

       

              // Create the connection

              topicConnection = topicFactory.createTopicConnection();

       

              // Create the session

              topicSession = topicConnection.createTopicSession(

                      // No transaction

                      false,

                      // Auto ack

                      Session.AUTO_ACKNOWLEDGE);

       

              // Look up the destination

              topic = (Topic) context.lookup(topicJNDI);

       

              // Create a publisher

              topicPublisher = topicSession.createPublisher(topic);

       

          }

       

          /**

           * Publish the given String as a JMS message to the testTopic topic.

           */

          public void publish(String msg) throws JMSException {

       

              // Create a message

              TextMessage message = topicSession.createTextMessage();

              message.setText(msg);

       

              // Publish the message

              topicPublisher.publish(topic, message);

       

          }

       

          /**

           * Close session and connection.

           * When done, no publishing is possible any more.

           */

          public void close() throws JMSException {

       

              topicSession.close();

              topicConnection.close();

       

          }

       

          /**

           * Run an example publishing 10 messages to testTopic.

           * Only works up to and including JBoss 2.4.0

           */

          public static void main(String[] args) {

              try {

       

                  // Create the HelloPublisher, giving it the name of the

                  // TopicConnection Factory and the Topic destination to

                  // use in lookup.

                  NewClass publisher = new NewClass("ConnectionFactory","topic/testTopic1");

       

                  // Publish 10 messages

                  for (int i = 1; i < 11; i++) {

       

                      String msg = "Hello World no. " + i;

                      System.out.println("Publishing message: " + msg);

                      publisher.publish(msg);

       

                  }

       

                  // Close down your publisher

                  publisher.close();

       

              }

              catch (Exception ex)

              {

       

                  System.err.println("An exception occurred while testing HelloPublisher: " + ex);

                  ex.printStackTrace();

       

              }

       

          }

      } // HelloPublisher

       

       

       

       

      MDB For reciving on Client End

       

      package com;

       

      import java.util.logging.Level;

      import java.util.logging.Logger;

      import javax.ejb.ActivationConfigProperty;

      import javax.ejb.MessageDriven;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageListener;

      import javax.jms.TextMessage;

       

      @MessageDriven(mappedName = "topic/testTopic",

       

          activationConfig =  {

              @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/testTopic"),

              @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

              @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),

              @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),

              @ActivationConfigProperty(propertyName = "clientId", propertyValue = "DrivenBean6"),

              @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "DrivenBean6")

       

                              })

       

      public class DrivenBean implements MessageListener {

       

          public DrivenBean() {

          }

       

           TextMessage tx=null;

          public void onMessage(Message message)

          {

              tx=(TextMessage) message;

              try {

                  System.out.println("Driven Bean -> " + tx.getText());

              } catch (JMSException ex) {

       

              }

              System.out.println("Hello");

          }

       

      }

       

      What Settings are required so that i could send message to client end.