我有一个 mule 流,它使用 JMS 消息和一个 Java 组件来处理批处理。完成工作后,我需要发送电子邮件通知用户此过程的结果。我目前正在 Java 组件内处理所有这些,包括处理和电子邮件发送。我想分离电子邮件发送操作,以便在其他流程中重用此组件,而不是将代码从 Java 组件复制/粘贴/改编到其他组件。我的问题是我要发送到此组件的有效负载是 Map<String, Object>
而流程收到 Serializable
参数(在本例中为扩展 Serializable
的自定义类)。我如何在从 Java 组件发送之前更改有效载荷,我知道要在此 Map<String, Object>
中设置的参数在调用电子邮件组件之前?
目前这是我拥有的:
<flow name="SomeBatchProcessFlow">
<jms:inbound-endpoint queue="${some.batch.process}"
connector-ref="JmsConnectorRef" />
<component>
<method-entry-point-resolver>
<include-entry-point method="foo" />
</method-entry-point-resolver>
<spring-object bean="someBatchProcessComponent" />
</component>
<!--
what to put here to change the payload for the Map<String, Object> I've prepared
in SomeBatchProcessComponent#foo method?
-->
<jms:outbound-endpoint address="jms://${queues.emailSend}"
connector-ref="JmsConnectorRef" />
</flow>
<flow name="EmailSendFlow">
<jms:inbound-endpoint queue="${queues.emailSend}"
connector-ref="JmsConnectorRef" />
<component>
<method-entry-point-resolver>
<include-entry-point method="sendEmail" />
</method-entry-point-resolver>
<spring-object bean="emailSenderComponent" />
</component>
</flow>
我知道我可以从 SomeBatchProcessComponent#foo
手动发送 JMS 消息但我更希望 mule 处理这项工作以保持解耦。
最佳答案
要在 mule 流中设置有效载荷,请使用
<set-payload value="#[newPayload]"/>
其中 newPayload
是局部变量。
要更改 Java 组件中的负载,返回 Map<String, Object>
对象,它将被推送到 JMS
.
您也可以查看 vm queues
而不是使用 JMS 发送电子邮件,
关于java - 如何从 java 组件发送不同的有效载荷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19236394/