ClickHouse/src/Storages/RabbitMQ/RabbitMQHandler.h

57 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
2020-06-02 13:15:53 +00:00
#include <thread>
#include <memory>
2020-06-02 13:15:53 +00:00
#include <mutex>
#include <amqpcpp.h>
#include <amqpcpp/linux_tcp.h>
#include <common/types.h>
#include <amqpcpp/libuv.h>
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(); }
};
class RabbitMQHandler : public AMQP::LibUvHandler
{
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
void onError(AMQP::TcpConnection * connection, const char * message) override;
void onReady(AMQP::TcpConnection * connection) override;
2020-06-29 15:41:17 +00:00
void startLoop();
2020-07-02 16:44:04 +00:00
void iterateLoop();
2020-08-28 08:52:02 +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(); }
private:
uv_loop_t * loop;
Poco::Logger * log;
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;
};
}