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