Skip to content
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
10 changes: 10 additions & 0 deletions pulsar/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,16 @@ async def subscribe(self, topic: Union[str, List[str]],
schema.attach_client(self._client)
return Consumer(await future, schema)

def shutdown(self) -> None:
"""
Shutdown the client and all the associated producers and consumers

Raises
------
PulsarException
"""
self._client.shutdown()

async def get_topic_partitions(self, topic: str) -> List[str]:
"""
Get the list of partitions for a given topic in asynchronous mode.
Expand Down
11 changes: 11 additions & 0 deletions tests/asyncio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ async def test_producer_is_connected(self):
await producer.close()
self.assertFalse(producer.is_connected())

async def test_shutdown_client(self):
producer = await self._client.create_producer("persistent://public/default/partitioned_topic_name_test")
await producer.send(b"hello")
self._client.shutdown()

try:
await producer.send(b"hello")
self.fail("Expected AlreadyClosed exception after client shutdown")
except PulsarException as e:
self.assertEqual(e.error(), pulsar.Result.AlreadyClosed)

async def _prepare_messages(self, producer: Producer) -> List[pulsar.MessageId]:
msg_ids = []
for i in range(5):
Expand Down
Loading