Mule ESB Service 配置摘要

1.when to use a service
Unless you specifically want to use Service, you should instead look at using  Configuration Patterns or Flows instead
2.Service Message Styles 
(1) One –way  单向的
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
http://www.mulesoft.org/schema/mule/test
http://www.mulesoft.org/schema/mule/test/3.0/mule-test.xsd
http://www.mulesoft.org/schema/mule/jms
http://www.mulesoft.org/schema/mule/jms/3.0/mule-jms.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<model name="Asynchronous_Message_Pattern">
<service name="AsynchronousService">
<inbound>
<jms:inbound-endpoint queue="test.in" exchange-pattern="one-way"/>
</inbound>
<test:component/>
</service>
</model>
</mule>
(2) request- response 双向的
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
http://www.mulesoft.org/schema/mule/test
http://www.mulesoft.org/schema/mule/test/3.0/mule-test.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/3.0/mule-http.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<model name="Request-Response_Message_Pattern">
<service name="SynchronousService">
<inbound>
<http:inbound-endpoint host="localhost" port="8080" path="/mule/services"
exchange-pattern="request-response"/>
</inbound>
<test:component/>
</service>
</model>
</mule>
(3) Synchronous
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
http://www.mulesoft.org/schema/mule/test
http://www.mulesoft.org/schema/mule/test/3.0/mule-test.xsd
http://www.mulesoft.org/schema/mule/jms
http://www.mulesoft.org/schema/mule/jms/3.0/mule-jms.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<model name="Synchronous_Message_Pattern">
<service name="SynchronousService">
<inbound>
<jms:inbound-endpoint queue="test.in" exchange-pattern="request-response"/>
</inbound>
<test:component/>
<outbound>
<pass-through-router>
<jms:outbound-endpoint queue="test.out" exchange-pattern="one-way"/>
</pass-through-router>
</outbound>
</service>
</model>
</mule>
(4) Async Request Response
    <mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
http://www.mulesoft.org/schema/mule/test
http://www.mulesoft.org/schema/mule/test/3.0/mule-test.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/3.0/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms
http://www.mulesoft.org/schema/mule/jms/3.0/mule-jms.xsd
http://www.mulesoft.org/schema/mule/scripting
http://www.mulesoft.org/schema/mule/scripting/3.0/mule-scripting.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<model name="Async_Request-Response_Message_Pattern">
<service name="AsyncRequestResponseService">
<inbound>
<http:inbound-endpoint host="localhost" port="8080" path="/mule/services"
exchange-pattern="request-response"/>
</inbound>
<test:component/>
<outbound>
<multicasting-router>
<jms:outbound-endpoint queue="service1" exchange-pattern="one-way"/>
<jms:outbound-endpoint queue="service2" exchange-pattern="one-way"/>
<reply-to address="jms://reply.queue"/>
</multicasting-router>
</outbound>
<async-reply timeout="5000">
<jms:inbound-endpoint queue="reply.queue" exchange-pattern="one-way"/>
<collection-async-reply-router/>
</async-reply>
</service>
</model>
</mule>
3.Configuring the Service 配置service
Each service can be configured with the following optional elements:
<description>: Describes the service (描述服务)
<inbound>: Configures the inbound routers, their endpoints, and inbound transformers(在此配置路由器,它们的端点,入口转换器)
component: Configures the service component (配置服务组件)
<outbound>: Configures the outbound routers, their endpoints, and outbound transformers(在此配置出口路由器,它们的端点,出口转换器)
<async-reply>: Configures an async reply router, which is used for asynchronous request-response messaging(配置一个异步回复路由器,它被用来处理 request-response模式的消息)
<exception-strategy>: Configures the exception strategy for the service (配置异常策略)
注意:
If you configure more than one of these elements, note that you must configure them in the order shown above.
样例:
<service name="GreeterUMO">
<description>Adds some text to the string before passing it on</description>
<inbound>
<stdio:inbound-endpoint system="IN">
<transformer ref="StdinToNameString"/>
</stdio:inbound-endpoint>
</inbound>
<component class="org.mule.example.hello.Greeter" />
<outbound>
<filtering-router>
<vm:outbound-endpoint path="chitchatter" />
<payload-type-filter expectedType="org.mule.example.hello.NameString" />
</filtering-router>
</outbound>
<default-service-exception-strategy>
<vm:outbound-endpoint path="systemErrorHandler" />
</default-service-exception-strategy>
</service>
4.service内部标签介绍
(1) Inbound
This element is used to configure inbound endpoints and inbound routers. Endpoints are used to receive incoming messages, and inbound
routers determine how these messages are routed. Inbound endpoints and routers are configured separately within the <inbound> element
(2) Inbound Endpoints
Inbound endpoints are used to receive incoming messages. An endpoint is simply a set of instructions indicating which transport and
path/address to receive messages from, as well as any transformers, filters, or security that should be applied when receiving the messages. You
can configure multiple inbound endpoints, each receiving message from different transports.
(3) Inbound Routers
The <inbound> element configure inbound routers. Inbound routers control and manipulate messages received by a service before passing
them to the service component. Typically, an inbound router is used to filter incoming messages, aggregate a set of incoming messages, or
re-sequence messages when they are received. Inbound routers are also used to register multiple inbound endpoints for a service. You can chain
inbound routers together, so that each router must be matched before the message can be passed to the component. You can also configure a
catch-all strategy that is invoked if none of the routers accept the current message
(4) Component
The <component> element configures the service component that will be invoked after the inbound message is processed by the inbound
routers. If no component is configured, the service acts as a bridge and simply passes messages through to the outbound router.
There are several standard components you can use, such as <log-component>, which logs component invocations, outputting the received
message as a string, and <echo-component>, which extends the log component to log and echo the incoming message. Typically, you will
create your own component as a plain old Java object (POJO) and configure it using the <component> element
(5) outbound
The <outbound> element configures outbound routers and their endpoints. Because outbound routers are used to determine which endpoints to
use for dispatching messages after the component has finished processing them, outbound endpoints are configured on the outbound routers, not
directly on the <outbound> element. Outbound routers allow the developer to define multiple routing constraints for any given message. You can
specify a catch-all strategy to invoke if none of the routers accept the current message.
(6) Asynchronous Reply Router
The <async-reply> element is used to configure the endpoints and routers that will be used to receive the response in asynchronous
request-response scenarios where you must consolidate responses from a remote endpoint before the current service responds via its inbound
endpoint. The classic example of this approach is where a request is made and then multiple tasks are executed in parallel. Each task must finish
executing and the results processed before a response can be sent back to the requester. For an illustration of asynchronous request-response,
click here


5.Service 配置中常用的filter配置介绍
Message routers are used within Using Mule Services to control how messages are sent and received by components in the system. 
注意:WithinUsing Flows for Service Orchestration, the same job is performed by message processors(在消息流中,同样的工作用消息处理器来代替)
下面是常用的路由器列表

Inbound Routers Outbound Routers Async-Reply Routers Catch-all Strategies
No Router Pass-through Single Forwarding
Selective Consumer Filtering Collection Custom Fowarding
Idempotent Receiver Recipient List Routers Custom Logging
Idempotent Secure Hash Receiver Multicasting Custom
Collection Aggregator Chaining
Message Chunking Aggregator List Message Splitter
Custom Correlation Aggregator Filtering XML Message Splitter
Correlation Resequencer Expression Splitter Router
Forwarding Message Chunking Router
WireTap Exception Based Routers
Custom Template Endpoint
Round Robin Message Splitter
Custom

每个路由器如何配置,查看Mule ESB 官网Guide.pdf Using Message Routers 这一节
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值