使用camel从webapp路由

时间:2014-06-25 22:32:05

标签: spring apache-camel activemq messaging

我正在尝试使用camel将消息从我的Web应用程序路由到队列,并且我使用bean引用从每当向浏览器提供输入时运行的函数中获取消息。但是,当camel继续轮询时会创建一个Null异常,因为每半秒都不会有输入。我怎样才能使骆驼只在有人拿起时才收到信息? Browserbean是从浏览器返回消息的函数。

这是我的骆驼路线:

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
    <from uri="browserBean"/>
    <to uri="jms:queue:testQSource"/>
    <to uri="myBean"/>
    <log message="Routing message from testQSource to testQDestination queue with data ${body}"/>
    <to uri="jms:queue:testQDestination"/>
    <to uri="finalBean"/>
    <log message="message: ${body}"/>
</route>
</camelContext>

<camel:camelContext id="camel-client">
    <camel:template id="camelTemplate" />
</camel:camelContext>

    <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>
    <bean id="myBean" class="com.example.integration.modifier"/>
    <bean id="finalBean" class="com.example.integration.ActionApp"/>
    <bean id="browserBean" class="com.hello.integration.GreetingController"/>

</beans>

这是我每隔一秒左右得到的堆栈跟踪:

Message History
---------------------------------------------------------------------------------------         ------------------------------------------------
RouteId              ProcessorId          Processor                                                                            Elapsed (ms)
[route1            ] [route1            ] [browserBean                                                                      ] [         0]
[route1            ] [to1               ] [jms:queue:testQSource                                                         ] [         0]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id                  ID-CO183LTCS06-59664-1403735006145-0-16
ExchangePattern     InOnly
Headers             {breadcrumbId=ID-CO183LTCS06-59664-1403735006145-0-15,          CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType            null
Body                [Body is null]
]

Stacktrace
---------------------------------------------------------------------------------------    ------------------------------------------------

java.lang.NullPointerException: null
at com.hello.integration.GreetingController.greeting(GreetingController.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:407)
at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:278)
at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:251)
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:166)
at     org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:67)
at    org.apache.camel.impl.ProcessorPollingConsumer.receive(ProcessorPollingConsumer.java:58)
at    org.apache.camel.impl.ProcessorPollingConsumer.receiveNoWait(ProcessorPollingConsumer.java:    66)
at     org.apache.camel.impl.DefaultScheduledPollConsumer.poll(DefaultScheduledPollConsumer.java:4    8)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at     java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown      Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown     Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案