mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
76 lines
1.5 KiB
C++
76 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <Storages/NATS/NATSHandler.h>
|
|
#include <Storages/UVLoop.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
struct NATSConfiguration
|
|
{
|
|
String url;
|
|
std::vector<String> servers;
|
|
|
|
String username;
|
|
String password;
|
|
String token;
|
|
|
|
int max_reconnect;
|
|
int reconnect_wait;
|
|
|
|
bool secure;
|
|
};
|
|
|
|
class NATSConnectionManager
|
|
{
|
|
public:
|
|
NATSConnectionManager(const NATSConfiguration & configuration_, Poco::Logger * log_);
|
|
~NATSConnectionManager();
|
|
|
|
bool isConnected();
|
|
|
|
bool connect();
|
|
|
|
bool reconnect();
|
|
|
|
void disconnect();
|
|
|
|
bool closed();
|
|
|
|
/// NATSHandler is thread safe. Any public methods can be called concurrently.
|
|
NATSHandler & getHandler() { return event_handler; }
|
|
natsConnection * getConnection() { return connection; }
|
|
|
|
String connectionInfoForLog() const;
|
|
|
|
private:
|
|
bool isConnectedImpl() const;
|
|
|
|
void connectImpl();
|
|
|
|
void disconnectImpl();
|
|
|
|
static void disconnectedCallback(natsConnection * nc, void * log);
|
|
static void reconnectedCallback(natsConnection * nc, void * log);
|
|
|
|
NATSConfiguration configuration;
|
|
Poco::Logger * log;
|
|
|
|
UVLoop loop;
|
|
NATSHandler event_handler;
|
|
|
|
|
|
natsConnection * connection;
|
|
// true if at any point successfully connected to NATS
|
|
bool has_connection = false;
|
|
|
|
// use CLICKHOUSE_NATS_TLS_SECURE=0 env var to skip TLS verification of server cert
|
|
bool skip_verification = false;
|
|
|
|
std::mutex mutex;
|
|
};
|
|
|
|
using NATSConnectionManagerPtr = std::shared_ptr<NATSConnectionManager>;
|
|
|
|
}
|