Using the Publish action to asynchronously invoke a service

In this recipe, we will use the Publish action to asynchronously invoke a service from the proxy service message flow, without having to wait for the calling service to finish its processing.

For this recipe, we have an external Processing Service, available as a soapUI mock service which takes quite some time to do its processing. The interface in the Processing Service WSDL is defined synchronous. We have a business service Processing which allows us to invoke the external service from a proxy service.

Instead of directly invoking the business service from the Publish proxy service, an additional proxy service Processing is added, which only exposes a one-way interface. By doing that, the Publish proxy service can use a Publish action to invoke the Processing proxy service without having to wait for external service to complete.

Using the Publish action to asynchronously invoke a service

Getting ready

You can import the OSB project containing the base setup for this recipe, with the Processing Service business and proxy service already implemented into Eclipse OEPE from chapter-9getting-readyusing-publish.

Start the soapUI mock service simulating the Processing Service by double-clicking on start-ProcessingService.cmd in the chapter-9getting-readymisc folder.

How to do it...

Let's implement the Publish proxy service, which will use the Publish action to invoke the Processing proxy service. In Eclipse OEPE, perform the following steps:

  1. Create a new proxy service in the proxy folder and name it Publish.
  2. On the General tab select Any XML Service for the Service Type option.
  3. Navigate to the Message Flow tab.
  4. Insert a Pipeline Pair node and name it PublishPipelinePair.
  5. Insert a Stage node into the Request Pipeline and name it PublishStage.
  6. Insert a Publish action into the Stage.
  7. On the Properties tab of the Publish action, click Browse.
  8. Select the Processing proxy service inside the proxy folder and click OK.
  9. Insert a Log action after the Publish action.
  10. On the Properties tab of the Log action, click <Expression> and enter 'Publish completed, continue with processing in Publish proxy service' into the Expression field.
  11. Click OK.
  12. Select Warning from the Severity drop-down listbox.
  13. Deploy the project to the OSB server.

    Now, let's test OSB project by performing the following steps in the Service Bus console:

  14. In the Project Explorer navigate to proxy folder inside the using-publish-to-async-invoke-service project.
  15. Click on the Launch Test Console icon of the Publish proxy service.
  16. Leave the Payload field empty and directly click Execute.
  17. The output of the Log action from the Publish proxy service should be shown first in the Service Bus console window, followed a few seconds later by the output of the Log action from the Processing proxy service, which is shown after the external service has completed its work.
    How to do it...

How it works...

We have used the Publish action in this recipe to asynchronously invoke a service, the Processing proxy service, with a one-way service interface. The Processing proxy service wraps some processing which takes longer to complete. Actually the external service, mocked by soapUI will use the ID passed (which is hardcoded in the Replace action of the Processing proxy service to the value of 10) to the Processing Service as the time in seconds to wait until the response is sent back. Therefore, the Processing proxy service will only show its Log output after a bit more than 10 seconds. However, because the Publish proxy service uses the Publish action to invoke the Processing proxy service, he/she does not have to wait and the Publish action finishes immediately. The processing of the Processing proxy service is done in a separate thread and is completely independent from the invoking service. The Log action in the Publish proxy service executes immediately and is therefore shown first in the Service Bus console log window.

See also

  • See the Creating private proxy services recipe for another usage of the Publish action and how to use the local protocol on a proxy service, to hide it from external consumers.
  • Check the Using the Service Callout action to invoke a service recipe for how to call another service synchronously.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset