[英]Retry queue binding to RabbitMQ exchange
Using Spring-Boot with RabbitMQ I'm trying to create an exchange that can have n-number of queues, one for each of the microservices so each of them will get the same message.使用带有 RabbitMQ 的 Spring-Boot 我试图创建一个可以有 n 个队列的交换,每个微服务一个,这样每个微服务都会得到相同的消息。
Producer microservice has a Fanout Exchange defined.生产者微服务定义了一个扇出交换。 Each Consumer microservice creates a queue and attempts to connect it to the Producer exchange
每个消费者微服务创建一个队列并尝试将其连接到生产者交换
When Producer is started first, exchange is created.当 Producer 首先启动时,就创建了 Exchange。 Starting Consumer microservices bind to the Producer exchange.
启动消费者微服务绑定到生产者交换。 However in case when Consumer microservices are started first, they will not bind as there is nothing to bind to yet giving this log:
但是,如果消费者微服务首先启动,它们将不会绑定,因为还没有什么可绑定的,但会给出以下日志:
2020-01-13 22:24:49.640 INFO [,,,] 88649 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2020-01-13 22:24:49.685 INFO [,,,] 88649 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#7746ae18:0/SimpleConnection@428ea503 [delegate=amqp://guest@127.0.0.1:5672/, localPort= 62282]
2020-01-13 22:24:49.726 ERROR [,,,] 88649 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'abc-exchange' in vhost '/', class-id=50, method-id=20)
2020-01-13 22:24:50.748 ERROR [,,,] 88649 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'abc-exchange' in vhost '/', class-id=50, method-id=20)
2020-01-13 22:24:52.754 ERROR [,,,] 88649 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'abc-exchange' in vhost '/', class-id=50, method-id=20)
2020-01-13 22:24:56.763 ERROR [,,,] 88649 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'abc-exchange' in vhost '/', class-id=50, method-id=20)
2020-01-13 22:25:01.794 ERROR [,,,] 88649 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'abc-exchange' in vhost '/', class-id=50, method-id=20)
2020-01-13 22:25:01.807 INFO [,,,] 88649 --- [ main] o.s.a.r.l.SimpleMessageListenerContainer : Broker not available; cannot force queue declarations during start: java.io.IOException
2020-01-13 22:25:01.859 DEBUG [,,,] 88649 --- [ main] .b.c.i.c.AppConfig$CustomHttpTraceFilter : Filter 'httpTraceFilter' configured for use
How can I configure Consumer microservices(or Producer) to try to bind the queues to the Producer exchange even if they were started before the exchange existed.我如何配置消费者微服务(或生产者)以尝试将队列绑定到生产者交换,即使它们在交换存在之前启动。
Another approach would be Producer creating the queues dynamically based on the starting Consumer microservices information, which then will listen on given queue.另一种方法是生产者根据起始消费者微服务信息动态创建队列,然后将侦听给定队列。 However the issue would still be there, if queue is not created fast enough or Consumer is created before Producer then the listener will throw an exception
但是问题仍然存在,如果队列创建速度不够快或消费者在生产者之前创建,则侦听器将抛出异常
我们不能在您的消费者应用程序中指定一个绑定 bean 吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.