我有一个SpringBoot应用程序,我想连接到Rabbit MQ并阅读一些消息。但是我确实有一个问题,当我部署该应用程序时,有时它会立即连接到Rabbit并开始工作,但更多时候它只会尝试连接并尝试,最后我收到超时异常,就像这样:
2018-10-17 09:03:54.460 ERROR 15 --- [ main] o.s.a.r.l.SimpleMessageListenerContainer : Consumer failed to start in 60000 milliseconds; does the task executor have enough threads to support the container concurrency?
我使用AWS ECS,因此我的应用程序在docker容器中运行。可能相关吗?
这是我的配置,其中所有这些环境变量均有效
spring.rabbitmq.host=${RABBIT_HOST}
spring.rabbitmq.port=${RABBIT_PORT}
spring.rabbitmq.username=${RABBIT_USERNAME}
spring.rabbitmq.password=${RABBIT_PASSWORD}
spring.rabbitmq.virtualHost=${RABBIT_HOST}
rabbitmq.queues=myQueue
我的代码
@Component
@Slf4j
@RequiredArgsConstructor
final class ListingMessageListener {
private final BackOfficeService backOfficeService;
@RabbitListener(queues = "${rabbitmq.queues}")
public void receiveMessage(final ListingMessage listingMessage) {
final String listingId = listingMessage.getMessage().getListingId();
log.info("Received listingId= {}", listingId);
Optional.ofNullable(backOfficeService.getOfferById(Long.valueOf(listingId))).ifPresent(offer -> log.info(offer.getName()));
}
}