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
-`session.closed` — `true` when the underlying connection is closed
17
20
-`session.stop()` — cancels reconnection, clears all subscriptions, and closes the connection
18
-
-`AMQPSubscription` — stable handle across reconnections: exposes `channel`, `consumerTag`, and `cancel()`
19
-
-`AMQPGeneratorSubscription` — extends `AMQPSubscription` with `AsyncIterable<AMQPMessage>` support; bridges the iterator across reconnects
21
+
-`AMQPQueue` — reconnect-safe queue handle returned by `session.queue()`, with `publish()`, `subscribe()`, `get()`, `bind()`, `unbind()`, `purge()`, `delete()` ([#186](https://github.com/cloudamqp/amqp-client.js/pull/186))
22
+
-`subscribe(params?, callback?)` accepts `QueueSubscribeParams` — `ConsumeParams` plus an optional `prefetch` that sets channel QoS before each consume, including after reconnect
23
+
- Subscriptions survive reconnection automatically; the async-iterator form continues yielding without any caller changes
24
+
-`AMQPExchange` — reconnect-safe exchange handle returned by `session.exchange()`, with `publish()`, `bind()`, `unbind()`, `delete()` ([#186](https://github.com/cloudamqp/amqp-client.js/pull/186))
25
+
-`AMQPSubscription` — stable consumer handle across reconnections: exposes `channel`, `consumerTag`, and `cancel()`
26
+
-`AMQPGeneratorSubscription` — extends `AMQPSubscription` with `AsyncIterable<AMQPMessage>` support
27
+
-`QueueSubscribeParams` — exported type combining `ConsumeParams` with `prefetch?`
28
+
-`QueuePublishOptions` / `ExchangePublishOptions` — exported types for publish options; both extend `AMQPProperties` with a `confirm?` flag; `ExchangePublishOptions` adds `routingKey?`
20
29
-`ondisconnect` hook on `AMQPBaseClient` (TCP and WebSocket) — fires when the connection drops
21
30
31
+
### Changed
32
+
33
+
-**Breaking:**`AMQPChannel.queue()` removed ([#186](https://github.com/cloudamqp/amqp-client.js/pull/186)). Use `ch.queueDeclare()` with low-level channel methods, or `session.queue()` for the high-level API. See the migration guide below.
34
+
-**Breaking:**`AMQPQueue` is now a session-only class — no longer returned by channel methods, no longer accepts a channel in its constructor. ([#186](https://github.com/cloudamqp/amqp-client.js/pull/186))
35
+
-**Breaking:**`AMQPQueue` is no longer re-exported from `AMQPClient` or `AMQPWebSocketClient`. Import from the main package entry point instead. ([#186](https://github.com/cloudamqp/amqp-client.js/pull/186))
36
+
37
+
### Migration guide
38
+
39
+
The v3 `AMQPQueue` was tied to a single channel. In v4, `AMQPQueue` is a session-level handle that is reconnect-safe.
awaitconsumer.wait() // will block until consumer is canceled or throw an error if server closed channel/connection
42
-
awaitconn.close()
43
-
} catch (e) {
44
-
console.error("ERROR", e)
45
-
e.connection.close()
46
-
setTimeout(run, 1000) // will try to reconnect in 1s
47
-
}
48
-
}
30
+
### High-level API (recommended)
49
31
50
-
run()
51
-
```
32
+
Use `AMQPSession.connect(url, options)` to get a session with automatic reconnection and consumer recovery. The transport is chosen from the URL scheme (`amqp://` / `amqps://` → TCP; `ws://` / `wss://` → WebSocket):
// Subscribe without a callback and use consumer.messages for AsyncGenerator
70
-
constconsumer=awaitq.subscribe({ noAck:false })
71
-
forawait (constmsgofconsumer.messages) {
72
-
console.log(msg.bodyToString())
73
-
awaitmsg.ack()
74
-
break// breaking automatically cancels the consumer
75
-
}
76
-
77
-
awaitconn.close()
78
-
} catch (e) {
79
-
console.error("ERROR", e)
80
-
e.connection.close()
81
-
}
49
+
// Or subscribe with an async iterator
50
+
constiterSub=awaitq.subscribe({ noAck:false })
51
+
forawait (constmsgofiterSub) {
52
+
console.log(msg.bodyString())
53
+
awaitmsg.ack()
82
54
}
83
55
84
-
run()
85
-
```
56
+
// Exchanges work the same way
57
+
constx=awaitsession.topicExchange("events")
58
+
awaitx.publish("user signed up", { routingKey:"events.user.created" })
86
59
87
-
### Automatic Reconnection
60
+
// When done
61
+
awaitsession.stop()
62
+
```
88
63
89
-
Use `AMQPSession.connect(url, options)` to get a session that manages reconnection and consumer recovery. The transport is chosen from the URL scheme (`amqp://` / `amqps://` → TCP socket; `ws://` / `wss://` → WebSocket):
Subscriptions created via `queue.subscribe()` are automatically re-established after reconnection. Include `prefetch` in the subscribe params to set QoS on each connection:
break// breaking automatically cancels the consumer
123
+
}
164
124
165
-
- The session reconnects automatically with exponential backoff
166
-
- After a successful reconnect, consumers registered via `session.subscribe()` are re-established, then `onconnect` fires
167
-
- Messages delivered but not acknowledged before disconnection are redelivered by the broker
168
-
- `onfailed` fires and reconnection stops if `maxRetries` is exceeded
169
-
- For disconnect detection, set `client.ondisconnect` directly
125
+
awaitconn.close()
126
+
```
170
127
171
128
## WebSockets
172
129
173
130
This library can be used in the browser to access an AMQP server over WebSockets. For servers such as RabbitMQ that doesn't support WebSockets natively a [WebSocket TCP relay](https://github.com/cloudamqp/websocket-tcp-relay/) have to be used as a proxy. All CloudAMQP servers has this proxy configured. More information can be found [in this blog post](https://www.cloudamqp.com/blog/cloudamqp-releases-amqp-websockets.html).
174
131
175
132
For web browsers a [compiled](https://www.typescriptlang.org/) and [rolled up](https://www.rollupjs.org/) version is available at <https://github.com/cloudamqp/amqp-client.js/releases>.
176
133
177
-
Using AMQP over WebSockets in a browser:
134
+
`AMQPSession` works with WebSocket URLs out of the box — pass a `ws://` or `wss://` URL and transport is chosen automatically:
135
+
136
+
```javascript
137
+
import { AMQPSession } from "@cloudamqp/amqp-client"
0 commit comments