Channel Groups API for Windows C++ SDK (legacy)
New SDK available
The Windows C++ SDK is built on C-Core (legacy), which is still supported. If you are starting a new project, use the new 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. See Enable the features your app calls.
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)
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)
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 linesRest 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. See Enable the features your app calls.
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)
channel_grouprequired#channel_groupto fetch the channels of.