Create Channel
Create KubeMQ channels for every messaging pattern type, Events, Events Store, Commands, Queries, and Queues, in Rust.
Overview
KubeMQ auto-creates a channel the first time a client publishes or subscribes to it — convenient for prototyping, but a liability once channels are infrastructure you need to reason about. Pre-creating channels with the management API lets you provision topology before any producer or consumer connects: enforce naming conventions in a startup script, stand up the channels a service depends on as part of deployment, or fail fast if a required channel is missing instead of it silently springing into existence.
Convenience methods like create_events_channel, create_events_store_channel, create_commands_channel, create_queries_channel, and create_queues_channel wrap the generic create_channel call, registering the channel directly with the server for a given pattern type.
Gotchas: the call is idempotent for a matching name and type, so it's safe to call on every startup — but a channel's type is fixed at creation, and reusing the name with a different type fails rather than migrating it. Creation only registers the channel; it does not start a consumer, so a freshly created queue or events channel happily accepts messages with nothing yet reading them.
Prerequisites
- KubeMQ server running on
localhost:50000 - Rust SDK installed (
cargo add kubemq)
Code
use kubemq::prelude::*;
#[tokio::main]
async fn main() -> kubemq::Result<()> {
let client = KubemqClient::builder()
.host("localhost")
.port(50000)
.build()
.await?;
client.create_events_channel("example-events-ch").await?;
println!("Created events channel");
client.create_events_store_channel("example-store-ch").await?;
println!("Created events store channel");
client.create_commands_channel("example-commands-ch").await?;
println!("Created commands channel");
client.create_queries_channel("example-queries-ch").await?;
println!("Created queries channel");
client.create_queues_channel("example-queues-ch").await?;
println!("Created queues channel");
client.close().await?;
Ok(())
}How It Works
- Convenience methods like
create_events_channelwrap the genericcreate_channelmethod. - Channel names must be non-empty; channel types must match one of the five valid types.
- Review timeouts, channel names, and client IDs before running against shared environments.
- Run the program while the server from the prerequisites is available.
Related
Was this page helpful?