Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring integration dsl filter instead filter method annotation

How can I switch from filter annotation method to Spring integration java DSL filter. how can I call filter method?

IntegrationFlows.from("removeSession")
                // remove chat session from user sessions map
                .handle("sessionLogService", "removeChatSession")
                // continue and remove user from ehcache only if user have no more opened sessions.
                .filter(/* what's going here? */)
                .get();

instead Filter annotation.

@Filter(inputChannel = "userGoOfflineFilter", outputChannel = "userGoOffline")
    public boolean notifyOnlyIfLastConnectionClosed(SecureUser secureUser) {
        ChatUser user = sessionUtils.getChatUser(secureUser.getId());
        if(user == null || user.getChatSessionIds() == null || user.getChatSessionIds().isEmpty())
            return true;
        LOGGER.debug(secureUser.getFirstName()+": Offline message not sent yet");
        return false;
    }
like image 957
lubo08 Avatar asked Dec 01 '25 08:12

lubo08


1 Answers

There are several overloaded .filter() methods on IntegrationFlowDefinition. Take a look at the javadocs, but

filter("expression");

takes a SpEL expression. It could be a bean reference, such as

.filter("@myFilter.notifyOnlyIfLastConnectionClosed('payload')")

or you can use a GenericSelector...

.filter(SecureUser.class, u -> u == null || u.getChatSessionIds() == null || u.getChatSessionIds().isEmpty())

(java 8 lambda) or

.filter(new GenericSelector<SecureUser>() {
                    @Override
                    public boolean accept(SecureUser u) {
                        return u == null || u.getChatSessionIds() == null || u.getChatSessionIds().isEmpty();
                    }
                })

(java 6/7).

etc.

like image 116
Gary Russell Avatar answered Dec 03 '25 23:12

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!