Channel Groups API for PubNub POSIX C++ SDK

Channel Groups allows PubNub developers to bundle thousands of channels into a group that can be identified by name. These Channel Groups can then be subscribed to, receiving data from the many backend-channels the channel group contains.

Learn more about our Channel Groups here.

Channel Group operations

You can't publish to a Channel Group. You can only subscribe to it. To publish within Channel Group, you need to publish to each channel individually.

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

Description

This function adds a channel to a channel group.

Method(s)

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

Addng multiple channels to channel groups

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.

Adding a single channel to a channel group

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

Adding 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"
}

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

Description

This function lists all the channels of the channel group.

Method(s)

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

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

Basic Usage

Listing 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
}

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

Description

This function removes the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Posix 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
}

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

Description

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Posix 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