我正在使用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();
}
}
答案 0 :(得分:4)
此流程应该有效:
<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" />
<expression-transformer returnSourceIfNull="true"
doc:name="Expression"
expression="#[payload.setJMSType("DoStuff"); return payload]" />
</jms:outbound-endpoint>
</flow>
答案 1 :(得分:0)
MEL
中,你可以做到
<set-property propertyName="Type" value="Set your value here"/>
这将在Mule Message
上设置出站属性,JMS Queue
将作为入站属性