Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set consumer priority with AmqpTemplate

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading