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::nats {
20
23public:
24 using conduit::TransportError::TransportError;
25};
26
28enum class Format : std::uint8_t { Json, Cbor };
29
30struct TlsConfig {
31 std::string ca_file;
32 std::optional<std::string> cert_file;
33 std::optional<std::string> key_file;
34 bool verify_peer = true;
35};
36
37struct Config {
39 std::string url = "nats://localhost:4222";
40
42 std::string name;
43
44 std::optional<std::string> user;
45 std::optional<std::string> password;
46 std::optional<std::string> token;
47
49 std::optional<std::string> credentials_file;
50
51 std::optional<TlsConfig> tls;
52
53 std::chrono::seconds connect_timeout{10};
54 std::chrono::seconds reconnect_wait{2};
56
62 std::string subject = "conduit.envelope";
63
66 std::optional<std::string> queue_group;
67
70};
71
77public:
81 explicit Transport(Config config, std::shared_ptr<EventRegistry> registry = {});
82
83 Transport(const Transport&) = delete;
84 Transport& operator=(const Transport&) = delete;
85 Transport(Transport&&) = delete;
87
88 ~Transport() override;
89
90 [[nodiscard]] TransportScope scope() const noexcept override {
92 }
93
94 void attach_with_sink(Bus& bus, InboundSink sink) override;
95 void detach() noexcept override;
96
97 void dispatch(const EventEnvelopeView& v) override;
98 void flush() override;
99
100 [[nodiscard]] bool is_connected() const noexcept;
101
102private:
103 struct Impl;
104 std::unique_ptr<Impl> impl_;
105};
106
107} // namespace conduit::nats
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
Operational/runtime failure inside the NATS transport adapter.
Definition transport.hpp:22
NATS pipe — one instance binds to a single NATS subject and carries traffic in both directions: outbo...
Definition transport.hpp:76
Transport(Config config, std::shared_ptr< EventRegistry > registry={})
Construct a NATS pipe.
Transport(Transport &&)=delete
void dispatch(const EventEnvelopeView &v) override
Transport & operator=(Transport &&)=delete
Transport(const Transport &)=delete
void flush() override
void detach() noexcept override
TransportScope scope() const noexcept override
Definition transport.hpp:90
void attach_with_sink(Bus &bus, InboundSink sink) override
Attach to a bus using a caller-supplied inbound sink.
bool is_connected() const noexcept
Transport & operator=(const Transport &)=delete
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
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:37
std::optional< std::string > password
Definition transport.hpp:45
std::optional< TlsConfig > tls
Definition transport.hpp:51
std::string subject
Subject this transport binds to.
Definition transport.hpp:62
int max_reconnects
Definition transport.hpp:55
std::optional< std::string > queue_group
When set, the transport uses natsConnection_QueueSubscribe so that multiple subscribers form a load-b...
Definition transport.hpp:66
std::chrono::seconds reconnect_wait
Definition transport.hpp:54
std::string name
Optional connection name (empty -> ULID-derived).
Definition transport.hpp:42
std::chrono::seconds connect_timeout
Definition transport.hpp:53
std::optional< std::string > credentials_file
Path to a JWT / NKey credentials file (e.g. NATS NGS).
Definition transport.hpp:49
Format format
Wire format used for both outbound publishes and inbound decoding.
Definition transport.hpp:69
std::optional< std::string > token
Definition transport.hpp:46
std::optional< std::string > user
Definition transport.hpp:44
std::string url
NATS connection URL(s). Comma-separated for clusters.
Definition transport.hpp:39
Definition transport.hpp:30
std::string ca_file
Definition transport.hpp:31
std::optional< std::string > key_file
Definition transport.hpp:33
std::optional< std::string > cert_file
Definition transport.hpp:32
bool verify_peer
Definition transport.hpp:34