ClickHouse/src/Storages/RabbitMQ/RabbitMQConnection.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.2 KiB
C++
Raw Normal View History

2021-09-10 10:28:09 +00:00
#pragma once
#include <Storages/UVLoop.h>
2021-09-10 10:28:09 +00:00
#include <Storages/RabbitMQ/RabbitMQHandler.h>
namespace DB
{
struct RabbitMQConfiguration
{
String host;
UInt16 port;
String username;
String password;
String vhost;
bool secure;
String connection_string;
};
class RabbitMQConnection
{
public:
RabbitMQConnection(const RabbitMQConfiguration & configuration_, Poco::Logger * log_);
bool isConnected();
bool connect();
bool reconnect();
void disconnect(bool immediately = false);
2021-09-11 17:38:55 +00:00
void heartbeat();
2021-09-10 10:28:09 +00:00
2021-09-11 17:38:55 +00:00
bool closed();
2021-09-10 10:28:09 +00:00
ChannelPtr createChannel();
/// RabbitMQHandler is thread safe. Any public methods can be called concurrently.
RabbitMQHandler & getHandler() { return event_handler; }
String connectionInfoForLog() const;
private:
2021-09-11 17:38:55 +00:00
bool isConnectedImpl() const;
void connectImpl();
void disconnectImpl(bool immediately = false);
2021-09-10 10:28:09 +00:00
RabbitMQConfiguration configuration;
Poco::Logger * log;
UVLoop loop;
RabbitMQHandler event_handler;
std::unique_ptr<AMQP::TcpConnection> connection;
std::mutex mutex;
};
using RabbitMQConnectionPtr = std::unique_ptr<RabbitMQConnection>;
}