Use the Mule ESB to orchestrate restful services with groovy

Source: Internet
Author: User
Tags resource mule esb

The rest-style software architecture has gained more and more recognition over the past few years, mainly because it reduces the need for moving parts of the system, while making the system less coupled and more resilient.

With more and more rest resources currently appearing in enterprise applications, it is important to orchestrate these resources. For example, a typical business activity involves the creation of resources, and then the discovery of resources and the creation of other resources.

In essence, the interaction with the restful service is fairly straightforward: you need to construct and send the appropriate request (Request header and request body), and then parse the returned response (response header and response body). This process does not require any special tools or frameworks, as long as a good HTTP client library is sufficient. In addition, because the different entities involved in the restful interaction are defined by so-called micro-formats, the ability to easily parse or export these entities is important.

The choreography of interacting with multiple resources is a tricky issue. We need to define choreography, handle errors, and keep trying, and the system must be able to perform well under pressure. As an integrated framework, Mule provides everything we need.

Consider an example of a business system that deals with new orders in a format that requires the following:

Create a new order by sending an XML entity to the service.

Look for the newly created order resource and extract the confirmation from it.

Send a confirmation message to the customer based on the confirmation information and through the Mail gateway.

We will detail the interaction process for each of these steps in this article, as well as the mule and groovy features needed to get the above interaction.

The overall choreography consists of a series of mule services connected through specific routes, filters, and Memory message queues (aka VM queues). The recent Infoq article on the message routing in Mule, you may wish to step into the view.

Mule Support for rest

Mule provides a simple and powerful way to interact with the Resfful service, which is mule Restpack.

Mule Restpack provides a full set of connectors and complete guides to help users create new restful applications. At the time this article was written, the package provided three types of transporter, based on three popular rest frameworks: Abdera, Jersey, and Restlet. So we can easily expose new resources, but how do we integrate existing rest resources?

The good news is that the groovy support provided by the Mule Standard Scripting module helps mule the use of the HTTP transporter so that we can successfully interact with the RESTful service. Send a POST request to mule

First, let's take a look at the first interaction. HTTP sends an XML entity to a specific resource to create an order, as shown in the following program fragment:

POST /orders HTTP 1.1
...
<order xmlns='urn:acme:order:3:1'>
   <customerId>123456</customerId>
   <productId>P987C</productId>
   <quantity>2</quantity>
</order>

If the response of the successful server is as follows:

201 Created
Location: http://acme.com/order/O13579
...
<order id='O13579' />

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.