4 Replies Latest reply on Mar 7, 2013 9:58 AM by pjr69

    Tips for my scenario + receiving adminstrative messages on MDB?

    pjr69 Newbie

      My scenario:

      - One server running JBoss 7.1.1.Final running the stock standalone-full-ha.xml configuration

      - Several clients that come and go, Java SE desktop applications with Embedded HornetQ 2.2.19.Final.

      - The clients are configured into same cluster with the server.

       

      On the server I have several MDBs that receive service requests from the clients. Each MDB has a separate known queue name (that's how the clients find them) which are also configured on the client side using the hornetq-jms.xml-file. The clients are able to send messages to the MDBs, that much I have verified. However, The MDBs should also be able to send replies to the clients as asynchronous JMS-messages and getting this to work is a bit problematic. The clients do pass their individual unique reply-queue names in the jmsReplyTo-property to the MDBs when making the service requests so the MDBs do know the name of the specific client queue where it should send the reply message once it's finished the service request. But AFAIU, I need to create this queue also on the server side before the server is able to send the reply to the client.

       

      Does that sound feasible use case?

       

      I have two ideas:

      a) When a MDB receives first request from client XYZ, it creates programmatically a queue named "XYZReplies" if it doesn't exist. This queue should be re-used by other MDBs until the client dies (=there are no more consumers to this queue), then it could be removed. So as there are multiple MDBs, the MDB should always check of the queue exists before trying to create it, and if it does, then just re-use it.

       

      b) Make a "manager MDB" on server that receives notification about the clustering bridge being formed and then creates a client-specific queue based on some unique identifier on the bridge. So, when the server is running and client XYZ starts it's embedded HornetQ Server and it forms a bridge with the HornetQ server running on the server, I'd get notification about this on the server and use that notification to create the client-specific queue so the MDBs can send service replies to that queue and the client would be listening to the queue. The point is that the name of the queue would be derived so that both client and server create equally named queues so they match. If the client is shutdown, there would be another notification and I would then programmatically destroy the queue.

       

      Any comments / ideas on my solutions?

       

      For b) I've tried to make a MDB like this:

      @MessageDriven(name = "MyManager", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/NotificationDestination") })
      public class MyManager implements MessageListener {

      @Override
      public void onMessage(Message msg) {
        System.out.println("GOT MESSAGE!"); // check here about bridges coming/going and create/destroy client-reply-queues accordingly
      }
      }

       

      And just dropped that to JBoss deployment and it gets registered, but I never get any messages and no console output (when I start the client, I do get BridgeImpl output about the bridge formation, so that works, but no callback to my MyManager onMessage...). Should I be able to capture management messages (specifically about bridge creationg/destroying) like that?

        • 1. Re: Tips for my scenario + receiving adminstrative messages on MDB?
          pjr69 Newbie

          To continue with this: On my client with the embedded HornetQ service I was able to do the following:

          jms = new EmbeddedJMS();
          jms.start();

          jms.getHornetQServer().getManagementService().addNotificationListener(new NotificationListener() {

          @Override
          public void onNotification(Notification n) {
            System.out.println("*** GOT NOTIFICATION: " + n);
          }
          });

          And it seems that this would give me the required notifications, but this is only on the client side.

           

          Is there any way to do this on the server side? I would need to get access to the HornetQServer inside JBoss, is that possible with some @Resource injection or somehow? Being able to add the NotificationListener inside JBoss would be perfect for my needs.

           

          • 2. Re: Tips for my scenario + receiving adminstrative messages on MDB?
            Andy Taylor Master

            can't you just create a temp queue on your client before you send the message.

             

            or alternatively use a topic with durable subscriptions with message selectors for the replies

            1 of 1 people found this helpful
            • 3. Re: Tips for my scenario + receiving adminstrative messages on MDB?
              Andy Taylor Master

              Is there any way to do this on the server side? I would need to get access to the HornetQServer inside JBoss, is that possible with some @Resource injection or somehow? Being able to add the NotificationListener inside JBoss would be perfect for my needs.

              Notification Listener is just a HornetQ service, its basically just a message listener so you wouldnt be able to do this on the server.

              • 4. Re: Tips for my scenario + receiving adminstrative messages on MDB?
                pjr69 Newbie

                Yep, having considered the case more, temp queues seems to be a suitable way for my scenario. I just need to create a simple temp queue when the client stars and just cache the session, connection and producer and the temp queue while the client is running so AFAIU, there shouldn't be any performance issues either. Furthermore, there is no need to store any reply messages while the client is off-line.