mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 18:32:29 +00:00
48 lines
1018 B
C++
48 lines
1018 B
C++
#pragma once
|
|
|
|
#include <thread>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <amqpcpp.h>
|
|
#include <amqpcpp/linux_tcp.h>
|
|
#include <common/types.h>
|
|
#include <amqpcpp/libuv.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace Loop
|
|
{
|
|
static const UInt8 RUN = 1;
|
|
static const UInt8 STOP = 2;
|
|
}
|
|
|
|
class RabbitMQHandler : public AMQP::LibUvHandler
|
|
{
|
|
|
|
public:
|
|
RabbitMQHandler(uv_loop_t * loop_, Poco::Logger * log_);
|
|
|
|
void onError(AMQP::TcpConnection * connection, const char * message) override;
|
|
void onReady(AMQP::TcpConnection * connection) override;
|
|
|
|
void startLoop();
|
|
void iterateLoop();
|
|
|
|
bool connectionRunning() { return connection_running.load(); }
|
|
bool loopRunning() { return loop_running.load(); }
|
|
|
|
void updateLoopState(UInt8 state) { loop_state.store(state); }
|
|
UInt8 getLoopState() { return loop_state.load(); }
|
|
|
|
private:
|
|
uv_loop_t * loop;
|
|
Poco::Logger * log;
|
|
|
|
std::atomic<bool> connection_running, loop_running;
|
|
std::atomic<UInt8> loop_state;
|
|
std::mutex startup_mutex;
|
|
};
|
|
|
|
}
|