Channel Groups API for C# SDK
Channel groups allow PubNub developers to bundle thousands of channels 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.
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.
Request execution
Use try/catch when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned status.
1try
2{
3 PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
4 .Message("Why do Java developers wear glasses? Because they can't C#.")
5 .Channel("my_channel")
6 .ExecuteAsync();
7
8 PNStatus status = publishResponse.Status;
9
10 Console.WriteLine("Server status code : " + status.StatusCode.ToString());
11}
12catch (Exception ex)
13{
14 Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
15}
Add channels to a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds channels to a channel group.
Method(s)
Use the following method in the C# SDK:
Maximum number of channels
You can add up to 200 channels to a channel group per API call.
1pubnub.AddChannelsToChannelGroup()
2 .ChannelGroup(string)
3 .Channels(Array)
4 .QueryParam(Dictionary<string,object>)
| Parameter | Description |
|---|---|
ChannelGroup *Type: string | The channel group to add the channels to. |
Channels *Type: Array | The channels to add to the channel group. |
QueryParamType: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
AsyncType: | PNCallback of type PNChannelGroupsAddChannelResult.This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNChannelGroupsAddChannelResult. |
ExecuteAsyncType: None | Returns PNResult<PNChannelGroupsAddChannelResult>. |
Sample code
Reference code
Add channels
1
Returns
The AddChannelsToChannelGroup() operation returns a PNResult<PNChannelGroupsAddChannelResult> which contains the following properties:
| Property Name | Type | Description |
|---|---|---|
Result | PNChannelGroupsAddChannelResult | Returns a PNChannelGroupsAddChannelResult object. |
Status | PNStatus | Returns a PNStatus object. |
PNChannelGroupsAddChannelResult contains the following properties:
| Property Name | Type | Description |
|---|---|---|
PNChannelGroupsAddChannelResult | Object | Returns empty object. |
PNStatus | Object | Returns status of request if error occurred or not. |
List channels in a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page 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 C# SDK:
1pubnub.ListChannelsForChannelGroup()
2 .ChannelGroup(string)
3 .QueryParam(Dictionary<string,object>)
| Parameter | Description |
|---|---|
ChannelGroup *Type: string | The channel group for which to list channels. |
QueryParamType: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
AsyncType: | PNCallback of type PNChannelGroupsAllChannelsResult.This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNChannelGroupsAllChannelsResult. |
ExecuteAsyncType: None | Returns PNResult<PNChannelGroupsAllChannelsResult>. |
Sample code
List channels
1
Returns
The ListChannelsForChannelGroup() operation returns a PNChannelGroupsAllChannelsResult which contains the following properties:
| Property Name | Type | Description |
|---|---|---|
Result | PNChannelGroupsAllChannelsResult | Returns a PNChannelGroupsAllChannelsResult object. |
Status | PNStatus | Returns a PNStatus object. |
PNChannelGroupsAllChannelsResult contains the following property:
| Property Name | Type | Description |
|---|---|---|
Channels | List<string> | List of channels of a channel group. |
Remove channels from a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes channels from a channel group.
Method(s)
Use the following method in the C# SDK:
1pubnub.RemoveChannelsFromChannelGroup()
2 .ChannelGroup(string)
3 .Channels(Array)
4 .QueryParam(Dictionary<string,object>)
| Parameter | Description |
|---|---|
ChannelGroup *Type: string | The channel group from which to remove the channels. |
Channels *Type: Array | The channels to remove from the channel group. |
QueryParamType: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
AsyncType: | PNCallback of type PNChannelGroupsRemoveChannelResult.This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNChannelGroupsRemoveChannelResult. |
ExecuteAsyncType: None | Returns PNResult<PNChannelGroupsRemoveChannelResult>. |
Sample code
Remove channels
1
Returns
The RemoveChannelsFromChannelGroup() operation returns a PNChannelGroupsAddChannelResult which contains the following properties:
| Property Name | Type | Description |
|---|---|---|
Result | PNChannelGroupsRemoveChannelResult | Returns a PNChannelGroupsRemoveChannelResult object. |
Status | PNStatus | Returns a PNStatus object. |
PNChannelGroupsRemoveChannelResult contains the following property:
| Property Name | Type | Description |
|---|---|---|
PNChannelGroupsRemoveChannelResult | Object | Returns empty object. |
Delete a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function deletes a channel group.
Method(s)
Use the following method in the C# SDK:
1pubnub.DeleteChannelGroup()
2 .ChannelGroup(string)
3 .QueryParam(Dictionary<string,object>)
| Parameter | Description |
|---|---|
ChannelGroup *Type: string | The channel group to delete. |
QueryParamType: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
AsyncType: | PNCallback of type PNChannelGroupsDeleteGroupResult.This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNChannelGroupsDeleteGroupResult. |
ExecuteAsyncType: None | Returns PNResult<PNChannelGroupsAllChannelsResult>. |
Sample code
Delete channel group
1
Response
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}