diff --git a/README.md b/README.md index 14b513d..d561475 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,11 @@ async with client.enter_transaction() as transaction: Now, let's subscribe to a queue and listen for messages. -Notice that `listen_to_events()` is not bound to a destination: it will listen to all subscribed destinations. If you want separate subscribtions, create separate clients for that. +Notice that `listen()` is not bound to a destination: it will listen to all subscribed destinations. If you want separate subscribtions, create separate clients for that. ```python async with client.subscribe("DLQ"): - async for event in client.listen_to_events(): + async for event in client.listen(): ... ``` @@ -72,7 +72,7 @@ Before learning how to processing messages from server, we need to understand ho I wanted to avoid them, and came up with an elegant solution: combining async generator and match statement. Here how it looks like: ```python -async for event in client.listen_to_events(): +async for event in client.listen(): match event: case stompman.MessageEvent(body=body): print(f"message: {body!s}") @@ -85,7 +85,7 @@ More complex example, that involves handling all possible events, and auto-ackno ```python async with asyncio.TaskGroup() as task_group: - async for event in client.listen_to_events(): + async for event in client.listen(): match event: case stompman.MessageEvent(body=body): task_group.create_task(handle_message(body)) @@ -132,7 +132,7 @@ stompman takes care of cleaning up resources automatically. When you leave the c - stompman only runs on Python 3.11 and newer. - It implements [STOMP 1.2](https://stomp.github.io/stomp-specification-1.2.html) — the latest version of the protocol. - The client-individual ack mode is used, which means that server requires `ack` or `nack`. In contrast, with `client` ack mode server assumes you don't care about messages that occured before you connected. And, with `auto` ack mode server assumes client successfully received the message. -- Heartbeats are required, and sent automatically on `listen_to_events()` (defaults to 1 second). +- Heartbeats are required, and sent automatically on `listen()` (defaults to 1 second). Also, I want to pointed out that: diff --git a/stompman/client.py b/stompman/client.py index 68ce490..b5c0112 100644 --- a/stompman/client.py +++ b/stompman/client.py @@ -163,7 +163,7 @@ async def subscribe(self, destination: str) -> AsyncGenerator[None, None]: finally: await self._connection.write_frame(UnsubscribeFrame(headers={"id": subscription_id})) - async def listen_to_events(self) -> AsyncIterator[AnyListeningEvent]: + async def listen(self) -> AsyncIterator[AnyListeningEvent]: async for frame in self._connection.read_frames(): match frame: case MessageFrame(): diff --git a/testing/consumer.py b/testing/consumer.py index 8a08eab..6b2a77e 100644 --- a/testing/consumer.py +++ b/testing/consumer.py @@ -8,7 +8,7 @@ async def main() -> None: stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "admin")]) as client, # noqa: S104 client.subscribe("DLQ"), ): - async for event in client.listen_to_events(): + async for event in client.listen(): print(event) # noqa: T201 match event: case stompman.MessageEvent(): diff --git a/tests/integration.py b/tests/integration.py index e6b0dd0..3a1351a 100644 --- a/tests/integration.py +++ b/tests/integration.py @@ -21,7 +21,7 @@ async def consume() -> None: received_messages = [] async with asyncio.timeout(5), consumer.subscribe(destination=destination): - async for event in consumer.listen_to_events(): + async for event in consumer.listen(): match event: case stompman.MessageEvent(body=body): await event.ack() diff --git a/tests/test_client.py b/tests/test_client.py index 00b11a8..736e12b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -302,7 +302,7 @@ async def test_client_listen_to_events_ok() -> None: ) ) async with EnrichedClient(connection_class=connection_class) as client: - events = [event async for event in client.listen_to_events()] + events = [event async for event in client.listen()] assert events == [ MessageEvent(_client=client, _frame=message_frame), @@ -320,7 +320,7 @@ async def test_client_listen_to_events_unreachable(frame: ConnectedFrame | Recei async with EnrichedClient(connection_class=connection_class) as client: with pytest.raises(AssertionError, match="unreachable"): - [event async for event in client.listen_to_events()] + [event async for event in client.listen()] async def test_ack_nack() -> None: @@ -335,7 +335,7 @@ async def test_ack_nack() -> None: connection_class, collected_frames = create_spying_connection(get_read_frames_with_lifespan([[message_frame]])) async with EnrichedClient(connection_class=connection_class) as client: - events = [event async for event in client.listen_to_events()] + events = [event async for event in client.listen()] assert len(events) == 1 event = events[0]