'Apache Pulsar: Error Checking/Getting Partition Metadata while Subscribing

I'm trying to subscribe to an Apache Pulsar topic, and I know for certain the tenant, namespace, and topic all exist because other consumers are able to subscribe to this exact same topic. I've double-checked that my URL and port are correct and that I'm using the correct trust cert. However, I'm getting the exception Error Checking/Getting Partition Metadata while Subscribing, and it won't connect. I'm attempting to connect with SSL over TLS.

My Python code looks like this, but as I mention below, I've used the same approach in Java and in Go, and I get the same result in each language:

import pulsar
client = pulsar.Client('pulsar+ssl://my-pulsar-ms-tls.mydomain.com:6651',
                       tls_trust_certs_file_path='./ca.cert.pem')
consumer = client.subscribe(topic='persistent://my-tenant/ingest/my-topic-name',
                            subscription_name='my-topic-name-source')

The exception I'm getting is detailed below:

2020-06-05 19:55:05.347 INFO  Client:88 | Subscribing on Topic :persistent://my-tenant/ingest/my-topic-name  
2020-06-05 19:55:05.348 INFO  ConnectionPool:72 | Created connection for pulsar+ssl://my-pulsar-ms-tls.mydomain.com:6651  
2020-06-05 19:55:05.540 INFO  ClientConnection:324 | [10.90.3.86:59058 ->
10.20.13.58:6651] Connected to broker  
2020-06-05 19:55:05.582 ERROR ClientConnection:382 | [10.90.3.86:59058 -> 10.20.13.58:6651] Handshake failed: Connection reset by peer  
2020-06-05 19:55:05.582 INFO  ClientConnection:1337 | [10.90.3.86:59058 -> 10.20.13.58:6651] Connection closed  
2020-06-05 19:55:05.582 ERROR ClientImpl:384 | Error Checking/Getting Partition Metadata while Subscribing on persistent://my-tenant/ingest/my-topic-name -- 5  
2020-06-05 19:55:05.582 INFO  ClientConnection:229 | [10.90.3.86:59058 ->
10.20.13.58:6651] Destroyed connection Traceback (most recent call last):   File "/Users/exampleUser/PycharmProjects/ledger/test.py", line 7, in <module>
    subscription_name='my-topic-name-source')   File "/Users/exampleUser/PycharmProjects/ledger/venv/lib/python3.7/site-packages/pulsar/__init__.py", line 604, in subscribe
    c._consumer = self._client.subscribe(topic, subscription_name, conf) Exception: Pulsar error: ConnectError

I got the same exception when using Java, as well as Go, so it's not Python-specific.

What is the issue?



Solution 1:[1]

The problem is that this topic is expecting you to provide an authentication token, but you are not providing one.

All you need to do is modify your pulsar Client constructor to pass an authentication token, like this:

// trust_cert_path could be "ca.cert.pem", if that file is accessible, for example.
client = pulsar.Client(pulsarBrokerURL,
                         authentication=pulsar.AuthenticationToken(pulsarBrokerToken), 
                         tls_trust_certs_file_path=trust_cert_path)

In Go, it will look like this:

client, err := pulsar.NewClient(pulsar.ClientOptions{
    URL:                     pulsarBrokerURL,
    OperationTimeoutSeconds: 5,
    MessageListenerThreads:  runtime.NumCPU(),
    TLSTrustCertsFilePath:   trust_cert_path,
    Authentication:          pulsar.NewAuthenticationToken(pulsarBrokerToken),
})

where the pulsarBrokerToken is just a string.

In Java, it's going to look like this:

// client is already defined
client = PulsarClient.builder()
        .serviceUrl(pulsarBrokerUrl)
        .tlsTrustCertsFilePath(trust_cert_path)
        .authentication(
                AuthenticationFactory.token(pulsarBrokerToken) )
        .build();

If you don't know how to obtain an authentication token (if you're not managing the Pulsar cluster), then please ask whoever is maintaining your Pulsar cluster to provide you with this authentication token.

Update: You can also get this exception if you're using the wrong value for your token (such as an empty string.) If you're using an empty string as a token, you may see this pattern in your logs:

2022-05-05 07:44:34.130 INFO  [0x17606b000] ClientConnection:375 | [192.168.1.232:54880 -> 35.232.116.225:6651] Connected to broker
2022-05-05 07:44:34.257 INFO  [0x17606b000] ClientConnection:1559 | [192.168.1.232:54880 -> 35.232.116.225:6651] Connection closed
2022-05-05 07:44:34.257 ERROR [0x17606b000] ClientImpl:192 | Error Checking/Getting Partition Metadata while creating producer on persistent://my-tenant/ingest/my-topic-name -- ConnectError
2022-05-05 07:44:34.257 ERROR [0x17606b000] ClientConnection:597 | [192.168.1.232:54880 -> 35.232.116.225:6651] Read operation failed: End of file
2022-05-05 07:44:34.258 INFO  [0x17606b000] ClientConnection:263 | [192.168.1.232:54880 -> 35.232.116.225:6651] Destroyed connection

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1