3 Replies Latest reply on Jun 16, 2009 12:37 PM by Rajneesh Kapur

    Invoking Service Invoker on client side...

    Rajneesh Kapur Newbie

      Hi All,

      I have a requirement where ServiceInvoker should listen on a queue - picks a message - and goes back to listen again.

      I implement the part with:

      Message message = TwoWayCourier.pickup(long waitTime, EPR epr)


      here after serviceInvoker picks a message - it exits. But I was wondering how can I make it go back to listen again. Should I use some sort of while loop ?

      Thanks a lot,
      -rishi


        • 1. Re: Invoking Service Invoker on client side...
          Scott Dawson Apprentice

          Rishi,
          Have you considered using a JMS client? Instantiate a class that implements javax.jms.MessageListener and the onMessage method will get called every time a message arrives on the queue. Then the listener will resume listening. An asynchronous JMS client fits your use case perfectly.

          Regards,
          Scott

          • 2. Re: Invoking Service Invoker on client side...
            Rajneesh Kapur Newbie

            Thanks Scott for the reply.

            Yes, but one of the main reason I like ServiceInvoker is that it handles Failover.

            btw, I tried to use the same instance of TwoWayCourier in while loop - but it won't pick up all the messages consistently. If I publish 5 messages - it picks 2 or 3 sometimes. I feel somewhere I am making a mistake.

            Here is what I did:

            Client Side
            1) Standalone client to listen on queue using TwoWayCourier.

            Server Side (ESB)
            1) In service; first action logs the message and second action route it to responseQueue using JMSRouter. This is where client is listening.

            please let me know if its correct why to do this.

            Thanks a lot, regards,
            rishi

            • 3. Re: Invoking Service Invoker on client side...
              Rajneesh Kapur Newbie

              It's working now. I somehow did not grasped statement in JavaDocs earlier.

              As per JavaDocs for CourierFactory.getPickupCourier(epr); I should prime "replyTo address" and "to address" with EPR that we are listening on. After I did that it started working.

              Here is what I did in client:

              JMSEpr pickupEPR = new JMSEpr("1.1", "queue", "responseQueue",
               "ConnectionFactory", props, null);
              TwoWayCourier twoWayCourier = CourierFactory.getPickupCourier(pickupEPR);
              twoWayCourier.setReplyToEpr(pickupEPR);
              twoWayCourier.setToEpr(pickupEPR);
              Message responseMessage = null;
              do {
               responseMessage = twoWayCourier.pickup(20000);
              
              }while (System.currentTimeMillis() < timeToWait);
              


              Now I don't need to create separate instances and I receive all messages correctly. Thanks all,
              -rishi