Channel Groups API for PubNub Java 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.
Adding Channels
Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-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 Java V4 SDK:
Note
200 channels
can be added to the channel group
per API call.
this.pubnub.addChannelsToChannelGroup().channelGroup(String).channels(Array)
Parameter Type Required Description channelGroup
String Yes The channelGroup
to add the channels to.channels
Array Yes The channel
to add to the channel group.async
PNCallback Yes PNCallback
of typePNChannelGroupsAddChannelResult
Basic Usage
pubnub.addChannelsToChannelGroup()
.channelGroup("cg1")
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.async(new PNCallback<PNChannelGroupsAddChannelResult>() {
@Override
public void onResponse(PNChannelGroupsAddChannelResult result, PNStatus status) {
}
});
Response
The addChannelsToChannelGroup()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError()
.
{
"service" : "channel-registry",
"status" : 200,
"error" : false,
"message" : "OK"
}
Listing Channels
Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-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 Java V4 SDK:
pubnub.listChannelsForChannelGroup().channelGroup(String)
Parameter Type Required Description channelGroup
String Yes Channel group
to fetch the channels.async
PNCallback Yes PNCallback
of typePNChannelGroupsAllChannelsResult
.
Basic Usage
pubnub.listChannelsForChannelGroup()
.channelGroup("cg1")
.async(new PNCallback<PNChannelGroupsAllChannelsResult>() {
@Override
public void onResponse(PNChannelGroupsAllChannelsResult result, PNStatus status) {
}
});
Returns
The listChannelsForChannelGroup()
operation returns a PNChannelGroupsAllChannelsResult
which contains the following operations:
Method | Type | Description |
---|---|---|
getChannels() | List | List of channels of a channel group . |
Removing Channels
Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-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 Java V4 SDK:
pubnub.removeChannelsFromChannelGroup().channelGroup(String).channels(Array)
Parameter Type Required Description channels
Array Yes The channels
to remove from the channel group.channelGroup
String Yes Specifies channelGroup
to remove the channels from.async
PNCallback Optional PNCallback
of typePNChannelGroupsRemoveChannelResult
.
Basic Usage
pubnub.removeChannelsFromChannelGroup()
.channelGroup("family")
.channels(Arrays.asList("son"))
.async(new PNCallback<PNChannelGroupsRemoveChannelResult>() {
@Override
public void onResponse(PNChannelGroupsRemoveChannelResult result, PNStatus status) {
}
});
Response
The removeChannelsFromChannelGroup()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError()
.
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}
Deleting Channel Group
Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
This function removes the channel group.
Method(s)
Deleting Channel Group
is accomplished by using the following method(s) in the Java V4 SDK:
pubnub.deleteChannelGroup().channelGroup(String)
Parameter Type Required Description channelGroup
String Yes Specifies channelGroup
to remove.async
PNCallback Optional PNCallback
of typePNChannelGroupsDeleteGroupResult
.
Basic Usage
pubnub.deleteChannelGroup()
.channelGroup("family")
.async(new PNCallback<PNChannelGroupsDeleteGroupResult>() {
@Override
public void onResponse(PNChannelGroupsDeleteGroupResult result, PNStatus status) {
}
});
Response
The deleteChannelGroup()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError()
.
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}