You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kevin Jackson <fo...@gmail.com> on 2010/02/01 13:37:50 UTC

filtering messages

Hi,

I have a use case where I want to drop certain messages where the body
is null (or conversely I want to process messages where the body is
not null)

I have the following config

public static class ContextConfig extends RouteBuilder {

        @Override
        public void configure() {
            from("direct:start").split(body(String.class).tokenize("\n"))
                    .bean(Unmarshaller.class).filter(
                    body().isNotNull())
                    .to("mock:result");

        }
    }

The Unmarshaller returns either a valid object or null, it is a POJO
and has no knowledge of Camel (and I want to keep it that way so I
don't want to change the code to inject a value into the header).

Reading the wiki and the posts in Nabble/MarkMail etc, I believe that
the filter() applied to the body is the correct approach, but in my
tests it seems as if the filter isn't being applied.

Kev

Re: filtering messages

Posted by Kevin Jackson <fo...@gmail.com>.
Hi,

>> I have a use case where I want to drop certain messages where the body
>> is null (or conversely I want to process messages where the body is
>> not null)
>>
>> I have the following config
>>
>> public static class ContextConfig extends RouteBuilder {
>>
>>        @Override
>>        public void configure() {
>>            from("direct:start").split(body(String.class).tokenize("\n"))
>>                    .bean(Unmarshaller.class).filter(
>>                    body().isNotNull())
>>                    .to("mock:result");
>>
>>        }
>>    }
>>
>> The Unmarshaller returns either a valid object or null, it is a POJO
>> and has no knowledge of Camel (and I want to keep it that way so I
>> don't want to change the code to inject a value into the header).
>>

> Always remember to write version number used.
Sorry 2.1 in this case

>
> I have looked into it and discovered a bug in the camel bean component.
> https://issues.apache.org/activemq/browse/CAMEL-2436
>
> Will be fixed in the next 2.2 release.
I managed to get a workaround working:

public static class ContextConfig extends RouteBuilder {
        @Override
        public void configure() {
            from("direct:start").split(body(String.class).tokenize("\n"))
                    .bean(Unmarshaller.class)
                    .filter(body().convertTo(Bean.class).isNotNull())
                    .to("mock:result");

        }
    }

Without the convertTo(), camel seemed to automatically generate a
non-null message

Thanks,
Kev

Re: filtering messages

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Feb 1, 2010 at 1:37 PM, Kevin Jackson <fo...@gmail.com> wrote:
> Hi,
>
> I have a use case where I want to drop certain messages where the body
> is null (or conversely I want to process messages where the body is
> not null)
>
> I have the following config
>
> public static class ContextConfig extends RouteBuilder {
>
>        @Override
>        public void configure() {
>            from("direct:start").split(body(String.class).tokenize("\n"))
>                    .bean(Unmarshaller.class).filter(
>                    body().isNotNull())
>                    .to("mock:result");
>
>        }
>    }
>
> The Unmarshaller returns either a valid object or null, it is a POJO
> and has no knowledge of Camel (and I want to keep it that way so I
> don't want to change the code to inject a value into the header).
>
> Reading the wiki and the posts in Nabble/MarkMail etc, I believe that
> the filter() applied to the body is the correct approach, but in my
> tests it seems as if the filter isn't being applied.
>
> Kev
>

Hi

Always remember to write version number used.

I have looked into it and discovered a bug in the camel bean component.
https://issues.apache.org/activemq/browse/CAMEL-2436

Will be fixed in the next 2.2 release.



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus