3 Replies Latest reply on Aug 21, 2006 12:08 AM by Erik Westland

    Using JNDIProviderAdapter from client (MDB) code?

    Erik Westland Newbie


      I am successfully using EJB3 MDBs to connect to a remote destination; defined a "RemoteJMSProvider" and connected using the "providerAdapterJNDI" annotation (see: http://wiki.jboss.org/wiki/Wiki.jsp?page=HowDoIConfigureAnEJB3MDBToTalkToARemoteQueue)

      The twist is that I need to send another JMS message from within the MDB, so I need to create a client JMS connection. It seems cleanest to reuse this provider, but I am not sure if I can/should.

      InitialContext ctx = new InitialContext();
      JNDIProviderAdapter remoteProvider = (JNDIProviderAdapter)ctx.lookup("java:/RemoteJMSProvider");
      ConnectionFactory connectionFactory = ???
      Connection conn = connectionFactory.createConnection();

      API for JNDIProviderAdapter:

      * Can/should I use the JNDIProviderAdapter to get a ConnectionFactory?
      * If so, which jar contains JNDIProviderAdapter.class (necessary to compile)?


        • 1. Re: Using JNDIProviderAdapter from client (MDB) code?
          Erik Westland Newbie

          "That was easy!!!" - sigh...

          InitialContext localCtx = new InitialContext();
          JNDIProviderAdapter jmsProvider = (JNDIProviderAdapter) localCtx.lookup("java:/RemoteJMSProvider");
          Properties jmsProviderProps = jmsProvider.getProperties();
          InitialContext remoteCtx = new InitialContext(jmsProviderProps);
          Destination topic = (Destination) remoteCtx.lookup("queue/test");

          Note: You will need to include jboss.jar in build path.


          • 2. Re: Using JNDIProviderAdapter from client (MDB) code?
            Elias Ross Master

            For inbound, define your configuration in standardjboss.xml and then in jboss.xml:

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

            It's better to use a -ds.xml file (JCA) connection to your provider outbound.

            Then you simply do:
            ConnectionFactory cf =
             new InitialContext().lookup("java:/RemoteJmsXA");
            Connection c = cf.createQueueConnection();
            try {
            } finally {

            • 3. Re: Using JNDIProviderAdapter from client (MDB) code?
              Erik Westland Newbie

              Thanks for the tip...

              I am pretty wiped out now, so forgive me, but I don't quite get your solution.

              My objective is indeed to use "a -ds.xml file (JCA) connection to your provider outbound", but my initial problem was getting access to the destinations on the remote JMS provider. My JBoss-specific (hokey?) solution does that.

              I like that your solution looks portable, but it appears to be missing some of the extra sauce. My issue is that I am unclear how to lookup the remote destination (i.e. "queue/test") etc; assuming remote provider defined as "RemoteJmsXA" (i.e. ./deploy/jms/remotejmsxa-ds.xml).

              If you could extend your example a bit to include creating a "MessageProducer" to a remote queue it would be helpful.

              Standard example client code:

              InitialContext ctx = new InitialContext();
              Destination topic = (Destination) ctx.lookup("queue/test");
              ConnectionFactory factory = (ConnectionFactory)ctx.lookup("UIL2ConnectionFactory");
              Connection connection = factory.createConnection();
              Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
              MessageProducer publisher = session.createProducer(topic);