# Create Channel (/sdks/elixir/how-to/management/create-channel)



## Overview [#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.

`KubeMQ.Client.create_channel/3` takes a client, a channel name, and a type atom (`:events`, `:events_store`, `:commands`, `:queries`, or `:queues`), registering the channel directly with the broker and returning `:ok` or `{:error, %KubeMQ.Error{}}`.

**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 [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Elixir SDK installed (`{:kubemq, "~> 1.0"}` in mix.exs)

## Code [#code]

```elixir title="main.exs"
{:ok, client} = KubeMQ.Client.start_link(address: "localhost:50000", client_id: "elixir-mgmt-create")

channels = [
  {"elixir-mgmt.events-channel", :events},
  {"elixir-mgmt.events-store-channel", :events_store},
  {"elixir-mgmt.commands-channel", :commands},
  {"elixir-mgmt.queries-channel", :queries},
  {"elixir-mgmt.queues-channel", :queues}
]

for {name, type} <- channels do
  case KubeMQ.Client.create_channel(client, name, type) do
    :ok -> IO.puts("Created #{type} channel '#{name}'")
    {:error, err} -> IO.puts("Failed to create '#{name}': #{err.message}")
  end
end

IO.puts("\nAll channels created.")
KubeMQ.Client.close(client)
```

## How It Works [#how-it-works]

* `create_channel/3` accepts a channel name and type atom
* Supported types: `:events`, `:events_store`, `:commands`, `:queries`, `:queues`
* Returns `:ok` on success or `{:error, %KubeMQ.Error{}}` on failure

## Related [#related]

* [Delete Channel](/sdks/elixir/how-to/management/delete-channel)
* [List Channels](/sdks/elixir/how-to/management/list-channels)
