Channel Groups API for 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 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 Windows C++ SDK:
Maximum number of channels
You can add up to 200 channels to a channel group per API call.
1add_channel_to_group(std::vector<std::string> const &channel, std::vector<std::string> const &channel_group)
| Parameter | Description | 
|---|---|
| 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_groupto add to thechannel(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.
1add_channel_to_group (std::string const &channel, std::string const &channel_group)
| Parameter | Description | 
|---|---|
| channel*Type: std::string const & | The channel(s)to add to thechannel group. | 
| channel_group*Type: std::string const & | The channel_groupto add thechannel(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  }
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 Windows C++ SDK:
1list_channel_group (std::string const &channel_group)
| Parameter | Description | 
|---|---|
| channel_group*Type: std::string const & | channel_groupto 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  }
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 the channel group.
Method(s)
Removing Channels is accomplished by using the following method(s) in the Windows C++ SDK:
1remove_channel_from_group (std::string const &channel, std::string const &channel_group)
| Parameter | Description | 
|---|---|
| channel_group*Type: std::string const & | Specifies channel_groupto remove the channels from. | 
| channel*Type: std::string const & | The channelto remove from thechannel 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  }
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 removes the channel group.
Method(s)
Deleting Channel Group is accomplished by using the following method(s) in the Windows C++ SDK:
1remove_channel_group (std::string const &channel_group)
| Parameter | Description | 
|---|---|
| channel_group*Type: std::string const & | Specifies channel_groupto 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  }
Rest response from server
1{
2    "status" : 200,
3    "message" : "OK",
4    "service" : "channel-registry",
5    "error" : False
6}