---
source_url: https://www.pubnub.com/docs/sdks/ruby/api-reference/channel-groups
title: Channel Groups API for Ruby SDK
updated_at: 2026-06-12T11:26:39.470Z
sdk_name: PubNub Ruby SDK
sdk_version: 6.0.2
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Channel Groups API for Ruby SDK

PubNub Ruby SDK, use the latest version: 6.0.2

Install:

```bash
gem install pubnub@6.0.2
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the Ruby SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```ruby
channel_registration(
    action: :add,
    channels: channels,
    channel_groups: channel_groups,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| action | Symbol | Yes |  | Action to perform; to add, use `:add`. |
| channels | String, | Yes |  | The channels to add to channel groups. |
| channel_groups | String, | Yes |  | The channel groups to add channels to. |
| http_sync | Boolean | Optional |  | Default `false`. Executes asynchronously and returns a future. If `true`, returns an array of envelopes (or a single envelope). |
| callback | Lambda | Optional |  | Callback for each envelope. For async methods a future is returned; call `value` to retrieve the `Envelope`. |

### Sample code

#### Add channels

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```ruby
require 'pubnub'

def add_channels_to_group(pubnub)
  # Async without callback
  pubnub.channel_registration(action: :add, channel: 'my_channel', channel_group: :somegroup) do |envelope|
    if envelope.status[:error]
      puts "Async Error: #{envelope.status[:error]}"
    else
      puts "Async Success: Channels added to channel group."
    end
  end

  # Sync without callback
  begin
    envelopes = pubnub.channel_registration(action: :add, channel: 'my_channel', channel_group: :somegroup, http_sync: true)
    puts "Sync Success: Channels added to channel group."
  rescue StandardError => e
    puts "Sync Error: #{e.message}"
  end
end

def main
  # Configuration for PubNub instance
  pubnub = Pubnub.new(
    subscribe_key: ENV.fetch('SUBSCRIBE_KEY', 'demo'),
    user_id: 'myUniqueUserId'
  )

  # Add channels to group
  add_channels_to_group(pubnub)
end

if __FILE__ == $0
  main
end
```

### Response

```ruby
#<Pubnub::Envelope:0x007fd385096220
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Ruby SDK:

```ruby
channel_registration(
    action: :get,
    channel_group: group,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Description |
| --- | --- |
| `action` *Type: Symbol | The action to perform; to get all channels from a channel group, specify `:get`. |
| `channel_groups` *Type: String, Symbol | The channel groups for which to list channels. |
| `http_sync`Type: Boolean | Default `false`. Executes asynchronously and returns a future. If `true`, returns an array of envelopes (or a single envelope). |
| `callback`Type: Lambda accepting one parameter | Callback for each envelope. For async methods a future is returned; call `value` to retrieve the `Envelope`. |

### Sample code

#### List channels

```ruby
pubnub.channel_registration(action: :get, group: 'family') do |envelope|
    pp envelope
end
```

### Response

```ruby
#<Pubnub::Envelope:0x007fd385856cf8
    @result = {
        :data => {
            "channels" => ["ben"],
            "group" => "family"
        }
    }
    @status = {
        :code => 200
    }
>
```

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Ruby SDK:

```ruby
channel_registration(
    action: :remove,
    channels: channels,
    channel_groups: group,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Description |
| --- | --- |
| `action` *Type: Symbol | The action to perform; to remove channels, specify `:remove`. |
| `channels` *Type: String, Symbol | The channels to remove from channel groups. |
| `channel_groups` *Type: String, Symbol | The channel groups from which to remove channels. |
| `http_sync`Type: Boolean | Default `false`. Executes asynchronously and returns a future. If `true`, returns an array of envelopes (or a single envelope). |
| `callback`Type: Lambda accepting one parameter | Callback for each envelope. For async methods a future is returned; call `value` to retrieve the `Envelope`. |

### Sample code

#### Remove channels

```ruby
pubnub.channel_registration(action: :remove, channel: 'son', group: 'family') do |envelope|
    pp envelope
end
```

### Response

```ruby
#<Pubnub::Envelope:0x007fd385096220
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function deletes a channel group.

### Method(s)

Use the following method in the Ruby SDK:

```ruby
channel_registration(
    action: :remove,
    channel_groups: channel_groups,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Description |
| --- | --- |
| `action` *Type: Symbol | Use `:remove` to remove the channel groups. |
| `channel_groups` *Type: String, Symbol | The channel groups to remove. |
| `http_sync`Type: Boolean | Default `false`. Executes asynchronously and returns a future. If `true`, returns an array of envelopes (or a single envelope). |
| `callback`Type: Lambda accepting one parameter | Callback for each envelope. For async methods a future is returned; call `value` to retrieve the `Envelope`. |

### Sample code

#### Delete channel group

```ruby
pubnub.channel_registration(action: :remove, channel_group: 'family') do |envelope|
    pp envelope
end
```

### Response

```ruby
#<Pubnub::Envelope:0x007fd385096220
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.