You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -54,61 +60,48 @@ async with client.begin() as transaction:
54
60
55
61
### Listening for Messages
56
62
57
-
Now, let's subscribe to a queue and listen for messages.
58
-
59
-
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.
63
+
Now, let's subscribe to a destination and listen for messages:
Entered `stompman.Client` will block forever waiting for messages if there are any active subscriptions.
68
74
69
-
Before learning how to processing messages from server, we need to understand how other libraries do it. They use callbacks. Damn callbacks in asynchronous programming.
75
+
Sometimes it's useful to avoid that:
70
76
71
-
I wanted to avoid them, and came up with an elegant solution: combining async generator and match statement. Here how it looks like:
By default, subscription have ACK mode "client-individual". If handler successfully processes the message, an `ACK` frame will be sent. If handler raises an exception, a `NACK` frame will be sent. You can catch (and log) exceptions using `on_suppressed_exception` parameter:
72
83
73
84
```python
74
-
asyncfor event in client.listen():
75
-
match event:
76
-
case stompman.MessageEvent(body=body):
77
-
print(f"message: {body!s}")
78
-
await event.ack()
79
-
case stompman.ErrorEvent(message_header=short_description, body=body):
stompman takes care of cleaning up resources automatically. When you leave the context of async context managers `stompman.Client()`, `client.subscribe()`, or `client.begin()`, the necessary frames will be sent to the server.
104
+
stompman takes care of cleaning up resources automatically. When you leave the context of async context managers `stompman.Client()`, or `client.begin()`, the necessary frames will be sent to the server.
112
105
113
106
### Handling Connectivity Issues
114
107
@@ -127,17 +120,12 @@ stompman takes care of cleaning up resources automatically. When you leave the c
127
120
128
121
### ...and caveats
129
122
130
-
- stompman only runs on Python 3.11 and newer.
123
+
- stompman supports Python 3.11 and newer.
131
124
- It implements [STOMP 1.2](https://stomp.github.io/stomp-specification-1.2.html) — the latest version of the protocol.
132
-
- 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.
133
-
- Heartbeats are required, and sent automatically on `listen()` (defaults to 1 second).
125
+
- Heartbeats are required, and sent automatically in background (defaults to 1 second).
134
126
135
127
Also, I want to pointed out that:
136
128
137
129
- Protocol parsing is inspired by [aiostomp](https://github.com/pedrokiefer/aiostomp/blob/3449dcb53f43e5956ccc7662bb5b7d76bc6ef36b/aiostomp/protocol.py) (meaning: consumed by me and refactored from).
138
130
- stompman is tested and used with [Artemis ActiveMQ](https://activemq.apache.org/components/artemis/).
139
-
- Specification says that headers in CONNECT and CONNECTED frames shouldn't be escaped for backwards compatibility. stompman doesn't escape headers in CONNECT frame (outcoming), but does not unescape headers in CONNECTED (outcoming).
140
-
141
-
## No docs
142
-
143
-
I try to keep it simple and easy to understand. May be counter-intuitive for some, but concise high-quality code speaks for itself. There're no comments and little indirection. Read the source if you wish, leave an issue if it's not enough or you want to add or fix something.
131
+
- Specification says that headers in CONNECT and CONNECTED frames shouldn't be escaped for backwards compatibility. stompman escapes headers in CONNECT frame (outcoming), but does not unescape headers in CONNECTED (outcoming).
0 commit comments