У меня есть приложение Spring Boot, использующее RabbitMQ. Я могу отправлять сообщения в очередь успешно. Я также могу получить сообщения. Однако когда я их получаю, сообщение не удаляется из очереди. Это приводит к тому, что мой получатель постоянно получает один и тот же список сообщений снова и снова.
Вопрос
Можно ли удалить сообщение после получения?
Код
Приемник
@ Компонент
public class RabbitMQReceiver {
@Autowired
private PhotoStatusProcessorService photoStatusProcessorService;
@RabbitListener(queues = "${rabbitmq.queuename}")
public void receive(UUID in) {
System.out.println("Received RabbitMQ msg = " + in);
photoStatusProcessorService.processPhotoForId(in);
}
}
Конфигурация
@Configuration
public class RabbitMQConfig {
@Value("${rabbitmq.queuename}")
String queueName;
// @Value("${rabbitmq.exchangename}")
// String exchange;
//
// @Value("${rabbitmq.routingkeyname}")
// String routingkey;
@Bean
Queue queue() {
return new Queue(queueName, false);
}
// @Bean
// DirectExchange exchange() {
// return new DirectExchange(exchange);
// }
//
// @Bean
// Binding binding(Queue queue, DirectExchange exchange) {
// return BindingBuilder.bind(queue).to(exchange).with(routingkey);
// }
@Profile("receiver")
@Bean
public RabbitMQReceiver receiver() {
return new RabbitMQReceiver();
}
}
application.properties
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=rabbitmq
spring.rabbitmq.password=****
rabbitmq.exchangename=photo-proccessor.exchange
rabbitmq.queuename=photo-proccessor
rabbitmq.routingkeyname=photo-proccessor.routingkey
YML-файл
rabbitmq:
container_name: rabbitmq
image: rabbitmq:3.7-management-alpine
ports:
- 15672:15672
- 5672:5672
environment:
RABBITMQ_ERLANG_COOKIE: "secretcookie"
RABBITMQ_DEFAULT_USER: ${AMQP_USERNAME}
RABBITMQ_DEFAULT_PASS: ${AMQP_PASSWORD}
выход
Received RabbitMQ msg = 9e24ec47-620b-4b93-833c-834a54d98ff8
Received RabbitMQ msg = 7e0e9aa6-f1d0-4154-abe1-617faa64a5fe
Received RabbitMQ msg = 3ade07c3-5f45-4aac-8054-0132bc85880b
Received RabbitMQ msg = 33645c35-a001-4c2c-a6f4-e3b96d3dc974
Received RabbitMQ msg = dcebdc77-6ddc-468e-978e-3714314a1abc
Received RabbitMQ msg = b7428adb-6356-4fd6-9ed1-c298886d95e8
Received RabbitMQ msg = 9e24ec47-620b-4b93-833c-834a54d98ff8
Received RabbitMQ msg = 7e0e9aa6-f1d0-4154-abe1-617faa64a5fe
Received RabbitMQ msg = 3ade07c3-5f45-4aac-8054-0132bc85880b
Received RabbitMQ msg = 33645c35-a001-4c2c-a6f4-e3b96d3dc974
Received RabbitMQ msg = dcebdc77-6ddc-468e-978e-3714314a1abc
Received RabbitMQ msg = b7428adb-6356-4fd6-9ed1-c298886d95e8
Received RabbitMQ msg = 9e24ec47-620b-4b93-833c-834a54d98ff8
Received RabbitMQ msg = 7e0e9aa6-f1d0-4154-abe1-617faa64a5fe
Received RabbitMQ msg = 3ade07c3-5f45-4aac-8054-0132bc85880b
Received RabbitMQ msg = 33645c35-a001-4c2c-a6f4-e3b96d3dc974
Received RabbitMQ msg = dcebdc77-6ddc-468e-978e-3714314a1abc
Received RabbitMQ msg = b7428adb-6356-4fd6-9ed1-c298886d95e8
Received RabbitMQ msg = 9e24ec47-620b-4b93-833c-834a54d98ff8
Received RabbitMQ msg = 7e0e9aa6-f1d0-4154-abe1-617faa64a5fe
Received RabbitMQ msg = 3ade07c3-5f45-4aac-8054-0132bc85880b
Received RabbitMQ msg = 33645c35-a001-4c2c-a6f4-e3b96d3dc974
Received RabbitMQ msg = dcebdc77-6ddc-468e-978e-3714314a1abc
..... forever