我遇到了一个小问题..我跟随骡子流: -
<flow name="PostgresSQLFlow1" doc:name="PostgresSQLFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="db"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<flow-ref name="PostgresSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="PostgresSql Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
<processor-chain>
<flow-ref name="MSSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="MSSQL Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
</scatter-gather>
<set-payload value="....... Process Complete !!!! #[message.payload]" doc:name="Set Payload"/>
</flow>
<sub-flow name="PostgresSQLSub-Flow" doc:name="PostgresSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global2" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="Postgres Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>
<sub-flow name="MSSQLSub-Flow" doc:name="MSSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="MSSQL Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>
现在我从子流中获取JSON数据如下: -
MSSQL Data :- [{"AGE":5,"DESIGNATION":"Software Engineer","NAME":"Sidray","ID":288},{"AGE":55,"DESIGNATION":"Software Engineer"}]
Postgres Data :- [{"AGE":33,"DESIGNATION":"Software Engineer","NAME":"Anil","ID":2}]
现在我想将它合并到一个JSON消息中......
我尝试了以下操作: - 在每个子流程中,我使用<json:json-to-object-transformer returnClass="java.util.HashMap" />
然后使用I used <set-payload value="#[groovy:payload.inject([:]) {result, part -> result.putAll(part); result}]" />
我已将以下内容作为参考: - I merge two different payloads into one payload
但没有用..我得到以下例外: -
org.mule.routing.CompositeRoutingException: Exception was found for route(s): 0, 1. Message payload is of type: String
at org.mule.routing.CollectAllAggregationStrategy.aggregateWithFailedRoutes(CollectAllAggregationStrategy.java:51)
at org.mule.routing.CollectAllAggregationStrategy.aggregate(CollectAllAggregationStrategy.java:38)
at org.mule.routing.ScatterGatherRouter.processResponses(ScatterGatherRouter.java:197)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
请帮助我如何将这2个json数据合并为一个json ??
更新流量: -
<flow name="PostgresSQLFlow1" doc:name="PostgresSQLFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="db"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<flow-ref name="PostgresSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="PostgresSql Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
<processor-chain>
<flow-ref name="MSSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="MSSQL Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
</scatter-gather>
<set-payload value="#[groovy:payload.inject([:]) {result, part -> result.putAll(part); result}]" />
</flow>
<sub-flow name="PostgresSQLSub-Flow" doc:name="PostgresSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global2" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<json:json-to-object-transformer returnClass="java.util.HashMap" />
<logger message="Postgres Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>
<sub-flow name="MSSQLSub-Flow" doc:name="MSSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<json:json-to-object-transformer returnClass="java.util.HashMap" />
<logger message="MSSQL Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>
我得到的例外: -
INFO 2014-09-17 22:00:08,380 [[MultipleDBWithMSSQLAndPostgresSQL].ScatterGatherWorkManager.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Database_Global2.dispatcher.1519448919'. Object is: EEJdbcMessageDispatcher
INFO 2014-09-17 22:00:08,380 [[MultipleDBWithMSSQLAndPostgresSQL].ScatterGatherWorkManager.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Database_Global.dispatcher.1649935156'. Object is: EEJdbcMessageDispatcher
INFO 2014-09-17 22:00:08,381 [[MultipleDBWithMSSQLAndPostgresSQL].ScatterGatherWorkManager.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Database_Global.dispatcher.1649935156'. Object is: EEJdbcMessageDispatcher
INFO 2014-09-17 22:00:08,381 [[MultipleDBWithMSSQLAndPostgresSQL].ScatterGatherWorkManager.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Database_Global2.dispatcher.1519448919'. Object is: EEJdbcMessageDispatcher
ERROR 2014-09-17 22:00:08,586 [[MultipleDBWithMSSQLAndPostgresSQL].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Exception was found for route(s): 0, 1. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Exception was found for route(s): 0, 1. Message payload is of type: String (org.mule.routing.CompositeRoutingException)
org.mule.routing.CollectAllAggregationStrategy:51 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/routing/CompositeRoutingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.routing.CompositeRoutingException: Exception was found for route(s): 0, 1. Message payload is of type: String
at org.mule.routing.CollectAllAggregationStrategy.aggregateWithFailedRoutes(CollectAllAggregationStrategy.java:51)
at org.mule.routing.CollectAllAggregationStrategy.aggregate(CollectAllAggregationStrategy.java:38)
at org.mule.routing.ScatterGatherRouter.processResponses(ScatterGatherRouter.java:197)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
答案 0 :(得分:0)
JDBC端点生成映射列表,而不是JSON字符串,因此json-to-object-transformer不可能工作。只需删除它们,让scatter-gather为您提供JDBC端点的数据。
答案 1 :(得分:0)
因此,根据David的建议,最终的工作代码是: -
<flow name="PostgresSQLFlow1" doc:name="PostgresSQLFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="db"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<flow-ref name="PostgresSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="PostgresSql Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
<processor-chain>
<flow-ref name="MSSQLSub-Flow" doc:name="Flow Reference"/>
<logger message="MSSQL Done !!!" level="INFO" doc:name="Logger"/>
</processor-chain>
</scatter-gather>
<set-payload value="....... Process Complete !!!! #[message.payload]" doc:name="Set Payload"/>
</flow>
<sub-flow name="PostgresSQLSub-Flow" doc:name="PostgresSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global2" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<logger message="Postgres Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>
<sub-flow name="MSSQLSub-Flow" doc:name="MSSQLSub-Flow">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" connector-ref="Database_Global" queryKey="RetriveQuery" queryTimeout="-1" doc:name="Database (JDBC)"/>
<logger message="MSSQL Data :- #[message.payload]" level="INFO" doc:name="Logger"/>
</sub-flow>