我在mule esb中尝试以下场景时遇到问题:
1)以下列格式发出http请求获取有效负载:
<result><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>20</seat_num><seat_increment>1</seat_increment><Cost>903</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>21</seat_num><seat_increment>1</seat_increment><Cost>904</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>22</seat_num><seat_increment>1</seat_increment><Cost>905</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>23</seat_num><seat_increment>1</seat_increment><Cost>905</Cost></row></result>
2)通过将一些逻辑应用于此格式的xml来转换有效负载。
<listings>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>903</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>1</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>20</seats>
<splitOption>NONE</splitOption>
</listing>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>904</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>1</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>21</seats>
<splitOption>NONE</splitOption>
</listing>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>905</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>2</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>22,23</seats>
<splitOption>NONE</splitOption>
</listing>
</listings>
3)使用拆分器
拆分消息<splitter enableCorrelation="ALWAYS" expression="#[xpath('//listings/listing')]" doc:name="ListingRequestSplitter"/>
4)使用请求 - 应答路由器将这些消息路由到dispatchIn VM队列
<request-reply storePrefix="listmsg" doc:name="Put message for processing">
<vm:outbound-endpoint path="dispatchIn">
<message-properties-transformer scope="outbound">
<delete-message-property key="MULE_REPLYTO" />
</message-properties-transformer>
</vm:outbound-endpoint>
<vm:inbound-endpoint path="dispatchOut" />
</request-reply>
5)正在处理侦听dispatchIn队列
的第二个流程 <flow name="ListingMessageProcessorFlow" doc:name="ListingMessageProcessorFlow">
<vm:inbound-endpoint path="dispatchIn"/>
<message-properties-transformer scope="invocation" doc:name="Remember correlation">
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_ID]" key="cid" />
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_GROUP_SIZE]" key="cgs" />
</message-properties-transformer>
<logger message="ListingMessageProcessorFlow - Splitted Message : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api-dev.srwd10.com" port="443" path="inventory/listings/v1/" method="POST" doc:name="HTTP" connector-ref="HTTP_HTTPS" transformer-refs="DOM_to_XML" contentType="application/xml" mimeType="application/xml">
<message-properties-transformer scope="outbound">
<add-message-property key="Authorization" value="Bearer 8da2ba50b471958168dfe0d4efd0f428" />
<add-message-property key="TARGET_HOST" value="srwq12" />
<add-message-property key="Acccept" value="application/xml" />
</message-properties-transformer>
</https:outbound-endpoint>
<message-properties-transformer scope="outbound">
<add-message-property value="#[header:INVOCATION:cid]" key="MULE_CORRELATION_ID" />
<add-message-property value="#[header:INVOCATION:cgs]" key="MULE_CORRELATION_GROUP_SIZE" />
</message-properties-transformer>
<vm:outbound-endpoint path="vm.aggregate" />
</flow>
<flow name="ListingMessageResponseAggregator">
<vm:inbound-endpoint path="vm.aggregate" />
<logger message="ListingMessageResponseAggregator - CorelationID : #[header:MULE_CORRELATION_ID], CorelationGroupSize : #[header:MULE_CORRELATION_GROUP_SIZE], Payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<collection-aggregator doc:name="Collection Aggregator" />
<vm:outbound-endpoint path="dispatchOut" />
</flow>
6)请求 - 回复出站配置将消息推送到dispatchOut队列。
我看到只有第一条消息得到处理,所有消息才会进入超时状态。如果我在这里做错了,有人可以提供帮助。这是完整的配置:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd">
<!-- HTTPS Connection Configuration With CERTS -->
<https:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
<https:tls-server path="/Users/rkesara/opt/MULE/truststore/cacerts" storePassword="changeit" />
</https:connector>
<!-- List of transformers that might be useful for this flow -->
<mulexml:dom-to-xml-transformer outputEncoding="UTF-8" name="DOM_to_XML" doc:name="DOM to XML"/>
<!-- Root flow that can trigger pull and push functionality -->
<flow name="PullAndPushInventoryFlow" doc:name="PullAndPushInventoryFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<logger message="Inside PullAndPushInventoryFlow - QueryParams : #[message.inboundProperties.'http.query.params']" level="INFO" doc:name="Logger"/>
<logger message="PullAndPushInventoryFlow - Invoking GetLocationList API" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="srwq12csb001.srwq12.com" port="8280" path="services/t/telecharge.com/GetLocationList/?eventId=4457573&rows=XN&seatFrom=20&seatTo=40&costMin=900&costMax=910" method="GET" doc:name="HTTP"/>
<logger message="PullAndPushInventoryFlow - Applying bundling logic to create SH listing requests on telecharge payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT" xsl-file="src/main/resources/xslt/listingrequest.xsl" />
<logger message="PullAndPushInventoryFlow - Listing requests payload after bunlding : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<logger message="PullAndPushInventoryFlow - Splitting listing requests..." level="INFO" doc:name="Logger"/>
<splitter enableCorrelation="ALWAYS" expression="#[xpath('//listings/listing')]" doc:name="ListingRequestSplitter"/>
<logger message="PullAndPushInventoryFlow - Number of listing requests found after bunlding : #[header:MULE_CORRELATION_GROUP_SIZE]" level="INFO" doc:name="Logger"/>
<request-reply storePrefix="listmsg" doc:name="Put message for processing">
<vm:outbound-endpoint path="dispatchIn">
<message-properties-transformer scope="outbound">
<delete-message-property key="MULE_REPLYTO" />
</message-properties-transformer>
</vm:outbound-endpoint>
<vm:inbound-endpoint path="dispatchOut" />
</request-reply>
<logger message="Aggregated Payload-> #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="ListingMessageProcessorFlow" doc:name="ListingMessageProcessorFlow">
<vm:inbound-endpoint path="dispatchIn"/>
<message-properties-transformer scope="invocation" doc:name="Remember correlation">
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_ID]" key="cid" />
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_GROUP_SIZE]" key="cgs" />
</message-properties-transformer>
<logger message="ListingMessageProcessorFlow - Splitted Message : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api-dev.srwd10.com" port="443" path="inventory/listings/v1/" method="POST" doc:name="HTTP" connector-ref="HTTP_HTTPS" transformer-refs="DOM_to_XML" contentType="application/xml" mimeType="application/xml">
<message-properties-transformer scope="outbound">
<add-message-property key="Authorization" value="Bearer 8da2ba50b471958168dfe0d4efd0f428" />
<add-message-property key="TARGET_HOST" value="srwq12" />
<add-message-property key="Acccept" value="application/xml" />
</message-properties-transformer>
</https:outbound-endpoint>
<message-properties-transformer scope="outbound">
<add-message-property value="#[header:INVOCATION:cid]" key="MULE_CORRELATION_ID" />
<add-message-property value="#[header:INVOCATION:cgs]" key="MULE_CORRELATION_GROUP_SIZE" />
</message-properties-transformer>
<vm:outbound-endpoint path="vm.aggregate" />
</flow>
<flow name="ListingMessageResponseAggregator">
<vm:inbound-endpoint path="vm.aggregate" />
<logger message="ListingMessageResponseAggregator - CorelationID : #[header:MULE_CORRELATION_ID], CorelationGroupSize : #[header:MULE_CORRELATION_GROUP_SIZE], Payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<collection-aggregator doc:name="Collection Aggregator" failOnTimeout="false"/>
<vm:outbound-endpoint path="dispatchOut" />
</flow>
</mule>
只是添加正在发生的事情的详细日志:
INFO 2014-06-12 16:00:15,617 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: Inside PullAndPushInventoryFlow - QueryParams : {}
INFO 2014-06-12 16:00:15,617 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PullAndPushInventoryFlow - Invoking GetLocationList API on telecharge
INFO 2014-06-12 16:00:16,213 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PullAndPushInventoryFlow - Applying bundling logic to create SH listing requests on telecharge payload : <result><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>20</seat_num><seat_increment>1</seat_increment><Cost>903</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>21</seat_num><seat_increment>1</seat_increment><Cost>904</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>22</seat_num><seat_increment>1</seat_increment><Cost>905</Cost></row><row><event_key>4457573</event_key><show_title>The Book of Mormon Houston</show_title><venue_name>Sarofim Hall at The Hobby Center in Houston, US</venue_name><perf_date>01/28/2015 12:00:00 AM</perf_date><area>CENTER ORCHESTRA</area><row_desc>XN</row_desc><seat_num>23</seat_num><seat_increment>1</seat_increment><Cost>905</Cost></row></result>
INFO 2014-06-12 16:00:16,221 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PullAndPushInventoryFlow - Listing requests payload after bunlding : <?xml version="1.0" encoding="UTF-8"?>
<listings>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>903</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>1</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>20</seats>
<splitOption>NONE</splitOption>
</listing>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>904</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>1</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>21</seats>
<splitOption>NONE</splitOption>
</listing>
<listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>905</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>2</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>22,23</seats>
<splitOption>NONE</splitOption>
</listing>
</listings>
INFO 2014-06-12 16:00:16,221 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PullAndPushInventoryFlow - Splitting listing requests...
INFO 2014-06-12 16:00:16,231 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PullAndPushInventoryFlow - Number of listing requests found after bunlding : 9
INFO 2014-06-12 16:00:16,232 [[telecharge].connector.http.mule.default.receiver.04] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.VM.mule.default.dispatcher.521391459'. Object is: VMMessageDispatcher
INFO 2014-06-12 16:00:16,232 [[telecharge].connector.http.mule.default.receiver.04] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.VM.mule.default.dispatcher.521391459'. Object is: VMMessageDispatcher
INFO 2014-06-12 16:00:16,236 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Splitted Message : <listing>
<eventId>4457573</eventId>
<eventDescription>The Book of Mormon Houston</eventDescription>
<pricePerTicket>
<amount>903</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>1</quantity>
<section>CENTER ORCHESTRA</section>
<rows>XN</rows>
<seats>20</seats>
<splitOption>NONE</splitOption>
</listing>
INFO 2014-06-12 16:00:16,238 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2014-06-12 16:00:16,238 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.http.transformers.MuleMessageToHttpResponse
INFO 2014-06-12 16:00:16,238 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2014-06-12 16:00:16,238 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'HTTP_HTTPS.dispatcher.1221616365'. Object is: HttpsClientMessageDispatcher
INFO 2014-06-12 16:00:16,238 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'HTTP_HTTPS.dispatcher.1221616365'. Object is: HttpsClientMessageDispatcher
WARN 2014-06-12 16:00:17,658 [[telecharge].ListingMessageProcessorFlow.stage1.02] org.apache.commons.httpclient.HttpMethodBase: Cookie rejected: "$Version=0; TLTSID=4FE5E730F28510F29E93A683F88FB10C; $Path=/; $Domain=.srwq12.com". Illegal domain attribute ".srwq12.com". Domain of origin: "api-dev.srwd10.com"
INFO 2014-06-12 16:00:17,660 [[telecharge].connector.VM.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.VM.mule.default.dispatcher.222031696'. Object is: VMMessageDispatcher
INFO 2014-06-12 16:00:17,660 [[telecharge].connector.VM.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.VM.mule.default.dispatcher.222031696'. Object is: VMMessageDispatcher
INFO 2014-06-12 16:00:17,664 [[telecharge].ListingMessageResponseAggregator.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ListingMessageResponseAggregator - CorelationID : 5168ed50-f285-11e3-b82a-28cfe91ad417, CorelationGroupSize : 9, Payload : {"listing":{"id":"1082795830","status":"ACTIVE"}}
答案 0 :(得分:0)
对于处理有效负载中大量元素的初始问题,可能不是一个正确的解决方案,但我找到了一种处理请求列表的同步方法。我仍然必须在最后转换响应,但至少聚合的有效负载正在好转:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd">
<!-- HTTPS Connection Configuration With CERTS -->
<https:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
<https:tls-server path="/Users/rkesara/opt/MULE/truststore/cacerts" storePassword="changeit" />
</https:connector>
<!-- List of transformers that might be useful for this flow -->
<mulexml:dom-to-xml-transformer outputEncoding="UTF-8" name="DOM_to_XML" doc:name="DOM to XML"/>
<!-- Root flow that can trigger pull and push functionality -->
<flow name="PullAndPushInventoryFlow" doc:name="PullAndPushInventoryFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<logger message="Inside PullAndPushInventoryFlow - QueryParams : #[message.inboundProperties.'http.query.params']" level="INFO" doc:name="Logger"/>
<logger message="PullAndPushInventoryFlow - Invoking GetLocationList API on telecharge" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="srwq12csb001.srwq12.com" port="8280" path="services/t/telecharge.com/GetLocationList/?eventId=4457573&rows=XO&seatFrom=1&seatTo=6&costMin=900&costMax=905" method="GET" doc:name="HTTP"/>
<logger message="PullAndPushInventoryFlow - Applying bundling logic to create SH listing requests on telecharge payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT" xsl-file="src/main/resources/xslt/listingrequest.xsl" />
<logger message="PullAndPushInventoryFlow - Listing requests payload after bunlding : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<logger message="PullAndPushInventoryFlow - Splitting listing requests..." level="INFO" doc:name="Logger"/>
<splitter enableCorrelation="ALWAYS" expression="#[xpath('//listings/listing')]" doc:name="ListingRequestSplitter"/>
<logger message="PullAndPushInventoryFlow - Number of listing requests found after bunlding : #[header:MULE_CORRELATION_GROUP_SIZE] - current request number : #[header:MULE_CORRELATION_SEQUENCE]" level="INFO" doc:name="Logger"/>
<flow-ref name="ListingMessageProcessorFlow" />
<collection-aggregator />
<logger message="Aggregated Payload-> #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="ListingMessageProcessorFlow" doc:name="ListingMessageProcessorFlow">
<message-properties-transformer scope="invocation" doc:name="Remember correlation">
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_ID]" key="cid" />
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_GROUP_SIZE]" key="cgs" />
</message-properties-transformer>
<logger message="ListingMessageProcessorFlow - Invoking listingAPI with request payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api-dev.srwd10.com" port="443" path="inventory/listings/v1/" method="POST" doc:name="HTTP" connector-ref="HTTP_HTTPS" transformer-refs="DOM_to_XML" contentType="application/xml" mimeType="application/xml">
<message-properties-transformer scope="outbound">
<add-message-property key="Authorization" value="Bearer 8da2ba50b471958168dfe0d4efd0f428" />
<add-message-property key="TARGET_HOST" value="srwq12" />
<add-message-property key="Acccept" value="application/xml" />
</message-properties-transformer>
</https:outbound-endpoint>
<logger message="ListingMessageProcessorFlow - Listing API response : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<message-properties-transformer scope="outbound">
<add-message-property value="#[header:INVOCATION:cid]" key="MULE_CORRELATION_ID" />
<add-message-property value="#[header:INVOCATION:cgs]" key="MULE_CORRELATION_GROUP_SIZE" />
</message-properties-transformer>
</flow>
</mule>
答案 1 :(得分:0)
我找到了处理问题的同步方式的答案..
完全赞同此博客:(http://geekyprimitives.wordpress.com/2012/08/11/fork-and-join-with-mule-3/)
以下是使用请求回复路由器的异步方式:
<flow name="SimpleFilePollingFlow" doc:name="Simple File Polling">
<file:inbound-endpoint path="/Users/rkesara/opt/MULE/File" responseTimeout="10000" doc:name="ListingRequestsXmlFile">
<file:filename-wildcard-filter pattern="*.xml"/>
</file:inbound-endpoint>
<logger message="SimpleFilePollingFlow - File read successfully and contents : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="xslt/listingrequest.xsl" doc:name="BundleListingsUsingXSLT"/>
<transformer ref="DOM_to_XML" />
<request-reply doc:name="Split and process listing messages asynchronously">
<vm:outbound-endpoint path="listingRequestQueue" doc:name="listingRequestQueue">
<message-properties-transformer scope="outbound">
<delete-message-property key="MULE_REPLYTO" />
</message-properties-transformer>
</vm:outbound-endpoint>
<vm:inbound-endpoint path="listingResponseQueue" doc:name="listingResponseQueue" />
</request-reply>
<json:json-to-object-transformer returnClass="java.util.List" doc:name="JSON Array to List" />
<logger message="SimpleFilePollingFlow -Aggregated JSON-> #[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="{"listings": #[payload]}" doc:name="Set Payload"/>
<logger message="SimpleFilePollingFlow - Aggregated JSON With Root Element -> #[payload]" level="INFO" doc:name="Logger"/>
<response>
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/>
</response>
</flow>
<flow name="ListingRequestQueueFlow" doc:name="Listing Request Queue Processor">
<vm:inbound-endpoint path="listingRequestQueue" doc:name="listingRequestQueue" />
<logger message="Inside ListingRequestQueueFlow - payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<splitter enableCorrelation="ALWAYS" expression="#[xpath('//listings/listing')]" doc:name="ListingRequestSplitter" />
<logger message="Inside ListingRequestQueueFlow - NumOfListingRequests : #[header:MULE_CORRELATION_GROUP_SIZE]" level="INFO" doc:name="Logger"/>
<flow-ref name="ListingRequestWorkerFlow" doc:name="Invoke Listing Request Worker Flow" />
</flow>
<flow name="ListingRequestWorkerFlow" doc:name="Listing Request Worker Flow" processingStrategy="allow500Threads">
<message-properties-transformer scope="invocation" doc:name="Remember correlation">
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_ID]" key="cid" />
<add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_GROUP_SIZE]" key="cgs" />
</message-properties-transformer>
<logger message="ListingRequestWorkerFlow - Invoking listingAPI with request payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api-dev.srwd10.com" port="443" path="inventory/listings/v1/" method="POST" doc:name="HTTP" connector-ref="HTTP_HTTPS" transformer-refs="DOM_to_XML" contentType="application/xml" mimeType="application/xml" responseTimeout="180000">
<message-properties-transformer scope="outbound">
<add-message-property key="Acccept" value="application/xml" />
</message-properties-transformer>
</https:outbound-endpoint>
<logger message="ListingRequestWorkerFlow - Listing API response for request number : #[header:MULE_CORRELATION_SEQUENCE], group size : #[header:INVOCATION:cgs], Payload: #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property value="#[header:INVOCATION:cid]" key="MULE_CORRELATION_ID" />
<add-message-property value="#[header:INVOCATION:cgs]" key="MULE_CORRELATION_GROUP_SIZE" />
</message-properties-transformer>
<vm:outbound-endpoint path="listingResponseAggregatorQueue" doc:name="ListingResponseAggregatorQueue" />
</flow>
<flow name="ListingResponseAggregatorFlow" doc:name="Listing Response Aggregator">
<vm:inbound-endpoint path="listingResponseAggregatorQueue" doc:name="Listing Response Aggregator Queue"/>
<logger message="ListingResponseAggregatorFlow - request number : #[header:MULE_CORRELATION_SEQUENCE], group size : #[header:MULE_CORRELATION_GROUP_SIZE] - payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<collection-aggregator failOnTimeout="false" />
<vm:outbound-endpoint path="listingResponseQueue" doc:name="Listing Response Queue" />
</flow>