20#ifndef ORES_NATS_SERVICE_NATS_CLIENT_HPP
21#define ORES_NATS_SERVICE_NATS_CLIENT_HPP
30#include "ores.logging/make_logger.hpp"
31#include "ores.nats/config/nats_options.hpp"
32#include "ores.nats/domain/message.hpp"
33#include "ores.nats/service/session_expired_error.hpp"
35namespace ores::nats::service {
class client; }
37namespace ores::nats::service {
73 inline static std::string_view logger_name =
"ores.nats.service.nats_client";
75 [[nodiscard]]
static auto& lg() {
77 static auto instance = make_logger(logger_name);
90 std::string tenant_id;
91 std::string tenant_name;
125 [[nodiscard]]
bool is_connected() const noexcept;
156 [[nodiscard]]
bool is_logged_in() const noexcept;
163 [[nodiscard]]
message request(
std::string_view subject,
164 std::string_view json_body);
172 std::string_view json_body,
173 std::chrono::milliseconds timeout =
std::chrono::seconds(30));
181 std::span<const
std::
byte> body,
182 std::chrono::milliseconds timeout =
std::chrono::seconds(10));
192 [[nodiscard]]
client& active_client() const;
194 [[nodiscard]]
message do_authenticated_request(
std::string_view subject,
195 std::span<const
std::
byte> body,
std::chrono::milliseconds timeout);
202 client* external_client_ =
nullptr;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
@ client
Indicates that the span describes a request to some remote service. This is often the client-side of ...
Configuration for a NATS connection.
Definition nats_options.hpp:30
A received NATS message.
Definition message.hpp:40
NATS client: connection, pub/sub, request/reply, and JetStream.
Definition client.hpp:73
Authenticated NATS client for both interactive and service-to-service use.
Definition nats_client.hpp:71
const login_info & auth() const
Return current auth info.
Definition nats_client.cpp:75
void clear_auth()
Clear authentication info on logout.
Definition nats_client.cpp:67
std::function< std::string(bool force)> token_provider
Callable that returns a current Bearer token.
Definition nats_client.hpp:104
nats_client()=default
Default-construct for interactive use. Call connect() next.
void set_auth(login_info info)
Store authentication info after a successful login.
Definition nats_client.cpp:63
void disconnect()
Disconnect and clear all auth state.
Definition nats_client.cpp:48
std::shared_ptr< client > get_client() const
Return the underlying client (interactive path only).
Definition nats_client.cpp:147
void connect(config::nats_options opts)
Connect to NATS and take ownership of the connection.
Definition nats_client.cpp:33
message authenticated_request(std::string_view subject, std::string_view json_body, std::chrono::milliseconds timeout=std::chrono::seconds(30))
Authenticated synchronous request — string body overload.
Definition nats_client.cpp:137
Login state for the interactive path.
Definition nats_client.hpp:87