You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/06/24 01:10:38 UTC
[GitHub] [pulsar] alphara edited a comment on issue #7324: Python pulsar-client reader causes unidentifiable C++ exception
alphara edited a comment on issue #7324:
URL: https://github.com/apache/pulsar/issues/7324#issuecomment-648523128
The exception arises after the reader gets connected. Try to launch Pulsar before you launch the sample code.
The pulsar docs says [here](https://pulsar.apache.org/docs/en/next/client-libraries-python/):
> Pulsar Python client library is a wrapper over the existing C++ client library and exposes all of the same features. You can find the code in the python subdirectory of the C++ client code.
Is this info obsolete?
This is a simple example that I use
```python
from pulsar import Client, MessageId
client = Client(service_url='pulsar://localhost:6650',
authentication=None)
topic = 'my-topic'
msg_id = MessageId.earliest
reader = client.create_reader(topic, msg_id)
while True:
msg = reader.read_next()
print("Received message '{}' id='{}'".format(msg.data(), msg.message_id()))
```
I found that the example above works on my machine.
I have a bigger application that uses [asyncio](https://docs.python.org/3.7/library/asyncio.html) library. The `reader.read_next()` is executed inside the `run_in_executor()` method.
```python
# ...
async def _tryToSubscribe(self, topic, queue, callback, pulsarStartMessage):
def sync_subscribe():
startMessageId = MessageId.earliest
reader = self.pulsar.create_reader(topic, startMessageId) # <- exception occurs here
await self.loop.run_in_executor(self.executor, sync_subscribe)
# ...
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org