The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
Help & Documentation>TDMQ for Apache Pulsar

JWT Authentication Configuration

Last updated: 2025-02-06 10:31:26

Overview

TDMQ for Pulsar provides the same JWT authentication method used by native Pulsar, which allows you to access TDMQ for Pulsar resources by configuring the token in the client parameters. For directions on how to configure the relationships between different role tokens and TDMQ for Pulsar resources in the console, see Roles and Permissions.
This document describes how to configure JWT authentication in a TDMQ for Pulsar client, so that you can securely use the client to produce and consume messages. You can also add a token when creating a client.

Authentication Configuration

Java Client

Configure JWT authentication in the Java client:
Access Sample For Cluster On V2.7.1 or Above
Access Sample For Cluster On V2.6.1
PulsarClient client = PulsarClient.builder()
//Access address, copy from the access address in the Cluster Management operation column
.serviceUrl("http://*")
//Replace with the role token, located on the Role Management page
.authentication(AuthenticationFactory.token("eyJh****"))
.build();
PulsarClient client = PulsarClient.builder()
//Access address, fully copy from the access point list in Cluster Management
.serviceUrl("pulsar://*.*.*.*:6000/")
//Replace with the role token, located on the Role Management page
.authentication(AuthenticationFactory.token("eyJh****"))
//Replace the value of custom: with the route ID in the access point list in Cluster Management
.listenerName("custom:1******0/vpc-**/subnet-******")
.build();

Go Client

Configure JWT authentication in the Go client:
Access Sample For Cluster On V2.7.1 or Above
Access Sample For Cluster On V2.6.1
client, err := NewClient(ClientOptions{
//Access address, fully copy from the access point list in Cluster Management
URL: "http://*",
//Replace with the role token, located on the Role Management page
Authentication: NewAuthenticationToken("eyJh****"),
})
client, err := NewClient(ClientOptions{
//Access address, fully copy from the access point list in Cluster Management
URL: "pulsar://*.*.*.*:6000",
//Replace with the role token, located on the Role Management page
Authentication: NewAuthenticationToken("eyJh****"),
//Replace the value of custom: with the route ID in the access point list in Cluster Management
ListenerName: "custom:1300***0/vpc-**/subnet-******",
})