Skip to content

Commit f855696

Browse files
authored
Rename Client.listen_to_events() to Client.listen() (#10)
1 parent 3883c88 commit f855696

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ async with client.enter_transaction() as transaction:
5757

5858
Now, let's subscribe to a queue and listen for messages.
5959

60-
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.
60+
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.
6161

6262
```python
6363
async with client.subscribe("DLQ"):
64-
async for event in client.listen_to_events():
64+
async for event in client.listen():
6565
...
6666
```
6767

@@ -72,7 +72,7 @@ Before learning how to processing messages from server, we need to understand ho
7272
I wanted to avoid them, and came up with an elegant solution: combining async generator and match statement. Here how it looks like:
7373

7474
```python
75-
async for event in client.listen_to_events():
75+
async for event in client.listen():
7676
match event:
7777
case stompman.MessageEvent(body=body):
7878
print(f"message: {body!s}")
@@ -85,7 +85,7 @@ More complex example, that involves handling all possible events, and auto-ackno
8585

8686
```python
8787
async with asyncio.TaskGroup() as task_group:
88-
async for event in client.listen_to_events():
88+
async for event in client.listen():
8989
match event:
9090
case stompman.MessageEvent(body=body):
9191
task_group.create_task(handle_message(body))
@@ -132,7 +132,7 @@ stompman takes care of cleaning up resources automatically. When you leave the c
132132
- stompman only runs on Python 3.11 and newer.
133133
- It implements [STOMP 1.2](https://stomp.github.io/stomp-specification-1.2.html) — the latest version of the protocol.
134134
- 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.
135-
- Heartbeats are required, and sent automatically on `listen_to_events()` (defaults to 1 second).
135+
- Heartbeats are required, and sent automatically on `listen()` (defaults to 1 second).
136136

137137
Also, I want to pointed out that:
138138

stompman/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def subscribe(self, destination: str) -> AsyncGenerator[None, None]:
163163
finally:
164164
await self._connection.write_frame(UnsubscribeFrame(headers={"id": subscription_id}))
165165

166-
async def listen_to_events(self) -> AsyncIterator[AnyListeningEvent]:
166+
async def listen(self) -> AsyncIterator[AnyListeningEvent]:
167167
async for frame in self._connection.read_frames():
168168
match frame:
169169
case MessageFrame():

testing/consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def main() -> None:
88
stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "admin")]) as client, # noqa: S104
99
client.subscribe("DLQ"),
1010
):
11-
async for event in client.listen_to_events():
11+
async for event in client.listen():
1212
print(event) # noqa: T201
1313
match event:
1414
case stompman.MessageEvent():

tests/integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def consume() -> None:
2121
received_messages = []
2222

2323
async with asyncio.timeout(5), consumer.subscribe(destination=destination):
24-
async for event in consumer.listen_to_events():
24+
async for event in consumer.listen():
2525
match event:
2626
case stompman.MessageEvent(body=body):
2727
await event.ack()

tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async def test_client_listen_to_events_ok() -> None:
302302
)
303303
)
304304
async with EnrichedClient(connection_class=connection_class) as client:
305-
events = [event async for event in client.listen_to_events()]
305+
events = [event async for event in client.listen()]
306306

307307
assert events == [
308308
MessageEvent(_client=client, _frame=message_frame),
@@ -320,7 +320,7 @@ async def test_client_listen_to_events_unreachable(frame: ConnectedFrame | Recei
320320

321321
async with EnrichedClient(connection_class=connection_class) as client:
322322
with pytest.raises(AssertionError, match="unreachable"):
323-
[event async for event in client.listen_to_events()]
323+
[event async for event in client.listen()]
324324

325325

326326
async def test_ack_nack() -> None:
@@ -335,7 +335,7 @@ async def test_ack_nack() -> None:
335335

336336
connection_class, collected_frames = create_spying_connection(get_read_frames_with_lifespan([[message_frame]]))
337337
async with EnrichedClient(connection_class=connection_class) as client:
338-
events = [event async for event in client.listen_to_events()]
338+
events = [event async for event in client.listen()]
339339

340340
assert len(events) == 1
341341
event = events[0]

0 commit comments

Comments
 (0)