在 Camel 中进行故障过滤 [英] Trouble filtering in Camel

查看:30
本文介绍了在 Camel 中进行故障过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的路线中过滤掉空体.路由每半秒左右从函数中轮询一次.因此,我每隔半秒就会在控制台中收到此错误.这是堆栈跟踪:

I am attempting to filter out the null bodies from my route. The route polls from the function every half second or so. So, I get this error in my console also every half-second. Here is the stack trace:

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                            Elapsed (ms)
[route1            ] [route1            ] [browserBean                                                                       ] [         0]
[route1            ] [filter1           ] [filter[simple{(${body} == null)}]                                             ] [         0]

Exchange
---------------------------------------------------------------------------------------   ------------------------------------------------
Exchange[
Id                  ID-CO183LTCS06-54352-1403798372606-0-1058
ExchangePattern     InOnly
Headers             {breadcrumbId=ID-CO183LTCS06-54352-1403798372606-0-1057,     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.GeneratedMethodAccessor22.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:48)
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)

有什么想法吗?我觉得这很简单,但我一直在网上寻找解决方案,但找不到任何可以解决我的问题的方法.

Any Ideas? I feel like it's simple but I've been looking all over the web for solutions and can't find anything that solves my problem.

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd

    http://camel.apache.org/schema/osgi
    http://camel.apache.org/schema/osgi/camel-osgi.xsd

    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd

    http://camel.apache.org/schema/spring
    http://camel.apache.org/schema/spring/camel-spring.xsd">

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
    <from uri="browserBean"/>
        <filter>
            <simple>${body} == null</simple>
            <stop/>
        </filter>
    <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>

空体来自以下函数:

package com.hello.integration;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
public class GreetingController {


    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        //Thread.sleep(3000); // simulated delay
        return new Greeting("Hello, " + message.getName() + "!");
    }

}

即使我尝试过滤掉空主体,我仍然收到错误消息.是不是我过滤掉它们太晚了?

Even though I attempt filter out the null bodies, I am still getting the error. Am I filtering them out too late?

推荐答案

不能将过滤器放在 from 标签内.以下路线应该有效:)

You cannot put the filter inside of from tag. The below route should work :)

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
    <from uri="browserBean"/>

        <filter>
            <simple>${body} == null</simple>
            <stop/>
        </filter>

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

这篇关于在 Camel 中进行故障过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆