@spinajs/queue-amqp-transport 2.0.482

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +75 -0
  2. package/package.json +68 -0
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # `@spinajs/queue-amqp-transport`
2
+
3
+ AMQP 0-9-1 ( RabbitMQ ) transport for the [`@spinajs/queue`](../queue) module. Lets you publish and
4
+ consume queue messages ( jobs & events ) through an AMQP compatible broker.
5
+
6
+ ## Topology
7
+
8
+ The transport maps the queue `channel` string onto AMQP primitives using a simple, STOMP compatible
9
+ convention:
10
+
11
+ | Channel prefix | AMQP primitive | Semantics |
12
+ | ------------------- | ------------------------- | --------------------------------------------------- |
13
+ | `/topic/...` | `fanout` exchange | Events / pub-sub. Every subscriber gets every message. |
14
+ | anything else | durable work queue | Jobs. A message is delivered to a single consumer. |
15
+
16
+ The topic prefix can be changed per connection via `options.topicPrefix`.
17
+
18
+ - **Transient event subscription** – an exclusive, auto-deleted, server-named queue bound to the fanout exchange.
19
+ - **Durable event subscription** – a stable, durable queue named after `subscriptionId`; messages keep
20
+ accumulating while no consumer is attached and are delivered on re-subscribe.
21
+
22
+ ## Usage
23
+
24
+ Register the transport in your queue configuration:
25
+
26
+ ```js
27
+ import '@spinajs/queue-amqp-transport';
28
+
29
+ const config = {
30
+ queue: {
31
+ default: 'amqp',
32
+ routing: {
33
+ // optional per-message channel routing
34
+ MyEvent: '/topic/my-events',
35
+ MyJob: '/queue/my-jobs',
36
+ },
37
+ connections: [
38
+ {
39
+ name: 'amqp',
40
+ transport: 'AmqpQueueClient',
41
+ host: 'localhost',
42
+ port: 5672,
43
+ login: 'guest',
44
+ password: 'guest',
45
+ defaultTopicChannel: '/topic/default',
46
+ defaultQueueChannel: '/queue/default',
47
+ options: {
48
+ // forwarded to amqplib connect ( heartbeat, vhost, tls ... )
49
+ vhost: '/',
50
+ // topicPrefix: '/topic/',
51
+ },
52
+ },
53
+ ],
54
+ },
55
+ };
56
+ ```
57
+
58
+ `host` may also be a full url ( `amqp://user:pass@host/vhost` ), in which case the discrete
59
+ `port`/`login`/`password` fields are ignored.
60
+
61
+ ## Not yet supported
62
+
63
+ Delayed / scheduled delivery ( `ScheduleDelay`, `ScheduleCron`, `SchedulePeriod`, `ScheduleRepeat` ) is
64
+ not implemented yet — RabbitMQ requires the delayed-message plugin or a TTL + dead-letter topology for
65
+ this. When these fields are set the message is delivered immediately and a warning is logged.
66
+
67
+ ## Tests
68
+
69
+ The test suite expects a running RabbitMQ broker. By default it connects to `localhost:5672`; override
70
+ with `AMQP_HOST` / `AMQP_PORT` environment variables.
71
+
72
+ ```
73
+ docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
74
+ npm test
75
+ ```
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@spinajs/queue-amqp-transport",
3
+ "version": "2.0.482",
4
+ "description": "spinajs queue transport based on AMQP 0-9-1 ( RabbitMQ ). Sends & reads queue messages ( jobs & events ) from an amqp compatible broker.",
5
+ "main": "lib/cjs/index.js",
6
+ "module": "lib/mjs/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./lib/mjs/index.d.ts",
10
+ "import": "./lib/mjs/index.js",
11
+ "require": "./lib/cjs/index.js"
12
+ }
13
+ },
14
+ "type": "module",
15
+ "private": false,
16
+ "publishConfig": { "access": "public" },
17
+ "engines": {
18
+ "node": ">=16.11"
19
+ },
20
+ "scripts": {
21
+ "build": "npm run clean && npm run compile",
22
+ "compile": "tsc -b tsconfig.mjs.json",
23
+ "compile:cjs": "tsc -b tsconfig.cjs.json",
24
+ "rimraf": "./node_modules/rimraf/bin.js",
25
+ "clean": "rimraf lib/ && rimraf tsconfig.tsbuildinfo",
26
+ "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
27
+ "coverage": "nyc npm run test",
28
+ "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
29
+ "format": "prettier --write \"src/**/*.ts\"",
30
+ "lint": "eslint -c .eslintrc.cjs --ext .ts src --fix",
31
+ "preversion": "npm run lint",
32
+ "version": "npm run format && git add -A src"
33
+ },
34
+ "files": [
35
+ "lib/**/*"
36
+ ],
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/spinajs/main.git"
40
+ },
41
+ "keywords": [
42
+ "spinajs",
43
+ "queue",
44
+ "amqp",
45
+ "rabbitmq"
46
+ ],
47
+ "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/main)",
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/spinajs/main/issues"
51
+ },
52
+ "homepage": "https://github.com/spinajs/main#readme",
53
+ "devDependencies": {
54
+ "@types/amqplib": "^0.10.8",
55
+ "@types/luxon": "^3.6.1",
56
+ "@types/node": "^18.11.18"
57
+ },
58
+ "dependencies": {
59
+ "@spinajs/configuration": "^2.0.482",
60
+ "@spinajs/di": "^2.0.482",
61
+ "@spinajs/exceptions": "^2.0.482",
62
+ "@spinajs/log": "^2.0.482",
63
+ "@spinajs/queue": "^2.0.482",
64
+ "amqplib": "^0.10.9",
65
+ "@spinajs/util": "^2.0.482"
66
+ },
67
+ "gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee"
68
+ }