4 Replies Latest reply on May 11, 2009 6:16 AM by Kevin Conner

    ServiceInvoker -- deliverAsync question ?

    Rajneesh Kapur Newbie

      hi All,

      how should I receive/pickup response to a service --> when I use serviceInvoker.deliverAsync(msg). Do I have to use TwoWayInvoker ?

      All the documentation that I see is using Sync as example. Can someone please give an example?

      Thanks a lot,
      -rishi

        • 1. Re: ServiceInvoker -- deliverAsync question ?
          Rajneesh Kapur Newbie

          It is such a good feeling when things work and sometimes its like "oh yeah - that's exactly it."

          Lots of thanks to my colleague - who helped figured out.

          private void sendAsync() {
           try {
           System.setProperty("javax.xml.registry.ConnectionFactoryClass",
           "org.apache.ws.scout.registry.ConnectionFactoryImpl");
          
           ServiceInvoker invoker = new ServiceInvoker("FirstServiceESB",
           "SimpleListener");
          
           Message requestMessage = MessageFactory.getInstance().getMessage();
           requestMessage.getBody().add("hello world.");
           requestMessage.getProperties().setProperty("name", "testMessage");
          
          
           Properties props = new Properties();
           props.put("java.naming.factory.initial",
           "org.jnp.interfaces.NamingContextFactory");
           props.put("java.naming.provider.url", "jnp://localhost:1099");
           props.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
          
          
           JMSEpr replyToEPR = new JMSEpr("1.1", "queue",
           "quickstart_helloworld_Request_esb",
           "ConnectionFactory", props, "name='testMessage'");
          
           TwoWayCourier twoWayCourier = CourierFactory
           .getPickupCourier(replyToEPR);
          
           requestMessage.getHeader().getCall().setReplyTo(replyToEPR);
          
           invoker.deliverAsync(requestMessage);
          
           Message responseMessage = twoWayCourier.pickup(60000);
          
           System.out.println(responseMessage.getBody().get().toString());
          
           } catch (Exception e) {
           e.printStackTrace();
           }
           }
          


          • 2. Re: ServiceInvoker -- deliverAsync question ?
            Tom Fennelly Master

            This is effectively what ServiceInvoker.deliverSync does. Why did that not work, or did you simply miss it?

            • 3. Re: ServiceInvoker -- deliverAsync question ?
              Rajneesh Kapur Newbie

              yes, I should have probably open source code for Sync method. But the requirement was to demonstrate both mechanism.

              yes, I think I simply missed the details in documentation. thanks anyways

              kind regards -- rishi

              • 4. Re: ServiceInvoker -- deliverAsync question ?
                Kevin Conner Master

                Bit this does not demonstrate async behaviour as the intent with async is to allow processing to occur at a later time and on a different thread. This frees resources (threads etc), works well with transactions and scales much better than synchronous calls.

                As Tom says, all you have done is duplicate the sync behaviour.