Reduce messaging handler boilerplate

Table of Contents

This page is a capture in the next bucket of the product backlog — a pre-sprint idea, not yet pulled into a sprint as a story.

What

(One paragraph: the idea.)

Why

(Motivation, problem being solved, related context.)

References

See also

Every messaging handler repeats:

BOOST_LOG_SEV(some_entity_handler_lg(), debug) << "Handling " << msg.subject;
auto req_ctx_expected = ores::service::service::make_request_context(ctx_, msg, verifier_);
if (!req_ctx_expected) { error_reply(nats_, msg, req_ctx_expected.error()); return; }
const auto& req_ctx = *req_ctx_expected;
if (!has_permission(req_ctx, "module::entity:write")) { error_reply(...); return; }

And every handler holds the same three members:

ores::nats::service::client& nats_;
ores::database::context ctx_;
std::optional<ores::security::jwt::jwt_authenticator> verifier_;

Proposed fixes:

  • Introduce a BaseHandler (or CRTP mixin) that owns these members and exposes a handle_request template that performs the preamble then calls a user-provided lambda with (req_ctx, msg).
  • Add using service_type = ... / using response_type = ... type aliases inside each handler so the body reads in terms of concepts rather than concrete names.
  • Derive a per-handler log_category() static that lg() calls, removing the verbose per-file log-category function.

Emacs 29.1 (Org mode 9.6.6)