Magistrala
Dev GuideServices

Channels

Channel management service for Magistrala — create and configure communication channels, connect clients, manage access control and route messages between devices and applications.

The Channels service manages communication channels in Magistrala. A channel is a message topic that clients connect to for pub/sub messaging. The service handles channel creation, configuration, client connections, group hierarchy, and role-based access control. It exposes both HTTP and gRPC APIs.

Configuration

VariableDescriptionDefault
MG_CHANNELS_LOG_LEVELLog level (debug, info, warn, error)info
MG_CHANNELS_HTTP_HOSTHTTP hostlocalhost
MG_CHANNELS_HTTP_PORTHTTP port9005
MG_CHANNELS_GRPC_HOSTgRPC hostlocalhost
MG_CHANNELS_GRPC_PORTgRPC port7005
MG_CHANNELS_DB_HOSTDatabase hostlocalhost
MG_CHANNELS_DB_PORTDatabase port5432
MG_CHANNELS_DB_USERDatabase usermagistrala
MG_CHANNELS_DB_PASSDatabase passwordmagistrala
MG_CHANNELS_DB_NAMEDatabase namechannels
MG_CHANNELS_DB_SSL_MODESSL mode (disable, require, verify-ca, verify-full)disable
MG_CHANNELS_CACHE_URLRedis cache URLredis://localhost:6379/0
MG_JAEGER_URLJaeger tracing endpointhttp://jaeger:4318/v1/traces
MG_SEND_TELEMETRYSend telemetry to Magistrala call-home servertrue

Database Schema

channels table

ColumnTypeDescription
idVARCHAR(36)UUID primary key
nameVARCHAR(1024)Human-readable name
domain_idVARCHAR(36)Owning domain
parent_group_idVARCHAR(36)Optional parent group
tagsTEXT[]Arbitrary tags
metadataJSONBFree-form structured metadata
statusSMALLINT0 = enabled, 1 = disabled
routeVARCHAR(36)Optional unique identifier for routing within a domain

connections table

ColumnTypeDescription
channel_idVARCHAR(36)Channel UUID
domain_idVARCHAR(36)Domain of channel and client
client_idVARCHAR(36)Client UUID
typeSMALLINT1 = Publish, 2 = Subscribe

Deployment

git clone https://github.com/absmach/magistrala
cd magistrala

make channels
make install

MG_CHANNELS_LOG_LEVEL=info \
MG_CHANNELS_HTTP_HOST=localhost \
MG_CHANNELS_HTTP_PORT=9005 \
MG_CHANNELS_DB_HOST=localhost \
MG_CHANNELS_DB_PORT=5432 \
MG_CHANNELS_DB_USER=magistrala \
MG_CHANNELS_DB_PASS=magistrala \
MG_CHANNELS_DB_NAME=channels \
MG_CHANNELS_CACHE_URL=redis://localhost:6379/0 \
$GOBIN/magistrala-channels

HTTP API

Base URL defaults to http://localhost:9005. All endpoints require Authorization: Bearer <token> and a <domainID> path prefix.

OperationDescription
createCreate one or more channels
getRetrieve a channel by ID
listPage and filter channels in a domain
updateUpdate name, metadata, tags, or route
deletePermanently delete a channel
enable/disableToggle channel active state
set-parentAssign a parent group
remove-parentDetach from parent group
connectConnect clients to channels
disconnectRemove client-channel connections
create-roleCreate an RBAC role on a channel
add-role-memberAdd users to a channel role

Create a channel

curl -X POST "http://localhost:9005/<domainID>/channels" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "sensor-readings",
    "metadata": { "unit": "celsius" },
    "route": "temp-lab",
    "tags": ["sensor", "lab"]
  }'

Connect clients to a channel

curl -X POST "http://localhost:9005/<domainID>/channels/connect" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel_ids": ["<chanID>"],
    "client_ids": ["<clientID>"],
    "types": ["publish", "subscribe"]
  }'

Disconnect clients from a channel

curl -X POST "http://localhost:9005/<domainID>/channels/disconnect" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel_ids": ["<chanID>"],
    "client_ids": ["<clientID>"],
    "types": ["publish"]
  }'

Health check

curl http://localhost:9005/health

Best Practices

  • Use route when a channel needs a predictable human-readable identifier for message routing.
  • Use tags and metadata to categorize channels by environment, region, or purpose.
  • Keep channel hierarchies shallow — avoid deep nesting unless the use case demands it.
  • Use disable instead of delete when you want to temporarily suspend a channel.
  • Regularly audit client-channel connections and remove stale links.
  • Grant clients only the connection type they actually need (Publish or Subscribe, not both by default).

For the full API reference, see the API documentation.

On this page