Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

How to send response from rabbitmq consumer to producer in erlang with gen-server

I have a RabbitMq producer and consumer .I am sending a message from producer to consumer using erlang programming language with gen-server .How to send reply back to producer from consumer?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to implement Remote procedure call (RPC) pattern using rabbitmq queues. In order to receive a response, the client needs to send a 'callback' queue address with the request. Basic steps:

  1. In your client app create a queue to get a response and subscribe for it.
  2. Add additional properties to each rabbitmq message you want to get a response: reply_to - queue name to send a response (queue name from p. 1), correlation_id - id to distinguish your request (in erlang it can be a pid).
  3. Server app process message and publish a response to the queue from p.1 with the same correlation id.
  4. Client app queue listener gets a response and sends an erlang message to the pid from correlation_id.
  5. Your gen_server gets the response message.

Correlation id provides you the ability to create only one response queue. You can read it in details in documentation https://www.rabbitmq.com/tutorials/tutorial-six-elixir.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...