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
.
try
{
PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
.Message("Why do Java developers wear glasses? Because they can't C#.")
.Channel("my_channel")
.ExecuteAsync();
PNStatus status = publishResponse.Status;
Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
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.
pubnub.AddChannelsToChannelGroup()
.ChannelGroup(string)
.Channels(Array)
.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. |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | 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 . |
ExecuteAsync Type: None | Returns PNResult<PNChannelGroupsAddChannelResult> . |
Sample code
Reference code
Add channels
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:
pubnub.ListChannelsForChannelGroup()
.ChannelGroup(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
ChannelGroup *Type: string | The channel group for which to list channels. |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | 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 . |
ExecuteAsync Type: None | Returns PNResult<PNChannelGroupsAllChannelsResult> . |
Sample code
List channels
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:
pubnub.RemoveChannelsFromChannelGroup()
.ChannelGroup(string)
.Channels(Array)
.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. |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | 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 . |
ExecuteAsync Type: None | Returns PNResult<PNChannelGroupsRemoveChannelResult> . |
Sample code
Remove channels
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:
pubnub.DeleteChannelGroup()
.ChannelGroup(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
ChannelGroup *Type: string | The channel group to delete. |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | 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 . |
ExecuteAsync Type: None | Returns PNResult<PNChannelGroupsAllChannelsResult> . |
Sample code
Delete channel group
Response
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}