KubeMQ
Client SDKsRubyHow-to guidesManagement

Create Channel

Create messaging channels on the KubeMQ broker with the Ruby SDK, provisioning queues or pub/sub topics before traffic arrives.

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.

Each client provides typed methods for the patterns it owns — events and events-store on the pub/sub client, queues on the queues client, commands and queries on the CQ client — each registering the channel directly with the broker.

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
  • Ruby SDK installed (gem install kubemq)

Code

main.rb
require 'kubemq'

address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')

begin
  pubsub = KubeMQ::PubSubClient.new(address: address, client_id: 'mgmt-create-example')
  queues = KubeMQ::QueuesClient.new(address: address, client_id: 'mgmt-create-example')
  cq = KubeMQ::CQClient.new(address: address, client_id: 'mgmt-create-example')
  puts "Connected to #{address}"

  pubsub.create_events_channel(channel_name: 'mgmt.events.test')
  puts 'Created events channel: mgmt.events.test'

  pubsub.create_events_store_channel(channel_name: 'mgmt.es.test')
  puts 'Created events store channel: mgmt.es.test'

  queues.create_queues_channel(channel_name: 'mgmt.queues.test')
  puts 'Created queues channel: mgmt.queues.test'

  cq.create_commands_channel(channel_name: 'mgmt.commands.test')
  puts 'Created commands channel: mgmt.commands.test'

  cq.create_queries_channel(channel_name: 'mgmt.queries.test')
  puts 'Created queries channel: mgmt.queries.test'
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  pubsub&.close
  queues&.close
  cq&.close
  puts 'Done'
end

How It Works

  • Each client provides convenience methods for creating channels of its supported types.
  • Channels are created on the broker and persist until explicitly deleted.
  • Review timeouts, channel names, and client IDs before running against shared environments.

Was this page helpful?

On this page