我有一个Web服务,它从另一个系统接收xml事件,使用特定的工作流程处理它们,并将一个潜在错误列表作为HTTP响应发回.
事件处理工作流由几个处理程序组成(比方说:Preprocessor,Persister和Validator),使用Guava的EventBus实现.处理程序相互发送事件.像这样的东西:
public class RequestHandler {
@RequestMapping
public Errors handleRequest(String xmlData) {
eventBus.post(new XmlReceivedEvent(xmlData));
...
return errors; // how to get errors object from the last handler in chain ?
}
}
public class Preprocessor {
@Subscribe
public void onXmlReceived(XmlReceivedEvent event) {
// do some pre-processing
...
eventBus.post(new PreprocessingCompleteEvent(preprocessingResult));
}
}
public class Persister {
@Subscribe
public void onPreprocessingComplete(PreprocessingCompleteEvent event) {
// do some persistence stuff
...
eventBus.post(new PersistenceCompleteEvent(persistenceResult));
}
}
public …Run Code Online (Sandbox Code Playgroud)