Channel Groups API for C-Core 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.

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-Core SDK:

enum pubnub_res pubnub_add_channel_to_group (
pubnub_t *p,
char const *channel,
char const *channel_group
)
* required
ParameterDescription
p *
Type: pubnub_t*
Pointer to PubNub client context.
channel *
Type: char const*
The channel to add
channel_group *
Type: char const*
The channel group to add to

Sample code

Add channels

static char *channel_group = "family";
enum pubnub_res res;
res = pubnub_add_channel_to_group(pn, "wife", channel_group);
return check_response(pn, res);

Rest response from server

{
"service" : "channel-registry",
"status" : 200,
"error" : false,
"message" : "OK"
}

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-Core SDK:

enum pubnub_res pubnub_list_channel_group (
pubnub_t *p,
char const *channel_group
)
* required
ParameterDescription
p *
Type: pubnub_t*
Pointer to PubNub client context.
channel_group *
Type: char const*
The channel group for which to list channels.

Sample code

List channels

static char *channel_group = "family";
pubnub_list_channel_group(ctx, channel_group);
pbresult = pubnub_await(ctx);
if (PNR_OK == pbresult) {
char const *json_response = pubnub_get(ctx);
}

Rest response from server

{
"status" : 200,
"payload" : {
"channels" : ["hi"],
"group" : "abcd"
},
"service" : "channel-registry",
"error" : False
}

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-Core SDK:

enum pubnub_res pubnub_remove_channel_from_group (
pubnub_t *p,
char const *channel,
char const *channel_group
)
* required
ParameterDescription
p *
Type: pubnub_t*
Pointer to the PubNub client context.
channel *
Type: char const*
The channel to remove.
channel_group *
Type: char const*
The channel group from which to remove the channel.

Sample code

Removing channels :

static char *channel_group = "family";
enum pubnub_res res;
res = pubnub_remove_channel_from_group(pn, "son", channel_group);
return check_response(pn, res);

Rest response from server

{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}

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-Core SDK:

enum pubnub_res pubnub_remove_channel_group (
pubnub_t *p,
char const *channel_group
)
* required
ParameterDescription
p *
Type: pubnub_t*
Pointer to PubNub client context.
channel_group *
Type: char const*
The channel group to delete.

Sample code

Deleting Channel Group :

static char *channel_group = "family";
enum pubnub_res res;
res = pubnub_remove_channel_group(pn, channel_group);
return check_response(pn, res);

Rest response from server

{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}
Last updated on