我有一個像春天DSL線路:駱駝:路線直接到處理器
<bean id="sendMsgProc" class="com.tc.infrastructure.utils.jms.SendMessageProcessor"/>
<camel:camelContext id="folder-jms" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
<camel:propertyPlaceholder id="jmsProps" location="classpath:jms-jndi.properties"/>
<route id="folder-jms-route" autoStartup="true">
<!-- <from uri="{{jms.output.folder}}"/> -->
<from uri="direct:start"/>
<!-- <to uri="bean:camelMsgBean"/> -->
<camel:process ref="sendMsgProc"/>
<to uri="{{jms.in.send}}"/>
</route>
</camel:camelContext>
我的主類,它開始像背景:
SpringCamelContext conetx = (SpringCamelContext)camel.initContextCamel("camel-context.xml", "folder-jms");
Exchange ex = new DefaultExchange(conetx);
ex.getIn().setBody(executionTasks.entrySet().iterator().next().getValue(), CamelMessage.class);
conetx.start();
conetx.startRoute("folder-jms-route");
Thread.sleep(10000);
conetx.stopRoute("folder-jms-route");
conetx.stop();
而且我有一個處理器,讓我的對象形式交換,如:
public class SendMessageProcessor implements Processor {
//This processor exist for set headers into sending message
public void process(Exchange exchange) throws Exception
{
System.out.println("adasdasd");
CamelMessage message = (CamelMessage)exchange.getIn().getBody(CamelMessage.class);
System.out.println("Message with correlationId get for exchange " + message.getMsgCorrelationId());
System.out.println("Body" + message.getBody());
}
}
我設置爲交易所駱駝對象從地圖,如:
public class CamelMessage extends Message {
private Map<String, Object> headersMap;
private StringBuffer body;
private String msgCorrelationId;
public CamelMessage(File msgPath, String msgCorrelationId)
{
super.setMsgPath(msgPath);
this.msgCorrelationId = msgCorrelationId;
}
public CamelMessage(String correlationID, Map<String, Object> headers, String body)
{
setMsgCorrelationId(correlationID);
setHeadersMap(headers);
setBody(body);
}
public Map<String, Object> getHeadersMap() {
return headersMap;
}
protected void setHeadersMap(Map<String, Object> headersMap) {
if(headersMap == null)
headersMap = new HashMap<String, Object>();
this.headersMap = headersMap;
}
public String getBody() {
return body.toString();
}
protected void setBody(String body) {
if(this.body == null)
this.body = new StringBuffer();
this.body.append(body);
}
public String getMsgCorrelationId() {
return msgCorrelationId;
}
private void setMsgCorrelationId(String msgCorrelationId) {
this.msgCorrelationId = msgCorrelationId;
}
}
我不明白爲什麼我的駱駝處理器不起作用(不觸發automaticaly)。我希望得到我的對象,我用所有的領域填補交換駱駝交換。
請幫忙。
你是如何將信息插入你的路線?此外,將'Message'擴展爲'CamelMessage'看起來沒有必要......如果您使用JMS進行消費,您應該可以將主體作爲String對象進行獲取。 – mdnghtblue 2014-12-02 14:26:57