---
source_url: https://www.pubnub.com/docs/sdks/kotlin/entities/channel-group
title: ChannelGroup Entity
updated_at: 2026-05-22T11:06:54.239Z
sdk_name: PubNub Kotlin SDK
sdk_version: 13.3.0
---

> 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


# ChannelGroup Entity

PubNub Kotlin SDK, use the latest version: 13.3.0

Install:

```bash
Add PubNub dependency to your build@13.3.0
```

As of version 9.0.0, the Kotlin software development kit (SDK) supports entities. Entities are SDK objects that bundle operations for a specific resource type and simplify working with PubNub application programming interfaces (APIs).

Use entities to perform common tasks without manually wiring requests. Some PubNub APIs are exposed via entities. Other operations remain available on the `pubnub` object.

## Create ChannelGroup

Use this factory method to return a local `ChannelGroup` entity for a single channel group. A `ChannelGroup` entity centralizes operations—such as creating a subscription—so you can prototype and build faster.

```kotlin
pubnub.channelGroup(name: String): ChannelGroup
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| name | String | Yes |  | Name of the [channel group](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) for which to create the entity. |

#### Sample code

:::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.
:::

```kotlin
import com.pubnub.api.PubNub
import com.pubnub.api.UserId
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.api.v2.entities.ChannelGroup

fun main() {
    println("PubNub ChannelGroup Entity Example")
    println("=================================")

    // 1. Configure PubNub
    val userId = UserId("channel-group-entity-demo-user")
    val config = PNConfiguration.builder(userId, "demo").apply {
        publishKey = "demo"
        subscribeKey = "demo"
    }.build()

    // 2. Create PubNub instance
    val pubnub = PubNub.create(config)

    // 3. Create a ChannelGroup entity
    val groupName = "demo-entity-group"
    val channelGroup: ChannelGroup = pubnub.channelGroup(groupName)
    println("Created ChannelGroup entity for: ${channelGroup.name}")

    // Define channels to add to the group
    val channelMarketing = "chat-marketing"
    val channels = listOf(
        channelMarketing,
        "chat-engineering",
        "chat-support"
    )

    // 4. Add channels to the group
    println("\nAdding channels to group...")
    pubnub.addChannelsToChannelGroup(
        channelGroup = groupName,
        channels = channels
    ).async { result ->
        result.onSuccess {
            println("SUCCESS: Added channels to group '$groupName':")
            channels.forEach { println("- $it") }
        }.onFailure { exception ->
            println("ERROR: Failed to add channels to group")
            println("Error details: ${exception.message}")
        }
    }

    // 5. Define a subscription to the channel group
    val channelGroupSubscription = channelGroup.subscription()

    channelGroupSubscription.onMessage = { result ->
        println("Received message: ${result.message.asString}")
    }

    channelGroupSubscription.subscribe()
    Thread.sleep(2000)

    // 6. Publish a message to a channel in the group
    pubnub.publish(channelMarketing, "Important message").sync()

    // Wait for operation to complete
    Thread.sleep(2000)

    // Clean up
    pubnub.destroy()
    println("\nPubNub connection closed")
}
```

## Available operations

The `ChannelGroup` entity provides operations for PubNub [channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups).

| Operation (click for more information) | Description |
| --- | --- |
| [subscription(subscriptionOptions)](https://www.pubnub.com/docs/sdks/kotlin/api-reference/publish-and-subscribe#subscribe) | Returns a local channel group [subscription object](https://www.pubnub.com/docs/general/channels/subscribe#subscription-types) with [optional parameters](https://www.pubnub.com/docs/general/channels/subscribe#subscription-options). You can then subscribe to receive real-time updates for that channel group. |