/**
* Invoke the callback and run all operations on the template argument in a dedicated
* thread-bound channel and reliably close the channel afterwards.
* @param action the call back.
* @param <T> the return type.
* @return the result from the
* {@link OperationsCallback#doInRabbit(RabbitOperations operations)}.
* @throws AmqpException if one occurs.
* @since 2.0
*/
@Nullable
default <T> T invoke(OperationsCallback<T> action) throws AmqpException {
在其impl中,您将在循环中调用operations.receive(),直到null:
/**
* Receive a message from a specific queue, waiting up to the specified wait time if
* necessary for a message to become available.
*
* @param queueName the queue to receive from
* @param timeoutMillis how long to wait before giving up. Zero value means the method
* will return {@code null} immediately if there is no message available. Negative
* value makes method wait for a message indefinitely.
* @return a message or null if the time expires
* @throws AmqpException if there is a problem
* @since 1.6
*/
@Nullable
Message receive(String queueName, long timeoutMillis) throws AmqpException;
从一个队列中提取消息。 然后道:
/**
* Send a message to a default exchange with a specific routing key.
*
* @param routingKey the routing key
* @param message a message to send
* @throws AmqpException if there is a problem
*/
void send(String routingKey, Message message) throws AmqpException;
1条答案
按热度按时间ulmd4ohb1#
请参阅
RabbitTemplate
API:在其impl中,您将在循环中调用
operations.receive()
,直到null
:从一个队列中提取消息。
然后道:
若要发布到另一个队列,请执行以下操作。
由于您在循环(receive-n-send)中按顺序执行所有操作,因此队列抽象定义保证了消息的顺序。