Reputation: 71
I want to receive multiple messages on one request from Spring AMQP RabbitTemplate (https://docs.spring.io/spring-amqp/api/org/springframework/amqp/rabbit/core/RabbitTemplate.html). But I can't find the method working this way. Can I do that in Spring AMQP?
I don't want to use RabbitListener because it consumes all the time..
Upvotes: 0
Views: 917
Reputation: 121177
No, there is no such an API on the RabbitTemplate
, as well as there is no way to send several message per single publish.
You may consider to use this one instead of receive()
:
/**
* Execute the callback with a channel and reliably close the channel afterwards.
* @param action the call back.
* @param <T> the return type.
* @return the result from the
* {@link ChannelCallback#doInRabbit(com.rabbitmq.client.Channel)}.
* @throws AmqpException if one occurs.
*/
@Nullable
<T> T execute(ChannelCallback<T> action) throws AmqpException;
So, you can call the Channel.basicGet()
in a loop on the same opened channel.
However there is also this more higher API:
/**
* 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 {
So, you can call RabbitOperations.receive()
in a loop.
Upvotes: 2