SimplyStaking / panic

PANIC Monitoring and Alerting For Blockchains
Apache License 2.0
81 stars 31 forks source link

Refactor alerter to use 1 rabbitMQ connection per thread #139

Open Cherrett opened 2 years ago

Cherrett commented 2 years ago

When tackling #136, it was noted that we are sharing rabbitMQ connections between threads. This is not correct and each thread should have its own connection.

Cherrett commented 2 years ago

Comment left by @dillu24 on 136 MR:

Also as per pika docs, it is recommended that we use 1 connection per thread, where the connection is created inside that thread. I don't think we are doing that.

I think we should use separate initialisation functions for each thread, and we use the appropriate rabbit initialization function according to which thread we are in.

For example we should have a general initialise_rabbit function which initialises the queues and exchanges and then disconnects from rabbit in the mainthread. Then we should have an initialize_rabbit_heartbeat which initialises a rabbit connection for the ping thread and initialize_rabbit_sending_configs which initialises a connection for the sending_configs thread. When on the outside we terminate the threads we disconnect as normal. Due to this we must then have 2 variables, is_connected_rabbit_heartbeat and is_connected_rabbit_send_configs.