Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pulsar producer support configure auth token #96

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public class PulsarConfig {
@Value("${PULSAR_TLS_TRUSTSTORE_PASSWORD:}")
public String tlsTrustStorePassword;

@Value("${PULSAR_AUTH_TOKEN_ENABLE:false}")
public boolean authTokenEnable;

@Value("${PULSAR_AUTH_TOKEN:}")
public String authToken;

@Value("${PULSAR_SECURE_CONNECTION_ENABLE:false}")
public boolean secureConnectionEnable;

@Value("${TRACE_REPORT_SCENE:default}")
public String traceReportScene;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.github.perftool.trace.util.InboundCounter;
import io.github.perftool.trace.util.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.client.api.AuthenticationFactory;
import org.apache.pulsar.client.api.ClientBuilder;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
Expand Down Expand Up @@ -82,14 +83,21 @@ public void init() throws Exception {
.memoryLimit(pulsarConfig.memoryLimitMb, SizeUnit.MEGA_BYTES)
.ioThreads(pulsarConfig.pulsarIoThreads)
.maxConcurrentLookupRequests(pulsarConfig.pulsarMaxConcurrentLookupRequests);
if (pulsarConfig.authTokenEnable) {
clientBuilder.authentication(AuthenticationFactory.token(pulsarConfig.authToken));
}
if (!pulsarConfig.secureConnectionEnable) {
clientBuilder.allowTlsInsecureConnection(true)
.enableTlsHostnameVerification(false);
}
if (pulsarConfig.tlsEnable) {
Map<String, String> map = new HashMap<>();
map.put("keyStoreType", "JKS");
map.put("keyStorePath", pulsarConfig.keyStorePath);
map.put("keyStorePassword", pulsarConfig.keyStorePassword);
pulsarClient = clientBuilder.allowTlsInsecureConnection(true).serviceUrl(String.format("%s://%s:%s",
pulsarClient = clientBuilder.serviceUrl(String.format("%s://%s:%s",
pulsarConfig.protocol, pulsarConfig.host, pulsarConfig.port))
.enableTlsHostnameVerification(false).useKeyStoreTls(true)
.useKeyStoreTls(true)
.tlsTrustStoreType("JKS")
.tlsTrustStorePath(pulsarConfig.tlsTrustStorePath)
.tlsTrustStorePassword(pulsarConfig.tlsTrustStorePassword)
Expand Down
Loading