Using Kafka in a resquest / response script inside a REST web service

I am currently creating a REST web service that needs to communicate with Kafka in a request / response pattern. (I know Kafka is not really meant for this).

  • The client calls the REST web service.
  • REST web service publishes Kafka message
  • On the other hand, Kafka app sends a message and publishes a response to Kafka
  • (inside the same request as # 2) the REST web service listens on Kakfa and waits for a response that matches the request
  • REST web service returns response to client

Steps 1 through 3 seem pretty easy, but I'm scared from step 4.

My idea was to propagate the ID in every post so that I can get a response that matches the request.

However, I'm having a hard time figuring out how to set up a listener in a REST web service. How does the listener return a message to the controller?

+3


source to share


1 answer


I think it's best to create a topic for each user, then the user can send a message to another service, a message like this is like:

{
user:"myUserName"
data:"data of message"
}

      

then the service just needs to click on the topic "user.myUserName" Then from the web client just needs to subscribe to the "user.myUserName" (with the consumer group config, this is just to read only the newest messages) ...



I think the best way is to just implement the websocket and then push / read that way;)

Goodbye and have a nice day.

0


source







All Articles