【问题标题】:dynamic routing with camel don't forward messages骆驼动态路由不转发消息
【发布时间】:2017-10-10 08:19:11
【问题描述】:

我正在开发基于 web 服务和 jms 队列的 Camel 动态路由管理器。我有以下架构:

endpoint:cxf -> jms:queue -> dynamic routing to a jms:queue -> processing

这是我的路线定义:

@Override
public void configure() throws Exception {
    routeDefinition = from(fromEndpoint).routeId(name)
            .dynamicRouter(method(DynamicRoutingManager.class, "getRoute")).process(exchange -> {
                final List<?> soaList = exchange.getIn().getBody(List.class);
                final String type = (String) soaList.get(0);
                final String documentNumber = (String) soaList.get(1);
                final String productionStepNumber = (String) soaList.get(2);
                final String message = (String) soaList.get(3);

                final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type
                        + ", document number=" + documentNumber + ", production step number" + productionStepNumber
                        + ", message=" + message;
                LOG.debug("==> message={}", messageToSend);
                exchange.getOut().setBody(messageToSend);
            }); // .to(DLQ);
}

这里是我的动态路由管理器(我保持简单):

public String getRoute(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    LOG.debug("========> BODY={}", body);
    return "jms:topic:urgent_doc1_prod1";
}

路由jms:topic:urgent_doc1_prod1在运行时定义并运行(在日志中查看)

事实上,当我发送这样的请求时(见下文),我收到超时错误...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://cxf.apache.org/wsse/handler/helloworld">
   <soapenv:Header/>
   <soapenv:Body>
      <hel:message>
         <!--Optional:-->
         <type>urgent</type>
         <!--Optional:-->
         <document_number>1</document_number>
         <!--Optional:-->
         <production_step_number>1</production_step_number>
         <!--Optional:-->
         <message>un message</message>
      </hel:message>
   </soapenv:Body>
</soapenv:Envelope>

因为我认为我的消息没有转发到第二个 jms:queue,所以可以进行任何处理...

我做错了什么?

【问题讨论】:

    标签: java apache-camel dynamic-routing


    【解决方案1】:

    如果您想将消息路由到单个动态目的地,请使用 recipientListtoD - 请参阅此常见问题解答:http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

    动态路由器就像一个while loop,它会一直路由直到你告诉它在空/空目的地停止。请参阅顶部的文档:http://camel.apache.org/dynamic-router.html。而且您的示例不会将其作为硬编码的目标值。

    【讨论】:

    • 感谢您的回答,但它不起作用。消息在jms:topic:urgent_doc1_prod1 中排队,但从未出队并以DLQ 结束..
    • 我不明白你的问题。您是否正在通过 JMS 进行某种请求/回复,并希望 Camel 在继续之前等待回复消息。
    • 我在运行时使用用户界面创建动态路由,动态部分用于通过这些动态路由转发消息(根据请求中定义的选项)。最后,目前,我只想发送一条经过处理的消息(带有初始请求的内容)
    • 问题是jms:topic:urgent_doc1_prod1没有消费者。但我定义了一个处理器..
    • 然后使用 InOnly 发送消息(例如一种方式/触发和忘记模式)而不是潜在的 InOut(请求/回复)请参阅camel.apache.org/event-message.html
    【解决方案2】:

    实际上,这是我的一个误解。我没有在动态路由之后单独声明“from”路由,所以没有消费者,所以超时。

    @Override
    public void configure() throws Exception {
        from(fromEndpoint).routeId(name + "a").recipientList(method(DynamicRoutingManager.class, "getRoute"));
    
        from(toEndpoint).routeId(name + "b").process(exchange -> {
    
            final List<?> soaList = exchange.getIn().getBody(List.class);
            final String type = (String) soaList.get(0);
            final Integer documentNumber = (Integer) soaList.get(1);
            final Integer productionStepNumber = (Integer) soaList.get(2);
            final String message = (String) soaList.get(3);
    
            final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type
                    + ", document number=" + documentNumber + ", production step number" + productionStepNumber
                    + ", message=" + message;
    
            LOG.debug("==> message={}", messageToSend);
            exchange.getOut().setBody(messageToSend);
        });
    }
    

    让它工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-06
      • 2015-09-27
      • 2011-11-23
      • 2018-02-17
      • 1970-01-01
      • 2018-09-02
      • 2013-01-24
      相关资源
      最近更新 更多