簡體   English   中英

駱駝:從直接路線到加工者的路線

[英]Camel: Route from direct to processor

我有一個Spring 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());
        }
}

我確實將Map中的對象設置為Camel中的Exchange:

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;
    }
}

我不明白為什么我的駱駝處理器無法正常工作(無法自動觸發)。 我希望得到我在交換駱駝中設置的對象,並填滿所有字段。

請幫忙。

我會在您的conetx.startRoute("folder-jms-route");

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

-有關更多信息,請訪問http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/DefaultProducerTemplate.html

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().

消費者端點始終期望一些輸入數據。
例如,只要JMS隊列接收到消息,然后激活路由,並且其調用在消費端點旁邊定義的下一個處理器,您就已經聲明了JMS消費端點。
但是在您的情況下,您已經聲明了直接使用者終結點,因此某些生產者終結點應該將消息發送到直接終結點。
因此,這里我們在Java DSL中使用ProducerTemplate將消息發送到Direct端點。
在Spring DSL示例中:


<route id =“ parent”>
<from uri =“ file:location” />
<to uri =“ direct:start” />
<路線/>

<route id =“ child”>
<from uri =“ direct:start” />
<to uri =“ bean:textProcessor” />
<路線/>

一旦父級路由獲得文件格式定義的位置,我們便在此處將父級和子級路由發送到父級路由的直接端點。
子路徑用戶端點是直接的,因此現在消息將到達子路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM