1

I'm trying to design a system in an event-driven architecture style, trying also to expose REST API to send commands/queries. I decided to use Kafka as a message broker. The choreography I'm trying to design is the following: enter image description here

The part that is very obscure to me is how to implement event joins:

  1. billing-service should start creating the user only when it receives the user creation event (1) and the account has been created (2)
  2. api-gateway should return the result to the client only when both account and billing service have finished their processing (2 and 3)

I know I could use other protocols on the client side (e.g. WebSockets) but I prefer not doing that because I will need to expose such API to 3rd party. I could also do an async client call and poll to check if the request has been completed but it appears very complex to manage. What is the suggested way of implementing such an interaction?

p.s. I'm using Spring Boot and Spring Cloud Stream.

Alessandro Dionisi
  • 2,494
  • 4
  • 33
  • 37

1 Answers1

1

Request/reply messaging on the client side is possible with spring-cloud-stream, but it's a bit involved because it wasn't designed for that, it's intended for unidirectional stream processing.

You would be better off using spring-kafka (ReplyingKafkaTemplate) or spring-integration-kafka (Outbound Gateway) for request/reply on the client side.

On the service side you can use a @StreamListener (spring-cloud-stream) or a @KafkaListener or a spring-integration inbound-gateway.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Can you please detail a bit how to implement the problem of waiting for multiple events from multiple microservices (e.g. to create a user account I should create the authentication and billing entities, then return the result to the client)? – Alessandro Dionisi May 10 '19 at 14:52
  • Using the template, call `sendAndReceive()` - it returns a `Future` which you can `get()` the result from; then call another `sendAndReceive()` for the second operation and wait for its result. Refer to the documentation I pointed you to. – Gary Russell May 10 '19 at 15:12