0
votes

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.

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. 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://[email protected]: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

1

1 Answers

0
votes

Can't we specify a binding bean in ur consumer app?