KubeMQ
Client SDKsC++Reference

Events

Event publishing and subscription methods -- KubeMQ C++ SDK reference.

Fire-and-forget event messaging. Events are delivered to all active subscribers in real time and are not persisted.

Types

Event

Built via Event::Builder. Required field: channel.

auto event_or = kubemq::Event::Builder()
    .SetChannel("notifications")
    .SetBody("hello")
    .SetMetadata("greeting")
    .AddTag("env", "prod")
    .Build();
MethodTypeRequiredDescription
SetChannel(s)stringYesTarget channel name
SetBody(s)stringNoMessage body
SetMetadata(s)stringNoString metadata
SetId(s)stringNoEvent ID (auto-generated)
SetClientId(s)stringNoOverride client ID
SetTags(m)map<string,string>NoKey-value tags
AddTag(k, v)string, stringNoAdd a single tag

EventReceive

Received in subscription callbacks.

FieldTypeDescription
idstringEvent identifier
channelstringChannel name
metadatastringString metadata
bodystringMessage body
timestampint64_tUnix nanoseconds
sequenceuint64_tAlways 0 for non-store events
tagsmap<string,string>Key-value tags

Methods

SendEvent

[[nodiscard]] Status SendEvent(const Event& event);

Send a single fire-and-forget event. Returns Status indicating success or failure.

PublishEvent

[[nodiscard]] Status PublishEvent(
    const std::string& channel, const std::string& body,
    const std::string& metadata = "",
    const std::unordered_map<std::string, std::string>& tags = {});

Convenience method to build and send an event in one call.

SendEventStream

[[nodiscard]] StatusOr<std::unique_ptr<EventStreamHandle>> SendEventStream(
    std::function<void(const Status&)> on_error);

Open a persistent bidirectional stream for high-throughput event sending. Use handle->Send(event) to send events and handle->Close() to close the stream.

SubscribeToEvents

[[nodiscard]] StatusOr<std::unique_ptr<Subscription>> SubscribeToEvents(
    const std::string& channel, const std::string& group,
    std::function<void(const EventReceive&)> on_event,
    std::function<void(const Status&)> on_error);

Subscribe to real-time events on a channel. Pass an empty string for group to receive all events (fan-out). Use sub->Cancel() to unsubscribe.

Quick Usage

events.cc
// Subscribe
auto sub_or = client->SubscribeToEvents("ch", "",
    [](const kubemq::EventReceive& e) {
        std::cout << "Got: " << e.body << "\n";
    },
    [](const kubemq::Status& err) {
        std::cerr << "Error: " << err.message() << "\n";
    });

// Publish
client->PublishEvent("ch", "hello", "meta", {{"key", "val"}});

// Stream
auto stream_or = client->SendEventStream(
    [](const kubemq::Status& err) { /* handle */ });
(*stream_or)->Send(event);
(*stream_or)->Close();

See Also

Was this page helpful?

On this page