KubeMQ
Learn

Events — Real-Time Pub/Sub

Publish and subscribe to real-time events with fire-and-forget delivery and at-most-once semantics.

PublisherEvents channelorder-notificationspublishSubscriber ASubscriber BSubscriber Coffline — message missed

Think of Events like a PA system in a building — when an announcement is made, everyone currently listening hears it. If you step outside, you miss the announcement. There's no recording, no replay.

KubeMQ Events implement fire-and-forget publish/subscribe with at-most-once delivery. Publishers send messages to a named channel, and all active subscribers receive the message in real time. There is no persistence — if a subscriber is offline, the message is lost for that subscriber.

The concept it implements

Events is KubeMQ's implementation of two fundamental ideas. The interaction style is pub/sub (fan-out) — one publisher, many subscribers, each receiving every message. The delivery guarantee is at-most-once — messages reach only the subscribers connected at publish time and are never persisted or redelivered. New to these terms? Start with the Fundamentals track.

Key Properties

PropertyThis patternLearn the concept
Interaction stylepub/sub (fan-out)Interaction styles
Delivery guaranteeat-most-onceDelivery guarantees
PersistenceNone — fire-and-forgetOrdering & replay
OrderingNot guaranteedOrdering & replay
ScalingFan-out, or load-balance with consumer groupsScaling & flow
AddressingNamed channels, wildcards, multicast routingChannels & routing

Key Features

  • At-most-once delivery — messages delivered to active subscribers only
  • Lowest latency — no disk I/O or acknowledgment overhead
  • Multicast delivery — every subscriber on the channel receives every message (fan-out)
  • Channel groups — load balance across subscribers in a named group
  • Multicast routing — publish to multiple channels using routing syntax
  • Stream publishing — high-throughput batched delivery via bidirectional streaming

How It Works

Fan-out: a publisher broadcasts to the channel, every connected subscriber receives the message, and offline subscribers miss it.

Quick Example

publish.go
package main

import (
    "context"
    "log"

    "github.com/kubemq-io/kubemq-go/v2"
)

func main() {
    ctx := context.Background()
    client, err := kubemq.NewClient(ctx,
        kubemq.WithAddress("localhost", 50000),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    err = client.SendEvent(ctx, kubemq.NewEvent().
        SetChannel("order-notifications").
        SetMetadata("order.created").
        SetBody([]byte(`{"orderId":"ORD-1234","status":"created"}`)),
    )
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Event sent successfully")
}
publish.py
from kubemq.pubsub import Client as PubSubClient
from kubemq.pubsub import EventMessage

client = PubSubClient(address="localhost:50000")
client.send_event(
    EventMessage(
        channel="order-notifications",
        metadata="order.created",
        body=b'{"orderId":"ORD-1234","status":"created"}',
    )
)
print("Event sent successfully")
client.close()
publish.js
import { KubeMQClient } from 'kubemq-js';

const client = await KubeMQClient.create({ address: 'localhost:50000' });
await client.sendEvent({
  channel: "order-notifications",
  metadata: "order.created",
  body: Buffer.from(JSON.stringify({ orderId: "ORD-1234", status: "created" })),
});

console.log("Event sent successfully");
Publish.java
PubSubClient client = PubSubClient.builder()
    .address("localhost:50000")
    .clientId("order-publisher")
    .build();

client.sendEventsMessage(EventMessage.builder()
    .channel("order-notifications")
    .metadata("order.created")
    .body("{\"orderId\":\"ORD-1234\",\"status\":\"created\"}".getBytes())
    .build());

System.out.println("Event sent successfully");
client.close();
Publish.cs
using KubeMQ.Sdk.Client;

await using var client = new KubeMQClient(new KubeMQClientOptions());
await client.ConnectAsync();

await client.SendEventAsync(new EventMessage
{
    Channel = "order-notifications",
    Metadata = "order.created",
    Body = Encoding.UTF8.GetBytes("{\"orderId\":\"ORD-1234\",\"status\":\"created\"}")
});

Console.WriteLine("Event sent successfully");
Publish.kt
val client = PubSubClient("localhost:50000")

client.sendEvent(EventMessage(
    channel = "order-notifications",
    metadata = "order.created",
    body = """{"orderId":"ORD-1234","status":"created"}""".toByteArray()
))

println("Event sent successfully")
client.close()
publish.cpp
#include <kubemq/client.h>

auto client = kubemq::PubSubClient("localhost:50000");

kubemq::EventMessage event;
event.channel = "order-notifications";
event.metadata = "order.created";
event.body = R"({"orderId":"ORD-1234","status":"created"})";

client.sendEvent(event);
std::cout << "Event sent successfully" << std::endl;
publish.rs
use kubemq::prelude::*;
use kubemq::EventBuilder;

#[tokio::main]
async fn main() -> kubemq::Result<()> {
    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    let event = EventBuilder::new()
        .channel("order-notifications")
        .metadata("order.created")
        .body(br#"{"orderId":"ORD-1234","status":"created"}"#.to_vec())
        .build();

    client.send_event(event).await?;
    println!("Event sent successfully");

    client.close().await?;
    Ok(())
}
publish.rb
require 'kubemq'

client = KubeMQ::PubSubClient.new(address: "localhost:50000", client_id: "order-publisher")

client.send_event(KubeMQ::PubSub::EventMessage.new(
  channel: "order-notifications",
  metadata: "order.created",
  body: '{"orderId":"ORD-1234","status":"created"}'
))

puts "Event sent successfully"
client.close
publish.exs
{:ok, client} = KubeMQ.Client.start_link(address: "localhost:50000", client_id: "order-publisher")

event = KubeMQ.Event.new(
  channel: "order-notifications",
  metadata: "order.created",
  body: ~s({"orderId":"ORD-1234","status":"created"})
)

:ok = KubeMQ.Client.send_event(client, event)
IO.puts("Event sent successfully")

KubeMQ.Client.close(client)

When to Use Events

ScenarioEventsEvents Store
Real-time notifications✅ Best choiceOverkill
Log/metric streaming✅ Best choiceUse if logs must not be lost
Live dashboards✅ Best choiceUse if historical data needed
Cache invalidation✅ Best choiceNot needed
Audit trails❌ Messages can be lost✅ Use Events Store
Event sourcing❌ No persistence✅ Use Events Store

Need guaranteed delivery or replay capability? Use Events Store instead.

Events are also available via the CloudEvents protocol — use any language with a CloudEvents SDK, no KubeMQ client library needed.

Learn More

Was this page helpful?

On this page