Created
May 3, 2016 21:02
-
-
Save mizanRahman/f91539b0c50796b29b210b83839a457e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Class Clientservice implements Service { | |
| public Object serviceMethod() { | |
| businessLogic.execute(); | |
| db.save(); | |
| externalApi1.call(); | |
| try { | |
| externalApi2.call(request); //with circuit breaker or make very first call async | |
| } catch (HttpClientErrorException ex) { | |
| eventStore.submit("dead_letter_queue", request, correlationId, request.Class); | |
| } | |
| catch (Exception ex) { | |
| eventStore.submit("event_name",request, correlationId, request.Class) | |
| } | |
| } | |
| } | |
| Class EventStoreImpl implements EventStore { | |
| public Object submit(String eventName, Request request, String correlationId, Class clazz ) { | |
| messageQueue.push(eventName, request, correlationId) | |
| } | |
| public void listen(String eventName, Callback<RequestClass> callback) { | |
| //eventName is the name of queue in message broker | |
| messageQueue.listen(eventName, new DefaultConsumer() { | |
| public void HandleDelivery(byte[] body) { | |
| callback.call(body); | |
| } | |
| }); | |
| } | |
| } | |
| Class TargetService implements Service { | |
| public Object serviceMethod() { | |
| businessLogic.apply(); | |
| } | |
| } | |
| Class TargetServiceIntegration{ | |
| @Autowire | |
| Service TargetService; | |
| public Object serviceMethodInt() { | |
| eventStore.listen("TargetServiceIntegration.serviceMethodInt", new Callback() { | |
| public void call(byte[] body) { | |
| System.out.println(body); | |
| } | |
| }) | |
| targetService.serviceMethod(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment