spring integration dsl filter instead filter method annotation

杀马特。学长 韩版系。学妹 提交于 2020-02-03 11:41:43

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/28371718/spring-integration-dsl-filter-instead-filter-method-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!