如何从过滤器注释方法切换到Spring集成java DSL过滤器。我怎样才能调用过滤方法?
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();
代替过滤注释。
@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;
}
答案 0 :(得分:3)
.filter()
上有几个重载的IntegrationFlowDefinition
方法。看看javadocs,但是
filter("expression");
采用SpEL表达式。它可以是bean引用,例如
.filter("@myFilter.notifyOnlyIfLastConnectionClosed('payload')")
或者您可以使用GenericSelector
...
.filter(SecureUser.class, u -> u == null || u.getChatSessionIds() == null || u.getChatSessionIds().isEmpty())
(java 8 lambda)或
.filter(new GenericSelector<SecureUser>() {
@Override
public boolean accept(SecureUser u) {
return u == null || u.getChatSessionIds() == null || u.getChatSessionIds().isEmpty();
}
})
(java 6/7)。
等