@rxdi/graphql-pubsub 0.7.225 → 0.7.227
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.
- package/README.md +94 -49
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/subscribe-amqp/index.d.ts +1 -0
- package/dist/decorators/subscribe-amqp/index.js +17 -0
- package/dist/decorators/subscribe-amqp/subscribe.decorator.d.ts +5 -0
- package/dist/decorators/subscribe-amqp/subscribe.decorator.js +32 -0
- package/dist/services/pub-sub.service.d.ts +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -19,12 +19,12 @@ $ npm install @rxdi/graphql-pubsub --save
|
|
|
19
19
|
##### Import inside AppModule or CoreModule
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { Module } from
|
|
23
|
-
import { HapiModule } from
|
|
24
|
-
import { GraphQLPubSubModule } from
|
|
22
|
+
import { Module } from '@rxdi/core';
|
|
23
|
+
import { HapiModule } from '@rxdi/hapi';
|
|
24
|
+
import { GraphQLPubSubModule } from '@rxdi/graphql-pubsub';
|
|
25
25
|
|
|
26
26
|
@Module({
|
|
27
|
-
|
|
27
|
+
imports: [GraphQLPubSubModule.forRoot()],
|
|
28
28
|
})
|
|
29
29
|
export class CoreModule {}
|
|
30
30
|
```
|
|
@@ -32,27 +32,27 @@ export class CoreModule {}
|
|
|
32
32
|
Correct usage with `@rxdi/graphql`
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
|
-
import { Module } from
|
|
36
|
-
import { HapiModule } from
|
|
37
|
-
import { GraphQLModule } from
|
|
38
|
-
import { GraphQLPubSubModule } from
|
|
35
|
+
import { Module } from '@rxdi/core';
|
|
36
|
+
import { HapiModule } from '@rxdi/hapi';
|
|
37
|
+
import { GraphQLModule } from '@rxdi/graphql';
|
|
38
|
+
import { GraphQLPubSubModule } from '@rxdi/graphql-pubsub';
|
|
39
39
|
|
|
40
40
|
@Module({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
imports: [
|
|
42
|
+
HapiModule.forRoot({
|
|
43
|
+
hapi: {
|
|
44
|
+
port: 9000,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
GraphQLModule.forRoot({
|
|
48
|
+
path: '/graphql',
|
|
49
|
+
writeEffects: false,
|
|
50
|
+
graphqlOptions: {
|
|
51
|
+
schema: null,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
GraphQLPubSubModule.forRoot(),
|
|
55
|
+
],
|
|
56
56
|
})
|
|
57
57
|
export class CoreModule {}
|
|
58
58
|
```
|
|
@@ -61,34 +61,79 @@ Options for pubsub server can be defined like so
|
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
GraphQLPubSubModule.forRoot({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
64
|
+
activateRabbitMQ: false,
|
|
65
|
+
host: '182.10.0.5',
|
|
66
|
+
port: 5672,
|
|
67
|
+
// authentication: AuthService as never,
|
|
68
|
+
subscriptionServerOptions: {
|
|
69
|
+
perMessageDeflate: {
|
|
70
|
+
zlibDeflateOptions: {
|
|
71
|
+
// See zlib defaults.
|
|
72
|
+
chunkSize: 1024,
|
|
73
|
+
memLevel: 7,
|
|
74
|
+
level: 3,
|
|
75
|
+
},
|
|
76
|
+
zlibInflateOptions: {
|
|
77
|
+
chunkSize: 10 * 1024,
|
|
78
|
+
},
|
|
79
|
+
// Other options settable:
|
|
80
|
+
clientNoContextTakeover: true, // Defaults to negotiated value.
|
|
81
|
+
serverNoContextTakeover: true, // Defaults to negotiated value.
|
|
82
|
+
serverMaxWindowBits: 10, // Defaults to negotiated value.
|
|
83
|
+
// Below options specified as default values.
|
|
84
|
+
concurrencyLimit: 10, // Limits zlib concurrency for perf.
|
|
85
|
+
threshold: 1024, // Size (in bytes) below which messages
|
|
86
|
+
// should not be compressed.
|
|
88
87
|
},
|
|
88
|
+
},
|
|
89
89
|
});
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
##### Complex example of dead letter queue
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { AMQPSubscribe, PubSubService } from '@rxdi/graphql-pubsub';
|
|
96
|
+
import { Injectable } from '@rxdi/core';
|
|
97
|
+
|
|
98
|
+
@Injectable()
|
|
99
|
+
class MyClass {
|
|
100
|
+
constructor(private pubsub: PubSubService) {}
|
|
101
|
+
OnInit() {
|
|
102
|
+
setInterval(() => {
|
|
103
|
+
this.pubsub.publish('my-queue', { test: 'aaa' });
|
|
104
|
+
console.log('message-send-to-queue');
|
|
105
|
+
}, 2000);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@AMQPSubscribe({
|
|
109
|
+
queue: 'my-queue',
|
|
110
|
+
config: {
|
|
111
|
+
prefetch: 1,
|
|
112
|
+
globalPrefetch: true,
|
|
113
|
+
strictName: true,
|
|
114
|
+
arguments: {
|
|
115
|
+
'x-dead-letter-exchange': 'my-queue.DLQ',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
first(message) {
|
|
120
|
+
console.log('Message received from queue', message);
|
|
121
|
+
throw new Error('AAA');
|
|
122
|
+
// We throw an error here so we can simulate error job which will automatically send message to dead letter queue
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@AMQPSubscribe({
|
|
126
|
+
queue: 'my-queue-dlq',
|
|
127
|
+
config: {
|
|
128
|
+
prefetch: 1,
|
|
129
|
+
globalPrefetch: true,
|
|
130
|
+
strictName: true,
|
|
131
|
+
dlx: 'my-queue.DLQ',
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
second(message) {
|
|
135
|
+
console.log('Dead Letter Queue', message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
93
139
|
|
|
94
|
-
Enjoy ! :)
|
package/dist/decorators/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./subscribe"), exports);
|
|
18
18
|
__exportStar(require("./subscription"), exports);
|
|
19
|
+
__exportStar(require("./subscribe-amqp"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './subscribe.decorator';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./subscribe.decorator"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AMQPSubscribe = void 0;
|
|
13
|
+
const core_1 = require("@rxdi/core");
|
|
14
|
+
const pub_sub_service_1 = require("../../services/pub-sub.service");
|
|
15
|
+
const AMQPSubscribe = ({ queue, config, }) => (target, memberName) => {
|
|
16
|
+
const OnInit = target.OnInit ||
|
|
17
|
+
function () {
|
|
18
|
+
/* */
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(target, 'OnInit', {
|
|
21
|
+
value: function (...args) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const amqpService = core_1.Container.get(pub_sub_service_1.PubSubService);
|
|
24
|
+
yield amqpService.sub.subscribe(queue, (msg) => target[memberName].call(this, msg), config);
|
|
25
|
+
return OnInit.apply(this, args);
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.AMQPSubscribe = AMQPSubscribe;
|
|
@@ -6,7 +6,7 @@ export declare let pubsub: PubSub | AmqpPubSub;
|
|
|
6
6
|
export declare class PubSubService {
|
|
7
7
|
private config;
|
|
8
8
|
private logger;
|
|
9
|
-
sub: AmqpPubSub
|
|
9
|
+
sub: AmqpPubSub & PubSub;
|
|
10
10
|
constructor(config: GRAPHQL_PUB_SUB_DI_CONFIG, logger: PubSubLogger);
|
|
11
11
|
asyncIterator<T>(event: any, options?: any): AsyncIterator<T>;
|
|
12
12
|
asyncIterableIterator<T>(event: any, options?: any): AsyncIterator<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdi/graphql-pubsub",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.227",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rxdi/graphql-pubsub"
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/rxdi/graphql-pubsub#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@rxdi/graphql-rabbitmq-subscriptions": "^0.7.
|
|
33
|
+
"@rxdi/graphql-rabbitmq-subscriptions": "^0.7.226",
|
|
34
|
+
"@rxdi/rabbitmq-pubsub": "^0.7.226",
|
|
34
35
|
"subscriptions-transport-ws": "^0.9.19"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@rxdi/core": "^0.7.
|
|
38
|
-
"@rxdi/graphql": "^0.7.
|
|
39
|
-
"@rxdi/hapi": "^0.7.
|
|
38
|
+
"@rxdi/core": "^0.7.226",
|
|
39
|
+
"@rxdi/graphql": "^0.7.226",
|
|
40
|
+
"@rxdi/hapi": "^0.7.226",
|
|
40
41
|
"@types/graphql": "^14.5.0",
|
|
41
42
|
"@types/hapi": "^18.0.4",
|
|
42
43
|
"@types/jest": "^24.0.22",
|