5 Replies Latest reply on Feb 15, 2002 7:42 PM by Mary Jane

    Connecting from mdb to remote queue

    judy Newbie

      I've read all posts in the forum, but i cant get it to run.
      My situation:

      Host1 ----------------- Host2
      Jboss-2.4.3-----------Jboss-2.4.3 - simple MDB
      |
      |
      TestClient

      The TestClient send a message to a queue (testQueue) of JBoss on host1:

      public static void main(String args[]) {
      Context jndiContext = null;
      QueueConnectionFactory queueConnectionFactory = null;
      QueueConnection queueConnection = null;
      QueueSession queueSession = null;
      Queue queue = null;
      QueueSender queueSender = null;
      TextMessage message = null;
      try {
      java.util.Properties props = new java.util.Properties();
      props.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      props.setProperty("java.naming.provider.url",
      "jnp://localhost:1099");
      props.setProperty("java.naming.factory.url.pkgs",
      "org.jboss.naming.org.jnp.interfaces");
      jndiContext = new InitialContext(props);
      } catch (NamingException e) {
      System.out.println("Could not create JNDI " +
      "context: " + e.toString());
      System.exit(1);
      }
      try {
      queueConnectionFactory = (QueueConnectionFactory)
      jndiContext.lookup
      ("QueueConnectionFactory");
      queue = (Queue) jndiContext.lookup("queue/testQueue");
      } catch (NamingException e) {
      System.out.println("JNDI lookup failed: " +
      e.toString() + "\n " + e.getMessage());
      System.exit(1);
      }
      try {
      queueConnection = queueConnectionFactory.createQueueConnection();
      queueSession =
      queueConnection.createQueueSession(false,
      Session.AUTO_ACKNOWLEDGE);
      queueSender = queueSession.createSender(queue);
      message = queueSession.createTextMessage();
      message.setText("message - send for testing");
      queueSender.send(message);
      } catch (JMSException e) {
      System.out.println("Exception occurred: " + e.toString());
      } finally {
      if (queueConnection != null) {
      try {
      queueConnection.close();
      } catch (JMSException e) {}
      }
      }
      }

      On Host2 the MDB should get the messages from the testQueue on Host1:

      MDB:
      public class Mail_2 implements MessageDrivenBean, javax.jms.MessageListener {
      private transient MessageDrivenContext mdc = null;
      private Context context;
      private int counter = 0;
      public Mail_2() {
      System.out.println("In Constructor of Mail");
      }
      public void setMessageDrivenContext(MessageDrivenContext mdc) {
      System.out.println("In Mail.setMessageDrivenContext()");
      this.mdc = mdc;
      }
      public void ejbCreate() {
      System.out.println("In Mail.ejbCreate()");
      }
      public void onMessage(Message inMessage) {
      TextMessage msg = null;
      try {
      if (inMessage instanceof TextMessage) {
      msg = (TextMessage) inMessage;
      System.out.println("MESSAGE BEAN: Message received: "
      + msg.getText());
      } else {
      System.out.println("Message of wrong type: "
      + inMessage.getClass().getName());
      }
      } catch (JMSException e) {
      e.printStackTrace();
      }
      }
      public void ejbRemove() {
      System.out.println("In Mail.remove()");
      }
      }

      And on host2 i have added a RemoteJMSProvider in the jboss.jcml:

      <mbean code="org.jboss.jms.jndi.JMSProviderLoader" name=":service=JMSProviderLoader, name=RemoteJMSProvider"
      RemoteJMSProvider
      192.168.30.86:1099
      XAConnectionFactory
      XAConnectionFactory
      org.jboss.jms.jndi.JBossMQProvider


      The jboss.xml of the MDB:
      <?xml version="1.0" encoding="Cp1252"?>

      <enterprise-beans>
      <message-driven>
      <ejb-name>Mail_2</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/testQueue</destination-jndi-name>
      </message-driven>
      </enterprise-beans>
      <container-configurations>
      <container-configuration>
      <container-name>My Message Driven Config</container-name>
      <call-logging>false</call-logging>
      <container-invoker>org.jboss.ejb.plugins.jms.JMSContainerInvoker</container-invoker>
      <!-- <container-interceptors>
      org.jboss.ejb.plugins.LogInterceptor
      org.jboss.ejb.plugins.SecurityInterceptor
      --> <!-- CMT -->
      <!-- org.jboss.ejb.plugins.TxInterceptorCMT
      org.jboss.ejb.plugins.MetricsInterceptor
      org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor
      --> <!-- BMT -->
      <!-- org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor
      org.jboss.ejb.plugins.MessageDrivenTxInterceptorBMT
      org.jboss.ejb.plugins.MetricsInterceptor
      </container-interceptors>-->
      <instance-pool>org.jboss.ejb.plugins.MessageDrivenInstancePool</instance-pool>
      <instance-cache></instance-cache>
      <persistence-manager></persistence-manager>
      <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
      <container-invoker-conf>
      RemoteJMSProvider
      StdJMSPool
      15
      1
      True
      </container-invoker-conf>
      <container-pool-conf>
      100
      10
      </container-pool-conf>
      </container-configuration>
      </container-configurations>


      And the ejb-jar.xml:
      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar>
      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>Mail_2</ejb-name>
      <ejb-class>mail2.Mail_2</ejb-class>
      <message-selector></message-selector>
      <transaction-type>Container</transaction-type>
      <!-- <acknowledge-mode>Auto-acknowledge</acknowledge-mode>-->
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      </message-driven>
      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Mail_2</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      I get no exception, but the mdb on host2 never revieces a message.
      I have no idea.
      Thanks for help

      judy

        • 1. Re: Connecting from mdb to remote queue
          Peter Antman Expert

          Almost allways when it does not work between two hosts the hostname resolution is flawad. It may have to do witn your DNS/etc/hosts or with your RMI setting.

          What does the mdb on host2 say when deployed. Does it connect and create sesssion (turn on debugging).

          //Peter

          • 2. Re: Connecting from mdb to remote queue
            judy Newbie

            Thanks.
            It looks like the Server is only looking for the DefaultJMSProvider, even though i specified the RemoteJMSProvider in the jboss.xml of the MDB.Maybe there is something wrong with the configuration in the jboss.xml.

            judy

            here are the log Messages:

            [Configuration] ProviderName set to DefaultJMSProvider in :service=JMSProviderLoader,name=JBossMQProvider
            [Configuration] ProviderAdapterClass set to org.jboss.jms.jndi.JBossMQProvider in :service=JMSProviderLoader,name=JBossMQProvi
            der
            [Configuration] QueueFactoryRef set to java:/XAConnectionFactory in :service=JMSProviderLoader,name=JBossMQProvider
            [Configuration] TopicFactoryRef set to java:/XAConnectionFactory in :service=JMSProviderLoader,name=JBossMQProvider
            [Configuration] ProviderName set to RemoteJMSProvider in :service=JMSProviderLoader, name=RemoteJMSProvider
            [Configuration] ProviderUrl set to 192.168.30.86:1099 in :service=JMSProviderLoader, name=RemoteJMSProvider
            [JBossMQProvider] initializing
            [JMSProviderLoader] Initialized
            [JMSProviderLoader] attempting to bind org.jboss.jms.jndi.JBossMQProvider@5311bd to java:/DefaultJMSProvider
            [JMSProviderLoader] bound adapter DefaultJMSProvider to java:/DefaultJMSProvider
            [JMSProviderLoader] Started
            [JMSProviderLoader] Starting
            [JMSProviderLoader] attempting to bind org.jboss.jms.jndi.JBossMQProvider@1d6065 to java:/RemoteJMSProvider
            [JMSProviderLoader] bound adapter RemoteJMSProvider to java:/RemoteJMSProvider
            [JMSProviderLoader] Started
            [ServerSessionPoolLoader] Starting
            [ServerSessionPoolLoader] pool factory StdJMSPool bound to java:/StdJMSPool
            [ServerSessionPoolLoader] Started
            [J2eeDeployer] install EJB module mail2.jar
            [Container factory] Deploying:file:/home/demo/software/JBoss-2.4.3/tmp/deploy/Default/mail2.jar
            [Verifier] Verifying file:/home/demo/software/JBoss-2.4.3/tmp/deploy/Default/mail2.jar/ejb1001.jar
            [Container factory] Begin java:comp/env for EJB: Mail_2
            [Container factory] End java:comp/env for EJB: Mail_2
            [JMSContainerInvoker] looking up provider adapter: java:/DefaultJMSProvider
            [JMSContainerInvoker] provider adapter: org.jboss.jms.jndi.JBossMQProvider@7aa550
            [JBossMQProvider] no provider url; connecting to local JNDI
            [JBossMQProvider] created context: javax.naming.InitialContext@7b6643
            [JMSContainerInvoker] context: javax.naming.InitialContext@7b6643
            [JMSContainerInvoker] jndiSuffix: testQueue
            [JMSContainerInvoker] Got destination type Queue for Mail_2
            [ConnectionFactoryHelper] using connection factory: org.jboss.mq.SpyXAConnectionFactory@245536
            [ConnectionFactoryHelper] using username/password: null/null
            [ConnectionFactoryHelper] created XAQueueConnection: org.jboss.mq.SpyXAConnection@7a6d18
            [JMSContainerInvoker] destination not found: queue/testQueue reason: javax.naming.NameNotFoundException: testQueue not bound
            [JMSContainerInvoker] creating a new temporary destination: queue/testQueue
            [QueueManager] Initializing
            [JMSServer] addDestination: QUEUE.testQueue, JMSDestination:QUEUE.testQueue

            • 3. Re: Connecting from mdb to remote queue
              Peter Antman Expert

              Hey, look att the line:

              <configuration-name>Standard Message Driven Bean</configuration-name>

              Thats where you define the configuration to use, and the line:

              <container-name>My Message Driven Config</container-name>

              Thats the name of you remote config. Change the first line to contain the name of your special config, and I bet it will start working.

              //Peter

              • 4. Re: Connecting from mdb to remote queue
                judy Newbie

                Thanks very much!
                No it works.

                judy

                • 5. Re: Connecting from mdb to remote queue
                  Mary Jane Newbie

                  I'm having a similar problem. Can you tell me which files you modified on the server side. I think it should be in my case:
                  /usr/local/JBoss-2.4.4_Tomcat-4.0.1/jboss/conf/catalina/jboss.jml

                  and

                  /usr/local/JBoss-2.4.4_Tomcat-4.0.1/jboss/conf/catalina/jndi.properties

                  Is that it? The online docs say there is a remote jboss.xml file that needs to be modified. I'm not sure where that would exist.

                  Help.