Channel Groups API for PubNub 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
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 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)
Parameter | Type | Required | Description |
---|---|---|---|
channel | std::vector <std::string>const & | Yes | The channel(s) vector to add to the channel group. |
channel_group | std::vector<std::string>const & | Yes | 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
add_channel_to_group (std::string const &channel, std::string const &channel_group)
Parameter | Type | Required | Description |
---|---|---|---|
channel | std::string const & | Yes | The channel(s) to add to the channel group . |
channel_group | std::string const & | Yes | 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.
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 linesRest 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 Posix C++ SDK:
list_channel_group (std::string const &channel_group)
Parameter | Type | Required | Description |
---|---|---|---|
channel_group | std::string const & | Yes | channel_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 linesRest 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 Posix C++ SDK:
remove_channel_from_group (std::string const &channel, std::string const &channel_group)
Parameter | Type | Required | Description |
---|---|---|---|
channel_group | std::string const & | Yes | Specifies channel_group to remove the channels from. |
channel | std::string const & | Yes | The 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 linesRest 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 Posix C++ SDK:
remove_channel_group (std::string const &channel_group)
Parameter | Type | Required | Description |
---|---|---|---|
channel_group | std::string const & | Yes | Specifies 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 linesRest Response from Server
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}