HowToTellAChild
HowToTellAChild

Reputation: 729

AMQP, RabbitMQ Push API how works?

I'm trying to get a deep understand how works the Push API communication between the client and the RabbitMQ server.

As I know - but correct me in case - the client open a TCP connenction to the broker (RabbitMQ) and keep this connenction alive until the client decision to close it. But during this connection the client can get messages immediately.

My question is, during this connection, do the client monitor the Broker to ask him for messages, or when the Broker forward a message to the Queue, where the client subscribed, just take that connencion and push the data to the client?

first case: client monitor the broker for messages

last case: client don't need to monitor the broker, broker just push the data

or other?

Upvotes: 2

Views: 2086

Answers (1)

Gary Russell
Gary Russell

Reputation: 174504

There are two options to receive messages

  1. The client registers a consumer callback (basicConsume) on the channel; the broker then "pushes" messages to the consumer.

  2. The client sends the broker a basicGet and receives one message (if present).

The first use case is the most common.

Since you tagged the question with I assume you are interested in Spring. For the first case, Spring AMQP has a listener container (and @RabbitListener annotation); for the second case, one of the RabbitTemplate receive operations can be used.

I suggest you look at the tutorials to get a basic understanding. They cover several languages including pure java and Spring AMQP.

You can also look at the Spring AMQP Reference Manual.

Upvotes: 2

Related Questions