3
votes

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.

2
How are you inserting the message into your route? Also, extending the Message into a CamelMessage seems unnecessary....you should be able to just get the body as a String object if you're consuming from JMS.mdnghtblue

2 Answers

3
votes

I would add after your conetx.startRoute("folder-jms-route");

ProducerTemplate pt = conetx.createProducerTemplate();
pt.send("direct:start", ex);

-- Look at http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/DefaultProducerTemplate.html for more info

send(String endpointUri, Exchange exchange)
Sends the exchange to the given endpoint 

Notice: that if the processing of the exchange failed with an Exception it is not thrown from this method, but you can access it from the returned exchange using Exchange.getException().
0
votes

Consumer End point always expecting some Input data.
For Example You have declared JMS Consumer Endpoint whenever the JMS Queues receive the message then route get activated and its calls next processor which is defined next to consumer end point.
But In your case , you have declared direct consumer endpoint so some producer endpoint should send message to Direct endpoint.
So Here we are using ProducerTemplate in java DSL to send message to Direct endpoint.
In Spring DSL example :


<route id="parent">
<from uri="file:location"/>
<to uri="direct:start"/>
<route/ >

<route id="child">
<from uri="direct:start"/>
<to uri="bean:textProcessor"/>
<route/ >

Here we have parent and child route once parent route get the file form defined location it send it to the direct endpoint in the parent route.
child route consumer end point is direct so now message will come to child route.