changed
changed

Reputation: 2143

How to filter messages in apache camel

In my application build using apache camel (mavenized, spring dsl) , i am reading messages from a queue, about 3/5 of the messages need to be discarded based on some conditions in data in payload.

But i am new to apache camel and dont know how to call a bean's method and based on return value (boolean) , if true forward the message to next bean for processing.

JMS queue => Filter (Bean's method) => (true) =>Bean(process data)

Upvotes: 3

Views: 11283

Answers (1)

Ben ODay
Ben ODay

Reputation: 21005

see the message filter pattern

from("jms:queue:start")
    .filter().method(MyBean.class, "isGoldCustomer").to("bean:process");

public static class MyBean {
    public boolean isGoldCustomer(@Header("level") String level) { 
        return level.equals("gold"); 
    }
}

Upvotes: 3

Related Questions