【发布时间】:2014-06-27 10:15:10
【问题描述】:
我正在使用 MuleStudio 3.5.0 并尝试创建一个向 ActiveMQ 队列发送消息的流。该队列由一个旧的现有服务(用 .Net 编写)使用,我想将其集成到我的工作流程中。该服务期望消息的标头 Type 设置为“DoStuff”。我怎样才能做到这一点?
我尝试了以下流程。请注意,出于测试目的,我通过 DoStuff 类手动设置了 ActiveMQ 消息的负载,HTTP 连接器仅用于触发工作流:
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<spring:beans>
<spring:bean id="DoStuffBean" name="DoStuffBean" class="foo.DoStuff"/>
</spring:beans>
<flow name="Flow1" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8199" path="activemq" doc:name="HTTP"/>
<component doc:name="Java" class="com.kws.mule.DoStuff"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<jms:outbound-endpoint queue="MyServiceQueue" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer name="ObjectToJmsMessage" />
<message-properties-transformer>
<add-message-property key="Type" value="DoStuff" />
</message-properties-transformer>
</jms:outbound-endpoint>
</flow>
但这不起作用,因为没有设置标题 Type,而是设置了一个属性。这显示在 ActiveMQ 代理管理器控制台的图像中:
这里的参考是DoStuff 类:
public class DoStuff implements Callable {
private String jobId;
private String createdTime;
public String getJobId()
{
return this.jobId;
}
public String getResult()
{
return this.createdTime;
}
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
DoStuff result = new DoStuff();
result.jobId = "abd4df7b-0f31-41b4-826a-3dbbe77df7eb";
result.createdTime = "0001-01-01T00:00:00";
eventContext.getMessage().setPayload(result);
return eventContext.getMessage();
}
}
【问题讨论】: