TL;DR - Whats the best way to expose RabbitMQ to a consumer via REST API?
I'm creating an API to publish and consume message from RabbitMQ. In my current design, the publisher is going to make a POST request. My API will route the POST request to the exchange. In this way, the publisher doesn't have to know the server address, exchange name etc. while publishing.
Now the consumer part is where I'm not sure how to proceed.
At the beginning there will be no queues. When a new consumer wants to subscribe to a TOPIC, then I will create a queue and bind it to the exchange. I need help with answers to few questions -
- Once I create a queue for the consumer, what's the next step to let the consumer get messages from that queue?
- I make the consumer ask for a batch of messages(say 50 messages) from the queue. Then once I receive an ack from the consumer I will send the next 50 messages from queue. If I don't receive an ack I will requeue the 50 messages back into the queue. Isn't this expensive in terms of opening and closing connection between the consumer and my API?
If there is a better approach then please suggest
basic.consume
method, in client libraries regardless language it should be called in a similar way. 2) You basically not sending any messages from queue to consumer, it's broker (RabbitMQ) responsibility. You send messages to exchanges, bind queues to exchanges and consume from queues. But you can interact between consumer and sender if it fits your needs. Real costs should be measured. – pinepain