conduit 0.6.0
Modern C++23 header-only event-dispatching / event-transport library
Loading...
Searching...
No Matches
transport.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <conduit/bus.hpp>
11#include <conduit/transport.hpp>
12
13#include <chrono>
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <string>
18
19namespace conduit::zmq {
20
23public:
24 using conduit::TransportError::TransportError;
25};
26
28enum class Format : std::uint8_t { Json, Cbor };
29
32enum class Pattern : std::uint8_t {
34 PubSub,
39};
40
45enum class Role : std::uint8_t { Bind, Connect };
46
50 std::string server_key;
52 std::string public_key;
54 std::string secret_key;
56 bool is_server = false;
57};
58
59// NOLINTBEGIN(clang-analyzer-optin.performance.Padding)
60// Layout is grouped by pattern (PubSub / PushPull / RouterDealer) for human
61// readability; this Config is instantiated rarely (once per transport at
62// startup), so the wasted padding is not worth scrambling the field order for.
63struct Config {
65
66 // PubSub — pub_endpoint is required when pattern == PubSub.
67 std::string pub_endpoint;
69 std::string sub_endpoint;
73
74 // PushPull — both endpoints required when pattern == PushPull.
75 std::string push_endpoint;
77 std::string pull_endpoint;
79
80 // RouterDealer — single bidirectional socket.
81 std::string endpoint;
83
85 std::optional<std::string> identity;
86
87 std::chrono::milliseconds linger{0};
88 int send_hwm = 1000;
89 int recv_hwm = 1000;
90
91 std::optional<CurveConfig> curve;
92
94};
95// NOLINTEND(clang-analyzer-optin.performance.Padding)
96
103public:
107 explicit Transport(Config config, std::shared_ptr<EventRegistry> registry = {});
108
109 Transport(const Transport&) = delete;
110 Transport& operator=(const Transport&) = delete;
111 Transport(Transport&&) = delete;
113
114 ~Transport() override;
115
116 [[nodiscard]] TransportScope scope() const noexcept override {
118 }
119
120 void attach_with_sink(Bus& bus, InboundSink sink) override;
121 void detach() noexcept override;
122
123 void dispatch(const EventEnvelopeView& v) override;
124 void flush() override;
125
126 [[nodiscard]] bool is_connected() const noexcept;
127
128private:
129 struct Impl;
130 std::unique_ptr<Impl> impl_;
131};
132
133} // namespace conduit::zmq
Bus — owns transports, middleware, listeners; dispatches envelopes.
Definition bus.hpp:58
Polymorphic envelope cell.
Definition envelope.hpp:62
Operational/runtime failure inside a transport adapter (connect, subscribe, publish,...
Definition exception.hpp:48
Definition transport.hpp:30
Bus * bus() const noexcept
Definition transport.hpp:68
ZeroMQ pipe — one instance covers a pattern-specific pair of sockets and carries traffic in both dire...
Definition transport.hpp:102
TransportScope scope() const noexcept override
Definition transport.hpp:116
Transport & operator=(const Transport &)=delete
void attach_with_sink(Bus &bus, InboundSink sink) override
Attach to a bus using a caller-supplied inbound sink.
Transport(Transport &&)=delete
void dispatch(const EventEnvelopeView &v) override
Transport(const Transport &)=delete
Transport & operator=(Transport &&)=delete
bool is_connected() const noexcept
void detach() noexcept override
Transport(Config config, std::shared_ptr< EventRegistry > registry={})
Construct a ZMQ pipe.
void flush() override
Operational/runtime failure inside the ZMQ transport adapter.
Definition transport.hpp:22
EventEnvelope — a parcel cell carrying conduit's envelope metadata plus a polymorphic payload cell.
Root exception hierarchy for the conduit library.
Transport interface and the local/remote scope enum used for flag-based filtering.
Listener / Subscription / Subscriber primitives.
Definition transport.hpp:19
Role
Per-socket role.
Definition transport.hpp:45
Pattern
ZMQ socket pattern.
Definition transport.hpp:32
@ RouterDealer
ROUTER+DEALER on a single bidirectional socket.
@ PubSub
PUB outbound, SUB inbound. Use for one-to-many fan-out broadcasts.
@ PushPull
PUSH outbound, PULL inbound. Round-robin pipeline.
Format
Wire format used for encoded envelopes.
Definition transport.hpp:28
std::function< void(const EventEnvelopeView &)> InboundSink
Callable installed on a Transport at attach time that receives inbound envelopes the transport pulled...
Definition transport.hpp:28
TransportScope
Distinguishes in-process transports from off-machine ones.
Definition transport.hpp:21
Thin EventRegistry wrapper around parcel::ParcelRegistry, plus envelope encode/decode helpers for JSO...
Definition transport.hpp:63
std::string push_endpoint
Definition transport.hpp:75
Role endpoint_role
Definition transport.hpp:82
int send_hwm
Definition transport.hpp:88
Format format
Definition transport.hpp:93
std::string subscription_prefix
ZMQ subscription filter prefix; empty means "subscribe to everything".
Definition transport.hpp:72
int recv_hwm
Definition transport.hpp:89
Role pull_role
Definition transport.hpp:78
std::chrono::milliseconds linger
Definition transport.hpp:87
std::string sub_endpoint
Definition transport.hpp:69
std::optional< CurveConfig > curve
Definition transport.hpp:91
Pattern pattern
Definition transport.hpp:64
Role push_role
Definition transport.hpp:76
Role sub_role
Definition transport.hpp:70
std::string endpoint
Definition transport.hpp:81
std::optional< std::string > identity
Optional socket identity / routing-id.
Definition transport.hpp:85
std::string pull_endpoint
Definition transport.hpp:77
std::string pub_endpoint
Definition transport.hpp:67
Role pub_role
Definition transport.hpp:68
CurveZMQ authentication parameters (gated by CONDUIT_TRANSPORT_ZMQ_CURVE).
Definition transport.hpp:48
bool is_server
When true, this socket is the Curve server; otherwise a client.
Definition transport.hpp:56
std::string public_key
Z85-encoded 40-byte public key of this socket.
Definition transport.hpp:52
std::string secret_key
Z85-encoded 40-byte secret key of this socket.
Definition transport.hpp:54
std::string server_key
Z85-encoded 40-byte public key of the server.
Definition transport.hpp:50