Channel Groups API for PubNub Windows 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.

Add Channels

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 adds a channel to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the Windows C++ SDK:

add_channel_to_group(std::vector<std::string> const &channel, std::vector<std::string> const &channel_group)
ParameterTypeRequiredDescription
channelstd::vector <std::string>const &YesThe channel(s) vector to add to the channel group.
channel_groupstd::vector<std::string>const &YesThe channel_group to add to the channel(s).

A future result (pubnub::futres). If transaction is successful, the response will be available via get_channel() function as one channel, a JSON object.

add_channel_to_group (std::string const &channel, std::string const &channel_group)
ParameterTypeRequiredDescription
channelstd::string const &YesThe channel(s) to add to the channel group.
channel_groupstd::string const &YesThe channel_group to add the channel(s) to.

A future result (pubnub::futres). If transaction is successful, the response will be available via get_channel() function as one channel, a JSON object.

Basic Usage

Add Channels

const std::string channel_group("family");
//Sync
static void add_channel(pubnub::context &pn) {
enum pubnub_res res;

try {
res = pn.add_channel_to_group("wife", channel_group).await();

if (PNR_OK == res) {
std::cout << pn.get_channel() << std::endl;
} else {
std::cout << "Failed with code " << res << std::endl;
}
} catch (std::exception &ex) {
std::cout << "Exception: " << ex.what() << std::endl;
}
show all 41 lines

Rest Response from Server

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

List Channels

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 the channels of the channel group.

Method(s)

Listing Channels is accomplished by using the following method(s) in the Windows C++ SDK:

list_channel_group (std::string const &channel_group)
ParameterTypeRequiredDescription
channel_groupstd::string const &Yeschannel_group to fetch the channels of.

Basic Usage

List Channels

const std::string channel_group("family");
//Sync
static void list_channels(pubnub::context &pn) {
enum pubnub_res res;

try {
res = pn.list_channel_group(channel_group).await();

if (PNR_OK == res) {
std::cout << pn.get_channel() << std::endl;
} else {
std::cout << "Failed with code " << res << std::endl;
}
} catch (std::exception &ex) {
std::cout << "Exception: " << ex.what() << std::endl;
}
show all 41 lines

Rest Response from Server

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

Remove Channels

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 the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Windows C++ SDK:

remove_channel_from_group (std::string const &channel, std::string const &channel_group)
ParameterTypeRequiredDescription
channel_groupstd::string const &YesSpecifies channel_group to remove the channels from.
channelstd::string const &YesThe channel to remove from the channel group.

Basic Usage

Removing channels :

const std::string channel_group("family");
//Sync
static void remove_channel(pubnub::context &pn) {
enum pubnub_res res;

try {
res = pn.remove_channel_from_group("son", channel_group).await();

if (PNR_OK == res) {
std::cout << pn.get_channel() << std::endl;
} else {
std::cout << "Failed with code " << res << std::endl;
}
} catch (std::exception &ex) {
std::cout << "Exception: " << ex.what() << std::endl;
}
show all 42 lines

Rest Response from Server

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

Delete 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 the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Windows C++ SDK:

remove_channel_group (std::string const &channel_group)
ParameterTypeRequiredDescription
channel_groupstd::string const &YesSpecifies channel_group to remove.

Basic Usage

Deleting Channel Group :

const std::string channel_group("family");
//Sync
static void remove_group(pubnub::context &pn) {
enum pubnub_res res;

try {
res = pn.remove_channel_group(channel_group).await();

if (PNR_OK == res) {
std::cout << pn.get_channel() << std::endl;
} else {
std::cout << "Failed with code " << res << std::endl;
}
} catch (std::exception &ex) {
std::cout << "Exception: " << ex.what() << std::endl;
}
show all 41 lines

Rest Response from Server

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