2020-05-20 09:40:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-02 13:15:53 +00:00
|
|
|
#include <thread>
|
2020-05-20 09:40:49 +00:00
|
|
|
#include <memory>
|
2020-06-02 13:15:53 +00:00
|
|
|
#include <mutex>
|
2020-05-20 09:40:49 +00:00
|
|
|
#include <amqpcpp.h>
|
|
|
|
#include <amqpcpp/linux_tcp.h>
|
|
|
|
#include <common/types.h>
|
2020-06-24 21:14:49 +00:00
|
|
|
#include <amqpcpp/libuv.h>
|
2020-05-20 09:40:49 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-08-08 16:45:52 +00:00
|
|
|
namespace Loop
|
|
|
|
{
|
|
|
|
static const UInt8 RUN = 1;
|
|
|
|
static const UInt8 STOP = 2;
|
|
|
|
}
|
|
|
|
|
2021-05-01 18:00:43 +00:00
|
|
|
|
|
|
|
class RabbitMQChannel : public AMQP::TcpChannel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RabbitMQChannel(AMQP::TcpConnection * connection) : TcpChannel(connection) {}
|
|
|
|
~RabbitMQChannel() override { close(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-06-24 21:14:49 +00:00
|
|
|
class RabbitMQHandler : public AMQP::LibUvHandler
|
2020-05-20 09:40:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2020-06-30 01:48:11 +00:00
|
|
|
RabbitMQHandler(uv_loop_t * loop_, Poco::Logger * log_);
|
2020-08-28 08:52:02 +00:00
|
|
|
|
2020-05-20 09:40:49 +00:00
|
|
|
void onError(AMQP::TcpConnection * connection, const char * message) override;
|
2020-08-01 12:52:00 +00:00
|
|
|
void onReady(AMQP::TcpConnection * connection) override;
|
2020-06-29 15:41:17 +00:00
|
|
|
|
2020-06-27 17:26:00 +00:00
|
|
|
void startLoop();
|
2020-07-02 16:44:04 +00:00
|
|
|
void iterateLoop();
|
2020-08-28 08:52:02 +00:00
|
|
|
|
2020-08-01 12:52:00 +00:00
|
|
|
bool connectionRunning() { return connection_running.load(); }
|
2020-08-28 08:52:02 +00:00
|
|
|
bool loopRunning() { return loop_running.load(); }
|
|
|
|
|
2020-08-08 16:45:52 +00:00
|
|
|
void updateLoopState(UInt8 state) { loop_state.store(state); }
|
|
|
|
UInt8 getLoopState() { return loop_state.load(); }
|
2020-05-20 09:40:49 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-24 21:14:49 +00:00
|
|
|
uv_loop_t * loop;
|
2020-05-20 09:40:49 +00:00
|
|
|
Poco::Logger * log;
|
2020-05-29 16:04:44 +00:00
|
|
|
|
2020-08-28 08:52:02 +00:00
|
|
|
std::atomic<bool> connection_running, loop_running;
|
2020-08-08 16:45:52 +00:00
|
|
|
std::atomic<UInt8> loop_state;
|
2020-07-02 16:44:04 +00:00
|
|
|
std::mutex startup_mutex;
|
2020-05-20 09:40:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|