Channel Groups API for POSIX 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 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)

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

Addng multiple channels to channel groups

1add_channel_to_group(std::vector<std::string> const &channel, std::vector<std::string> const &channel_group)
* required
ParameterDescription
channel *
Type: std::vector <std::string>const &
The channel(s) vector to add to the channel group.
channel_group *
Type: std::vector<std::string>const &
The 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 a single channel to a channel group

1add_channel_to_group (std::string const &channel, std::string const &channel_group)
* required
ParameterDescription
channel *
Type: std::string const &
The channel(s) to add to the channel group.
channel_group *
Type: std::string const &
The 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.

Sample code

Add channels

1const std::string channel_group("family");
1//Sync
2static void add_channel(pubnub::context &pn) {
3 enum pubnub_res res;
4
5 try {
6 res = pn.add_channel_to_group("wife", channel_group).await();
7
8 if (PNR_OK == res) {
9 std::cout << pn.get_channel() << std::endl;
10 } else {
11 std::cout << "Failed with code " << res << std::endl;
12 }
13 } catch (std::exception &ex) {
14 std::cout << "Exception: " << ex.what() << std::endl;
15 }
show all 41 lines

Rest response from server

1{
2 "service" : "channel-registry",
3 "status" : 200,
4 "error" : false,
5 "message" : "OK"
6}

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)

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

1list_channel_group (std::string const &channel_group)
* required
ParameterDescription
channel_group *
Type: std::string const &
channel_group to fetch the channels of.

Sample code

List channels

1const std::string channel_group("family");
1//Sync
2static void list_channels(pubnub::context &pn) {
3 enum pubnub_res res;
4
5 try {
6 res = pn.list_channel_group(channel_group).await();
7
8 if (PNR_OK == res) {
9 std::cout << pn.get_channel() << std::endl;
10 } else {
11 std::cout << "Failed with code " << res << std::endl;
12 }
13 } catch (std::exception &ex) {
14 std::cout << "Exception: " << ex.what() << std::endl;
15 }
show all 41 lines

Rest response from server

1{
2 "status" : 200,
3 "payload" : {
4 "channels" : ["hi"],
5 "group" : "abcd"
6 },
7 "service" : "channel-registry",
8 "error" : False
9}

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)

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

1remove_channel_from_group (std::string const &channel, std::string const &channel_group)
* required
ParameterDescription
channel_group *
Type: std::string const &
Specifies channel_group to remove the channels from.
channel *
Type: std::string const &
The channel to remove from the channel group.

Sample code

Removing channels :

1const std::string channel_group("family");
1//Sync
2static void remove_channel(pubnub::context &pn) {
3 enum pubnub_res res;
4
5 try {
6 res = pn.remove_channel_from_group("son", channel_group).await();
7
8 if (PNR_OK == res) {
9 std::cout << pn.get_channel() << std::endl;
10 } else {
11 std::cout << "Failed with code " << res << std::endl;
12 }
13 } catch (std::exception &ex) {
14 std::cout << "Exception: " << ex.what() << std::endl;
15 }
show all 42 lines

Rest response from server

1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}

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)

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

1remove_channel_group (std::string const &channel_group)
* required
ParameterDescription
channel_group *
Type: std::string const &
Specifies channel_group to remove.

Sample code

Deleting Channel Group :

1const std::string channel_group("family");
1//Sync
2static void remove_group(pubnub::context &pn) {
3 enum pubnub_res res;
4
5 try {
6 res = pn.remove_channel_group(channel_group).await();
7
8 if (PNR_OK == res) {
9 std::cout << pn.get_channel() << std::endl;
10 } else {
11 std::cout << "Failed with code " << res << std::endl;
12 }
13 } catch (std::exception &ex) {
14 std::cout << "Exception: " << ex.what() << std::endl;
15 }
show all 41 lines

Rest response from server

1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}
Last updated on