6#include <spdlog/spdlog.h>
7#include <zmq_addon.hpp>
14void ZeroMQ::init(
const std::shared_ptr<zmq::context_t> &ctx,
const zmq::socket_type &type,
15 const std::string_view &addr,
bool isBind)
32ZeroMQ::ZeroMQ(
const zmq::socket_type &type,
const std::string &addr,
bool isBind)
34 init(std::make_shared<zmq::context_t>(1), type, addr, isBind);
37ZeroMQ::ZeroMQ(
const std::shared_ptr<zmq::context_t> &ctx,
const zmq::socket_type &type,
const std::string &addr,
40 init(ctx, type, addr, isBind);
83 std::vector<zmq::message_t> recvMsgs;
86 spdlog::warn(
"Connection needs to starting");
90 auto nMsgs = zmq::recv_multipart(*
_socketPtr, std::back_inserter(recvMsgs));
91 spdlog::debug(
"Received {} messages", nMsgs.value_or(0));
98 zmq::send_result_t res;
101 spdlog::warn(
"Connection needs to starting");
108 return res.value_or(0);
117 catch (
const std::exception &e)
121 spdlog::error(
"Error while stopping ZeroMQ connection {} ({})",
_socketAddr, e.what());
123 catch (
const std::exception &e2)
125 std::cerr <<
"Error while stopping ZeroMQ connection and logger for connection " <<
_socketAddr <<
" ("
126 << e.what() <<
")" <<
'\n'
127 << e2.what() <<
'\n';
constexpr int ZEROMQ_HEARTBEAT_TIMEOUT_MS
constexpr int ZEROMQ_MSG_TIMEOUT_MS
std::vector< zmq::message_t > recvMessages()
void init(const std::shared_ptr< zmq::context_t > &ctx, const zmq::socket_type &type, const std::string_view &addr, bool isBind)
size_t sendMessages(std::vector< zmq::message_t > &msg)
std::unique_ptr< zmq::socket_t > _socketPtr
std::shared_ptr< zmq::context_t > _contextPtr
ZeroMQ(const zmq::socket_type &type, const std::string &addr, bool isBind)