16#ifdef WITH_COMMON_SYSTEM
17#include "kcenon/common/resilience/circuit_breaker.h"
18#include "kcenon/common/resilience/circuit_state.h"
93 const std::string& host,
95 size_t max_retries = 3,
96 std::chrono::milliseconds initial_backoff = std::chrono::seconds(1)
97#ifdef WITH_COMMON_SYSTEM
98 , common::resilience::circuit_breaker_config cb_config = {}
136 [[nodiscard]]
auto is_connected()
const noexcept -> bool;
156 [[nodiscard]]
auto get_client()
const -> std::shared_ptr<core::messaging_client>;
158#ifdef WITH_COMMON_SYSTEM
163 [[nodiscard]]
auto circuit_state()
const -> common::resilience::circuit_state;
180 std::shared_ptr<core::messaging_client>
client_;
192#ifdef WITH_COMMON_SYSTEM
193 std::unique_ptr<common::resilience::circuit_breaker> circuit_breaker_;
Wrapper around messaging_client that adds automatic reconnection with exponential backoff and circuit...
auto reconnect() -> VoidResult
Attempts to reconnect with exponential backoff.
auto set_reconnect_callback(std::function< void(size_t attempt)> callback) -> void
Sets callback for reconnection events.
std::chrono::milliseconds initial_backoff_
std::shared_ptr< core::messaging_client > client_
~resilient_client() noexcept
Destructor - disconnects client if still connected.
auto calculate_backoff(size_t attempt) const -> std::chrono::milliseconds
Calculates backoff duration for given attempt.
resilient_client(const std::string &client_id, const std::string &host, unsigned short port, size_t max_retries=3, std::chrono::milliseconds initial_backoff=std::chrono::seconds(1))
Constructs a resilient client with reconnection support.
auto disconnect() -> VoidResult
Disconnects from the server.
auto connect() -> VoidResult
Connects to the server with retry logic.
auto send_with_retry(std::vector< uint8_t > &&data) -> VoidResult
Sends data with automatic reconnection on failure.
std::function< void(size_t)> reconnect_callback_
std::atomic< bool > is_connected_
std::function< void()> disconnect_callback_
auto is_connected() const noexcept -> bool
Checks if currently connected to server.
auto get_client() const -> std::shared_ptr< core::messaging_client >
Gets the underlying messaging client.
auto set_disconnect_callback(std::function< void()> callback) -> void
Sets callback for connection loss events.
TCP client implementation.
Utility components for network_system.
Result< std::monostate > VoidResult
Network-specific error and result type definitions.