教程
管理员设置
如果您在Pulsar实例中启用了身份验证,那么三个管理接口(pulsar-admin CLI工具、REST API和Java admin API)中的每一个都需要进行一些特殊设置。
- 脉冲管理员
- REST API
- Java
如果您已启用身份验证,您需要提供一个认证配置来使用pulsar-admin工具。默认情况下,pulsar-admin工具的配置位于conf/client.conf文件中。以下是可用的参数:
| 名称 | 描述 | 默认值 |
|---|---|---|
| webServiceUrl | 集群的网页URL。 | http://localhost:8080/ |
| brokerServiceUrl | 集群的Pulsar协议URL。 | pulsar://localhost:6650/ |
| authPlugin | 认证插件。 | |
| authParams | 集群的认证参数,以逗号分隔的字符串形式。 | |
| useTls | 是否在集群中强制执行TLS认证。 | false |
| tlsAllowInsecureConnection | 接受来自客户端的不可信TLS证书。 | false |
| tlsTrustCertsFilePath | 受信任的TLS证书文件的路径。 |
你可以在REST API文档中找到由Pulsar代理暴露的REST API的详细信息。
如果你想在Postman中测试REST API,你可以使用这里的REST API JSON文件here。
要使用Java管理API,实例化一个PulsarAdmin对象,并指定一个Pulsar broker的URL和一个PulsarAdminBuilder对象。以下是一个使用localhost的最小示例。
String url = "http://localhost:8080";
// Pass auth-plugin class fully-qualified name if Pulsar-security enabled
String authPluginClassName = "com.org.MyAuthPluginClass";
// Pass auth-param if auth-plugin class requires it
String authParams = "param1=value1";
boolean tlsAllowInsecureConnection = false;
String tlsTrustCertsFilePath = null;
PulsarAdmin admin = PulsarAdmin.builder()
.authentication(authPluginClassName,authParams)
.serviceHttpUrl(url)
.tlsTrustCertsFilePath(tlsTrustCertsFilePath)
.allowTlsInsecureConnection(tlsAllowInsecureConnection)
.build();
如果您使用多个代理,您可以使用像Pulsar服务这样的多主机。例如,
String url = "http://localhost:8080,localhost:8081,localhost:8082";
// Below are the same to the line 2 - line 13 in the code snippet above
// Pass auth-plugin class fully-qualified name if Pulsar-security enabled
String authPluginClassName = "com.org.MyAuthPluginClass";
// Pass auth-param if auth-plugin class requires it
String authParams = "param1=value1";
boolean tlsAllowInsecureConnection = false;
String tlsTrustCertsFilePath = null;
PulsarAdmin admin = PulsarAdmin.builder()
.authentication(authPluginClassName,authParams)
.serviceHttpUrl(url)
.tlsTrustCertsFilePath(tlsTrustCertsFilePath)
.allowTlsInsecureConnection(tlsAllowInsecureConnection)
.build();