Camel中的无限循环 - Rabbit MQ

时间:2014-12-14 23:13:07

标签: apache-camel rabbitmq

我有一个小的服务器路由,它从queue.in接收消息并放入queue.out。

当我在 queue.in 中放入一条消息时,服务器以无限循环运行。我想知道我在配置方面缺少什么。这似乎是一条非常简单的路线。

小型服务器路由:

<camelContext id="camel-server" xmlns="http://camel.apache.org/schema/spring">

    <jmxAgent disabled="false" onlyRegisterProcessorWithCustomId="false"
        createConnector="true" usePlatformMBeanServer="true"
        registerNewRoutes="true" statisticsLevel="All" includeHostName="false"
        mask="false" id="agent" />

    <endpoint id="queue.in" uri="${queue.url.input_queue}" />
    <endpoint id="queue.out" uri="${queue.url.output_queue}" />
    <route id="rabbitRoute">

        <from uri="ref:queue.in" />
        <bean ref="multiplier" /><!-- a simple bean that appends "BeanHello" to input msg-->
        <to uri="ref:queue.out" />
    </route>
</camelContext>

兔子队列属性:

queue.url.input_queue=rabbitmq://localhost:5672/ex1?queue=input_queue&routingKey=input_queue&connectionFactory=#customConnectionFactory&autoDelete=false&autoAck=true
queue.url.output_queue=rabbitmq://localhost:5672/ex1?queue=output_queue&routingKey=output_queue&connectionFactory=#customConnectionFactory&autoDelete=false&autoAck=true

日志文件的片段 - 请参阅日志末尾的递归部分: 字符串“BeanHello”被多次添加,这意味着消息将一次又一次地进入queue.in而不是去queue.out。

2014-12-14 15:00:16,692 [main           ] DEBUG DefaultComponentResolver       - Found component: rabbitmq via type: org.apache.camel.component.rabbitmq.RabbitMQComponent via: META-INF/services/org/apache/camel/component/rabbitmq
2014-12-14 15:00:16,699 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=components,name="rabbitmq"
2014-12-14 15:00:16,711 [main           ] DEBUG DefaultComponent               - Creating endpoint uri=[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue], path=[localhost:5672/ex1]
2014-12-14 15:00:16,721 [main           ] DEBUG IntrospectionSupport           - Configured property: autoAck on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] with value: true
2014-12-14 15:00:16,725 [main           ] DEBUG IntrospectionSupport           - Configured property: autoDelete on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] with value: false
2014-12-14 15:00:16,726 [main           ] DEBUG IntrospectionSupport           - Configured property: queue on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] with value: input_queue
2014-12-14 15:00:16,727 [main           ] DEBUG IntrospectionSupport           - Configured property: routingKey on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] with value: input_queue
2014-12-14 15:00:16,728 [main           ] DEBUG RabbitMQComponent              - Creating RabbitMQEndpoint with host localhost:5672 and exchangeName: ex1
2014-12-14 15:00:16,729 [main           ] DEBUG SpringCamelContext             - rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue converted to endpoint: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] by component: org.apache.camel.component.rabbitmq.RabbitMQComponent@2be25129
2014-12-14 15:00:16,730 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=endpoints,name="rabbitmq://localhost:5672/ex1\?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue"
2014-12-14 15:00:16,730 [main           ] DEBUG DefaultManagementAgent         - MBean already registered with ObjectName: org.apache.camel:context=camel-server,type=endpoints,name="rabbitmq://localhost:5672/ex1\?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue"
2014-12-14 15:00:16,743 [main           ] DEBUG SpringCamelContext             - Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@1bd7643a to resolve component with name: bean
2014-12-14 15:00:16,743 [main           ] DEBUG DefaultComponentResolver       - Found component: bean in registry: null
2014-12-14 15:00:16,743 [main           ] DEBUG DefaultComponentResolver       - Found component: bean via type: org.apache.camel.component.bean.BeanComponent via: META-INF/services/org/apache/camel/component/bean
2014-12-14 15:00:16,748 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=components,name="bean"
2014-12-14 15:00:16,758 [main           ] DEBUG DefaultChannel                 - Initialize channel for target: 'Bean[ref:multiplier]'
2014-12-14 15:00:16,765 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=tracer,name=BacklogTracer
2014-12-14 15:00:16,774 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=tracer,name=BacklogDebugger
2014-12-14 15:00:16,788 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=errorhandlers,name="DefaultErrorHandlerBuilder(ref:CamelDefaultErrorHandlerBuilder)"
2014-12-14 15:00:16,789 [main           ] DEBUG DefaultComponent               - Creating endpoint uri=[ref://queue.out], path=[queue.out]
2014-12-14 15:00:16,789 [main           ] DEBUG SpringCamelContext             - ref://queue.out converted to endpoint: Endpoint[ref://queue.out] by component: org.apache.camel.component.ref.RefComponent@2182fb16
2014-12-14 15:00:16,790 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=endpoints,name="ref://queue.out"
2014-12-14 15:00:16,792 [main           ] DEBUG DefaultComponent               - Creating endpoint uri=[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue], path=[localhost:5672/ex1]
2014-12-14 15:00:16,794 [main           ] DEBUG IntrospectionSupport           - Configured property: autoAck on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] with value: true
2014-12-14 15:00:16,795 [main           ] DEBUG IntrospectionSupport           - Configured property: autoDelete on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] with value: false
2014-12-14 15:00:16,797 [main           ] DEBUG IntrospectionSupport           - Configured property: queue on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] with value: output_queue
2014-12-14 15:00:16,798 [main           ] DEBUG IntrospectionSupport           - Configured property: routingKey on bean: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] with value: output_queue
2014-12-14 15:00:16,798 [main           ] DEBUG RabbitMQComponent              - Creating RabbitMQEndpoint with host localhost:5672 and exchangeName: ex1
2014-12-14 15:00:16,800 [main           ] DEBUG SpringCamelContext             - rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue converted to endpoint: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] by component: org.apache.camel.component.rabbitmq.RabbitMQComponent@2be25129
2014-12-14 15:00:16,801 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=endpoints,name="rabbitmq://localhost:5672/ex1\?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue"
2014-12-14 15:00:16,801 [main           ] DEBUG DefaultManagementAgent         - MBean already registered with ObjectName: org.apache.camel:context=camel-server,type=endpoints,name="rabbitmq://localhost:5672/ex1\?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue"
2014-12-14 15:00:16,802 [main           ] DEBUG DefaultChannel                 - Initialize channel for target: 'To[ref:queue.out]'
2014-12-14 15:00:16,808 [main           ] INFO  SpringCamelContext             - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2014-12-14 15:00:16,808 [main           ] INFO  SpringCamelContext             - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2014-12-14 15:00:16,809 [main           ] DEBUG SpringCamelContext             - Warming up route id: rabbitRoute having autoStartup=true
2014-12-14 15:00:16,809 [main           ] DEBUG RouteService                   - Starting services on route: rabbitRoute
2014-12-14 15:00:16,811 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> Pipeline[[Channel[BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]], Channel[sendTo(Endpoint[ref://queue.out])]]]
2014-12-14 15:00:16,811 [main           ] DEBUG DefaultErrorHandler            - Redelivery enabled: false on error handler: DefaultErrorHandler[Instrumentation:bean[BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]]]
2014-12-14 15:00:16,818 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=producers,name=RabbitMQProducer(0x89c08d3)
2014-12-14 15:00:16,823 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=threadpools,name="RabbitMQProducer(0x89c08d3)"
2014-12-14 15:00:16,824 [main           ] DEBUG DefaultExecutorServiceManager  - Created new ThreadPool for source: Producer[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue] with name: CamelRabbitMQProducer[output_queue]. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@69e4d7d[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][CamelRabbitMQProducer[output_queue]]
2014-12-14 15:00:16,890 [main           ] DEBUG RabbitMQProducer               - Created connection: amqp://guest@127.0.0.1:5672/
2014-12-14 15:00:16,911 [main           ] DEBUG ProducerCache                  - Adding to producer cache with key: Endpoint[ref://queue.out] for producer: Producer[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=output_queue&routingKey=output_queue]
2014-12-14 15:00:16,912 [main           ] DEBUG DefaultErrorHandler            - Redelivery enabled: false on error handler: DefaultErrorHandler[Instrumentation:to[sendTo(Endpoint[ref://queue.out])]]
2014-12-14 15:00:16,912 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> Pipeline[[Channel[BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]], Channel[sendTo(Endpoint[ref://queue.out])]]]
2014-12-14 15:00:16,912 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]
2014-12-14 15:00:16,919 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=processors,name="bean1"
2014-12-14 15:00:16,920 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> Channel[BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]]
2014-12-14 15:00:16,920 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> sendTo(Endpoint[ref://queue.out])
2014-12-14 15:00:16,928 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=processors,name="to1"
2014-12-14 15:00:16,928 [main           ] DEBUG RouteService                   - Starting child service on route: rabbitRoute -> Channel[sendTo(Endpoint[ref://queue.out])]
2014-12-14 15:00:16,939 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=routes,name="rabbitRoute"
2014-12-14 15:00:16,939 [main           ] DEBUG TimerListenerManager           - Added TimerListener: org.apache.camel.management.mbean.ManagedSuspendableRoute@19f7f0f0
2014-12-14 15:00:16,940 [main           ] DEBUG SpringCamelContext             - Route: rabbitRoute >>> EventDrivenConsumerRoute[Endpoint[ref://queue.in] -> Pipeline[[Channel[BeanProcessor[org.apache.camel.example.server.Treble(0x64eb29e1)]], Channel[sendTo(Endpoint[ref://queue.out])]]]]
2014-12-14 15:00:16,940 [main           ] DEBUG SpringCamelContext             - Starting consumer (order: 1000) on route: rabbitRoute
2014-12-14 15:00:16,945 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=consumers,name=RabbitMQConsumer(0x753af01f)
2014-12-14 15:00:16,947 [main           ] DEBUG DefaultManagementAgent         - Registered MBean with ObjectName: org.apache.camel:context=camel-server,type=threadpools,name="RabbitMQEndpoint(0xad9be15)"
2014-12-14 15:00:16,947 [main           ] DEBUG DefaultExecutorServiceManager  - Created new ThreadPool for source: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue] with name: RabbitMQConsumer. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@5d4e5a43[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][RabbitMQConsumer]
2014-12-14 15:00:16,947 [main           ] DEBUG RabbitMQConsumer               - Using executor org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@5d4e5a43[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][RabbitMQConsumer]
2014-12-14 15:00:16,951 [main           ] DEBUG RabbitMQConsumer               - Created connection: amqp://guest@127.0.0.1:5672/
2014-12-14 15:00:16,952 [main           ] DEBUG RabbitMQConsumer               - Created channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1)
2014-12-14 15:00:16,957 [main           ] INFO  SpringCamelContext             - Route: rabbitRoute started and consuming from: Endpoint[rabbitmq://localhost:5672/ex1?autoAck=true&autoDelete=false&connectionFactory=%23customConnectionFactory&queue=input_queue&routingKey=input_queue]
2014-12-14 15:00:16,958 [main           ] DEBUG ultManagementLifecycleStrategy - Load performance statistics disabled
2014-12-14 15:00:16,958 [main           ] INFO  SpringCamelContext             - Total 1 routes, of which 1 is started.
2014-12-14 15:00:16,962 [main           ] INFO  SpringCamelContext             - Apache Camel 2.15-SNAPSHOT (CamelContext: camel-server) started in 0.889 seconds
2014-12-14 15:00:16,963 [main           ] DEBUG MainSupport                    - Starting Spring ApplicationContext: org.springframework.context.support.ClassPathXmlApplicationContext@3db853a5
2014-12-14 15:00:16,964 [main           ] DEBUG SpringCamelContext             - onApplicationEvent: org.springframework.context.event.ContextStartedEvent[source=org.springframework.context.support.ClassPathXmlApplicationContext@3db853a5: startup date [Sun Dec 14 15:00:14 PST 2014]; root of context hierarchy]
2014-12-14 15:01:01,671 [abbitMQConsumer] DEBUG MethodInfo                     - Setting bean invocation result on the IN message: @@@MsgFromClient#BeanHello 
2014-12-14 15:01:01,676 [abbitMQConsumer] DEBUG SendProcessor                  - >>>> Endpoint[ref://queue.out] Exchange[Message: @@@MsgFromClient#BeanHello ]
2014-12-14 15:01:01,683 [abbitMQConsumer] DEBUG MethodInfo                     - Setting bean invocation result on the IN message: @@@MsgFromClient#BeanHello #BeanHello 
2014-12-14 15:01:01,684 [abbitMQConsumer] DEBUG SendProcessor                  - >>>> Endpoint[ref://queue.out] Exchange[Message: @@@MsgFromClient#BeanHello #BeanHello ]
2014-12-14 15:01:01,687 [abbitMQConsumer] DEBUG MethodInfo                     - Setting bean invocation result on the IN message: @@@MsgFromClient#BeanHello #BeanHello #BeanHello 
2014-12-14 15:01:01,687 [abbitMQConsumer] DEBUG SendProcessor                  - >>>> Endpoint[ref://queue.out] Exchange[Message: @@@MsgFromClient#BeanHello #BeanHello #BeanHello ]
2014-12-14 15:01:01,698 [abbitMQConsumer] DEBUG MethodInfo                     - Setting bean invocation result on the IN message: @@@MsgFromClient#BeanHello #BeanHello #BeanHello #BeanHello 
2014-12-14 15:01:01,698 [abbitMQConsumer] DEBUG SendProcessor                  - >>>> Endpoint[ref://queue.out] Exchange[Message: @@@MsgFromClient#BeanHello #BeanHello #BeanHello #BeanHello ]

2 个答案:

答案 0 :(得分:3)

决议:

更改了uri添加的BridgedEndpoint = true。我不明白这背后的机制,以及为什么这样的特别是兔子的额外并发症。如果我使用jboss-fuse / camel我应该期待同样的问题?

queue.url.input_queue=rabbitmq://localhost:5672/ex1?queue=input_queue&routingKey=input_queue&connectionFactory=#customConnectionFactory&autoDelete=false&autoAck=true&BridgeEndpoint=true
queue.url.output_queue=rabbitmq://localhost:5672/ex1?queue=output_queue&routingKey=output_queue&connectionFactory=#customConnectionFactory&autoDelete=false&autoAck=true&BridgeEndpoint=true

答案 1 :(得分:0)

我遇到了同样的问题,它通过在输入和输出(http://camel.apache.org/constant.html)之间添加来修复:

.setHeader("rabbitmq.ROUTING_KEY", constant("output_queue"))

根据http://camel.apache.org/rabbitmq.html

  

将使用者队列绑定到交换机时使用的路由键。   对于生产者路由键,您可以设置标题(请参阅标题部分)