Events — Real-Time Pub/Sub
Publish and subscribe to real-time events with fire-and-forget delivery and at-most-once semantics.
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
| Property | This pattern | Learn the concept |
|---|---|---|
| Interaction style | pub/sub (fan-out) | Interaction styles |
| Delivery guarantee | at-most-once | Delivery guarantees |
| Persistence | None — fire-and-forget | Ordering & replay |
| Ordering | Not guaranteed | Ordering & replay |
| Scaling | Fan-out, or load-balance with consumer groups | Scaling & flow |
| Addressing | Named channels, wildcards, multicast routing | Channels & 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
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")
}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()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");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();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");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()#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;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(())
}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{: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
| Scenario | Events | Events Store |
|---|---|---|
| Real-time notifications | ✅ Best choice | Overkill |
| Log/metric streaming | ✅ Best choice | Use if logs must not be lost |
| Live dashboards | ✅ Best choice | Use if historical data needed |
| Cache invalidation | ✅ Best choice | Not 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
Getting Started
Publish and subscribe to your first event in 5 minutes.
Publish & Subscribe
Learn the basic pub/sub pattern with multiple subscribers.
Consumer Groups
Distribute event processing across a group.
Wildcard Subscriptions
Subscribe to multiple channels with patterns.
Multicast Events
Publish to multiple channels simultaneously.
Stream Publishing
High-throughput batched event delivery.
Events Reference
Message structure, validation rules, and error codes.
Was this page helpful?
Channels & Routing
How messages find their destination — named channels, wildcard subscriptions, and multicast routing that fans one publish out to many channels.
Getting Started with Events
Build a fire-and-forget publisher and subscriber and send your first KubeMQ event in 5 minutes — at-most-once delivery, no persistence.