I have a Spring DSL route like:
<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>
And my main class which starts context like:
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();
And I have a processor to get my object form exchange like:
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());
}
}
I do set to Exchange in Camel the object from Map like:
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;
}
}
I can't understand why my Camel Processor doesnt work(doesn't trigger automaticaly). And I expected to get my Object which I setted in exchange camel with all field filled up.
Please help.
Message
into aCamelMessage
seems unnecessary....you should be able to just get the body as a String object if you're consuming from JMS. – mdnghtblue