C
C
cascado2016-12-21 18:53:57
go
cascado, 2016-12-21 18:53:57

How to Go way to implement reconnection to RabbitMQ?

Good afternoon. The github.com/streadway/amqp example was taken as a basis , a fragmentary code was found for implementing reconnection to the RabbitMQ node https://gist.github.com/svcavallar/be2d40953eaf278... in case the connection is closed. I tried several options, apparently I fundamentally misunderstand how it should work. As far as I understand, when recreating the amqp.Connect object, it is also necessary to recreate the channel, queue and messages objects. Please show (or correct a piece of code) how such functionality should look like, I attach the code https://gist.github.com/cascad-s/7fca5c68639114eb9... . Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kravchik, 2016-12-22
@cascado

I didn’t read it in detail, but before each one: the rabbitCloseError
channel for notifications about closing the connection needs to be recreated via make . Proof: https://github.com/streadway/amqp/issues/160 svcavallar does just that:

rabbitConn = connectToRabbitMQ(uri)
rabbitCloseError = make(chan *amqp.Error)  // <---- look here
rabbitConn.NotifyClose(rabbitCloseError)

If you have questions, write comments to the answer.
PS Also, I would recommend not to block the program with an "endless" channel, but at least use OS signals (even under Windows) .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question