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/headers.hpp"
33#include "ores.nats/domain/message.hpp"
34#include "ores.nats/service/session_expired_error.hpp"
36namespace ores::nats::service {
class client; }
38namespace ores::nats::service {
74 inline static std::string_view logger_name =
"ores.nats.service.nats_client";
76 [[nodiscard]]
static auto& lg() {
78 static auto instance = make_logger(logger_name);
91 std::string tenant_id;
92 std::string tenant_name;
126 [[nodiscard]]
bool is_connected() const noexcept;
157 [[nodiscard]]
bool is_logged_in() const noexcept;
164 [[nodiscard]]
message request(
std::string_view subject,
165 std::string_view json_body);
173 std::string_view json_body,
174 std::chrono::milliseconds timeout =
std::chrono::seconds(30));
182 std::span<const
std::
byte> body,
183 std::chrono::milliseconds timeout =
std::chrono::seconds(10));
219 [[nodiscard]]
client& active_client() const;
221 [[nodiscard]]
message do_authenticated_request(
std::string_view subject,
222 std::span<const
std::
byte> body,
std::chrono::milliseconds timeout);
229 client* external_client_ =
nullptr;
233 std::
string delegation_token_;
236 std::
string correlation_id_;
248[[nodiscard]]
std::
string extract_bearer(const
ores::nats::
message& msg);
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition image.hpp:29
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:72
const login_info & auth() const
Return current auth info.
Definition nats_client.cpp:76
nats_client with_correlation_id(std::string cid) const
Returns a new nats_client that forwards a Nats-Correlation-Id header on every authenticated_request c...
Definition nats_client.cpp:163
void clear_auth()
Clear authentication info on logout.
Definition nats_client.cpp:68
std::function< std::string(bool force)> token_provider
Callable that returns a current Bearer token.
Definition nats_client.hpp:105
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:64
void disconnect()
Disconnect and clear all auth state.
Definition nats_client.cpp:49
nats_client with_delegation(std::string token) const
Returns a new nats_client that shares this instance's underlying connection and token provider but in...
Definition nats_client.cpp:152
std::shared_ptr< client > get_client() const
Return the underlying client (interactive path only).
Definition nats_client.cpp:194
void connect(config::nats_options opts)
Connect to NATS and take ownership of the connection.
Definition nats_client.cpp:34
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:184
Login state for the interactive path.
Definition nats_client.hpp:88