Generate Token Pair

Before a client can subscribe to a Data Streams channel, it must obtain a token pair to authenticate the WebSocket connection. The token pair can be generated using either a user ID or a connection name.

You can generate the token pair in two ways as described in this section.

Get Token Pair using User ID

This method generates a token pair by passing the channel ID and the user ID to the getTokenPair() method. The user ID represents the unique identifier of the application user who is subscribing to the channel.

Sample Code Snippet


Package Imports
copy
import com.zc.component.datastream.ZCDatastream;
import com.zc.component.datastream.beans.ZCTokenResponse;
copy
//Create a Data Streams instance
ZCDatastream datastream = ZCDatastream.getInstance();
//Define channel ID and user ID
String channelId = "CHANNEL_ID";
Long userId = 30772000000631094L;
//Generate token pair using user ID
ZCTokenResponse tokenResponse = datastream.getTokenPair(channelId, userId);

Get Token Pair using Connection Name

This method generates a token pair by passing the channel ID and a connection name to the getTokenPair() method. The connection name is a custom identifier for the subscriber connection.

Sample Code Snippet


Package Imports
copy
import com.zc.component.datastream.ZCDatastream;
import com.zc.component.datastream.beans.ZCTokenResponse;
copy
//Create a Data Streams instance
ZCDatastream datastream = ZCDatastream.getInstance();
//Define channel ID and connection name
String channelId = "CHANNEL_ID";
String connectionName = "CONNECTION_NAME";
//Generate token pair using connection name
ZCTokenResponse tokenResponse = datastream.getTokenPair(channelId, connectionName);

Last Updated 2026-07-07 10:52:22 +0530 IST