I’m using the spring-boot-starter-amqp library to:
- Wait indefinitely until a message can be received.
- Process the message, which may take several minutes.
- Terminate the program
I also would like to the set the consumer priority. However, I don’t know how to set the x-priority consumer argument, as the documentation only mentions how to do this with an asynchronous consumer, not with AmqpTemplate or RabbitTemplate. Any help would be appreciated.
ApplicationRunner class:
private final AmqpTemplate template;
private final ApplicationContext applicationContext;
...
@Override
public void run(ApplicationArguments args) {
Message message = template.receive("analyses", -1);
if (message == null) throw new IllegalStateException("No message received");
byte[] body = message.getBody();
// todo: process the message
System.out.printf("[x] Received '%s'%n", new String(body, StandardCharsets.UTF_8));
context.close();
}
In a configuration class:
@Bean
public RabbitTemplate amqpTemplate(final ConnectionFactory connectionFactory) {
return new RabbitTemplate(connectionFactory);
}
>Solution :
It is not currently supported; the consumer is created in a private method createConsumer() which doesn’t pass any arguments to basicConsume().
Please open a new feature issue on GitHub; it won’t be difficult to implement and we have releases planned for next week.
https://github.com/spring-projects/spring-amqp/issues