@midwayjs/rabbitmq 3.0.0-alpha.9 → 3.0.0-beta.12

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/CHANGELOG.md CHANGED
@@ -3,6 +3,120 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
7
+
8
+ **Note:** Version bump only for package @midwayjs/rabbitmq
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
15
+
16
+ **Note:** Version bump only for package @midwayjs/rabbitmq
17
+
18
+
19
+
20
+
21
+
22
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
23
+
24
+
25
+ ### Features
26
+
27
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
34
+
35
+ **Note:** Version bump only for package @midwayjs/rabbitmq
36
+
37
+
38
+
39
+
40
+
41
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
47
+
48
+
49
+
50
+
51
+
52
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
58
+
59
+
60
+
61
+
62
+
63
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
64
+
65
+ **Note:** Version bump only for package @midwayjs/rabbitmq
66
+
67
+
68
+
69
+
70
+
71
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
72
+
73
+ **Note:** Version bump only for package @midwayjs/rabbitmq
74
+
75
+
76
+
77
+
78
+
79
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
80
+
81
+
82
+ ### Features
83
+
84
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
85
+
86
+
87
+
88
+
89
+
90
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
91
+
92
+
93
+ ### Features
94
+
95
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
96
+
97
+
98
+
99
+
100
+
101
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
102
+
103
+ **Note:** Version bump only for package @midwayjs/rabbitmq
104
+
105
+
106
+
107
+
108
+
109
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
110
+
111
+
112
+ ### Bug Fixes
113
+
114
+ * ci、build and type error with rabbitmq ([#1253](https://github.com/midwayjs/midway/issues/1253)) ([80ae991](https://github.com/midwayjs/midway/commit/80ae9919e1c21c9e326b5f186f891d14d43495a5))
115
+
116
+
117
+
118
+
119
+
6
120
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
121
 
8
122
  **Note:** Version bump only for package @midwayjs/rabbitmq
package/README.md CHANGED
@@ -7,7 +7,7 @@ this is a sub package for midway.
7
7
 
8
8
  this module use [amqplib](https://github.com/squaremo/amqp.node)
9
9
 
10
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
10
+ Document: [https://midwayjs.org](https://midwayjs.org)
11
11
 
12
12
  ## License
13
13
 
@@ -0,0 +1,6 @@
1
+ import { MidwayRabbitMQFramework } from './framework';
2
+ export declare class RabbitMQConfiguration {
3
+ framework: MidwayRabbitMQFramework;
4
+ onReady(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RabbitMQConfiguration = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const framework_1 = require("./framework");
15
+ let RabbitMQConfiguration = class RabbitMQConfiguration {
16
+ async onReady() { }
17
+ };
18
+ __decorate([
19
+ (0, decorator_1.Inject)(),
20
+ __metadata("design:type", framework_1.MidwayRabbitMQFramework)
21
+ ], RabbitMQConfiguration.prototype, "framework", void 0);
22
+ RabbitMQConfiguration = __decorate([
23
+ (0, decorator_1.Configuration)({
24
+ namespace: 'rabbitMQ',
25
+ importConfigs: [
26
+ {
27
+ default: {
28
+ rabbitMQServer: {},
29
+ },
30
+ },
31
+ ],
32
+ })
33
+ ], RabbitMQConfiguration);
34
+ exports.RabbitMQConfiguration = RabbitMQConfiguration;
35
+ //# sourceMappingURL=configuration.js.map
@@ -1,8 +1,10 @@
1
- import { BaseFramework, MidwayFrameworkType } from '@midwayjs/core';
1
+ import { MidwayFrameworkType } from '@midwayjs/decorator';
2
+ import { BaseFramework } from '@midwayjs/core';
2
3
  import { IMidwayRabbitMQApplication, IMidwayRabbitMQConfigurationOptions, IMidwayRabbitMQContext } from './interface';
3
4
  export declare class MidwayRabbitMQFramework extends BaseFramework<IMidwayRabbitMQApplication, IMidwayRabbitMQContext, IMidwayRabbitMQConfigurationOptions> {
4
5
  app: IMidwayRabbitMQApplication;
5
6
  consumerHandlerList: any[];
7
+ configure(): any;
6
8
  applicationInitialize(options: any): Promise<void>;
7
9
  run(): Promise<void>;
8
10
  protected beforeStop(): Promise<void>;
package/dist/framework.js CHANGED
@@ -1,14 +1,23 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.MidwayRabbitMQFramework = void 0;
4
- const core_1 = require("@midwayjs/core");
5
10
  const decorator_1 = require("@midwayjs/decorator");
11
+ const core_1 = require("@midwayjs/core");
6
12
  const mq_1 = require("./mq");
7
- class MidwayRabbitMQFramework extends core_1.BaseFramework {
13
+ let MidwayRabbitMQFramework = class MidwayRabbitMQFramework extends core_1.BaseFramework {
8
14
  constructor() {
9
15
  super(...arguments);
10
16
  this.consumerHandlerList = [];
11
17
  }
18
+ configure() {
19
+ return this.configService.getConfiguration('rabbitMQServer');
20
+ }
12
21
  async applicationInitialize(options) {
13
22
  // Create a connection manager
14
23
  this.app = new mq_1.RabbitMQServer({
@@ -26,17 +35,16 @@ class MidwayRabbitMQFramework extends core_1.BaseFramework {
26
35
  await this.app.close();
27
36
  }
28
37
  getFrameworkType() {
29
- return core_1.MidwayFrameworkType.MS_RABBITMQ;
38
+ return decorator_1.MidwayFrameworkType.MS_RABBITMQ;
30
39
  }
31
40
  async loadSubscriber() {
32
41
  // create channel
33
- const subscriberModules = core_1.listModule(decorator_1.MS_CONSUMER_KEY, module => {
34
- const metadata = core_1.getClassMetadata(decorator_1.MS_CONSUMER_KEY, module);
42
+ const subscriberModules = (0, decorator_1.listModule)(decorator_1.MS_CONSUMER_KEY, module => {
43
+ const metadata = (0, decorator_1.getClassMetadata)(decorator_1.MS_CONSUMER_KEY, module);
35
44
  return metadata.type === decorator_1.MSListenerType.RABBITMQ;
36
45
  });
37
46
  for (const module of subscriberModules) {
38
- const providerId = core_1.getProviderId(module);
39
- const data = core_1.listPropertyDataFromClass(decorator_1.MS_CONSUMER_KEY, module);
47
+ const data = (0, decorator_1.listPropertyDataFromClass)(decorator_1.MS_CONSUMER_KEY, module);
40
48
  for (const methodBindListeners of data) {
41
49
  // 循环绑定的方法和监听的配置信息
42
50
  for (const listenerOptions of methodBindListeners) {
@@ -49,8 +57,19 @@ class MidwayRabbitMQFramework extends core_1.BaseFramework {
49
57
  },
50
58
  };
51
59
  this.app.createAnonymousContext(ctx);
52
- const ins = await ctx.requestContext.getAsync(providerId);
53
- await ins[listenerOptions.propertyKey].call(ins, data);
60
+ const ins = await ctx.requestContext.getAsync(module);
61
+ const fn = await this.applyMiddleware(async (ctx) => {
62
+ return await ins[listenerOptions.propertyKey].call(ins, data);
63
+ });
64
+ try {
65
+ const result = await fn(ctx);
66
+ if (result) {
67
+ return channelWrapper.ack(data);
68
+ }
69
+ }
70
+ catch (error) {
71
+ this.logger.error(error);
72
+ }
54
73
  });
55
74
  }
56
75
  }
@@ -59,6 +78,9 @@ class MidwayRabbitMQFramework extends core_1.BaseFramework {
59
78
  getFrameworkName() {
60
79
  return 'midway:rabbitmq';
61
80
  }
62
- }
81
+ };
82
+ MidwayRabbitMQFramework = __decorate([
83
+ (0, decorator_1.Framework)()
84
+ ], MidwayRabbitMQFramework);
63
85
  exports.MidwayRabbitMQFramework = MidwayRabbitMQFramework;
64
86
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { MidwayRabbitMQFramework as Framework } from './framework';
2
2
  export * from './interface';
3
+ export { RabbitMQConfiguration as Configuration } from './configuration';
3
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,8 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Framework = void 0;
13
+ exports.Configuration = exports.Framework = void 0;
14
14
  var framework_1 = require("./framework");
15
15
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayRabbitMQFramework; } });
16
16
  __exportStar(require("./interface"), exports);
17
+ var configuration_1 = require("./configuration");
18
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.RabbitMQConfiguration; } });
17
19
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,10 @@
1
- import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
1
+ import { IConfigurationOptions, IMidwayApplication, IMidwayContext, NextFunction as BaseNextFunction } from '@midwayjs/core';
2
2
  import { ConsumeMessage, Options } from 'amqplib/properties';
3
3
  import { RabbitMQListenerOptions } from '@midwayjs/decorator';
4
- import * as amqp from 'amqplib';
5
- import { Channel } from 'amqplib';
4
+ import type { ConfirmChannel, Channel, Options as AmqpOptions } from 'amqplib';
6
5
  export interface IRabbitMQApplication {
7
6
  connect(...args: any[]): Promise<void>;
8
- createChannel(): Promise<void>;
7
+ createChannel(): Promise<Channel | ConfirmChannel>;
9
8
  createConsumer(listenerOptions: RabbitMQListenerOptions, listenerCallback: (msg: ConsumeMessage | null, channel: Channel, channelWrapper: any) => Promise<void>): Promise<void>;
10
9
  close(): Promise<void>;
11
10
  }
@@ -23,12 +22,18 @@ export interface IMidwayRabbitMQConfigurationOptions extends IConfigurationOptio
23
22
  useConfirmChannel?: boolean;
24
23
  }
25
24
  export declare type IMidwayRabbitMQContext = IMidwayContext<{
26
- channel: amqp.Channel;
25
+ channel: Channel;
27
26
  queueName: string;
28
27
  ack: (data: any) => void;
29
28
  }>;
30
29
  export declare type Application = IMidwayRabbitMQApplication;
31
30
  export interface Context extends IMidwayRabbitMQContext {
32
31
  }
33
- export declare type DefaultConfig = string | amqp.Options.Connect;
32
+ export declare type NextFunction = BaseNextFunction;
33
+ export declare type DefaultConfig = string | AmqpOptions.Connect;
34
+ declare module '@midwayjs/core/dist/interface' {
35
+ interface MidwayConfig {
36
+ rabbitMQServer?: PowerPartial<IMidwayRabbitMQConfigurationOptions>;
37
+ }
38
+ }
34
39
  //# sourceMappingURL=interface.d.ts.map
package/dist/mq.d.ts CHANGED
@@ -6,19 +6,19 @@ import * as amqp from 'amqp-connection-manager';
6
6
  import { IRabbitMQApplication } from './interface';
7
7
  import { ConsumeMessage } from 'amqplib/properties';
8
8
  import { RabbitMQListenerOptions } from '@midwayjs/decorator';
9
- import { Channel } from 'amqplib';
9
+ import type { Channel } from 'amqplib';
10
10
  import { ILogger } from '@midwayjs/logger';
11
11
  import { EventEmitter } from 'events';
12
12
  export declare class RabbitMQServer extends EventEmitter implements IRabbitMQApplication {
13
13
  protected channelManagerSet: Set<Channel>;
14
- protected connection: amqp.Connection;
14
+ protected connection: amqp.AmqpConnectionManager;
15
15
  protected logger: ILogger;
16
16
  protected reconnectTime: any;
17
17
  constructor(options?: any);
18
18
  bindError(): void;
19
19
  createChannel(isConfirmChannel?: boolean): Promise<any>;
20
20
  connect(url: any, socketOptions: any): Promise<void>;
21
- createConsumer(listenerOptions: RabbitMQListenerOptions, listenerCallback: (msg: ConsumeMessage | null, channel: Channel, channelWrapper: any) => Promise<void>): Promise<any>;
21
+ createConsumer(listenerOptions: RabbitMQListenerOptions, listenerCallback: (msg: ConsumeMessage | null, channel: Channel, channelWrapper: any) => Promise<void>): Promise<void>;
22
22
  protected closeConnection(): Promise<void>;
23
23
  close(): Promise<void>;
24
24
  }
package/dist/mq.js CHANGED
@@ -23,10 +23,10 @@ class RabbitMQServer extends events_1.EventEmitter {
23
23
  }
24
24
  createChannel(isConfirmChannel = false) {
25
25
  if (!isConfirmChannel) {
26
- return this.connection.createChannel();
26
+ return this.connection.connection.createChannel();
27
27
  }
28
28
  else {
29
- return this.connection.createConfirmChannel();
29
+ return this.connection.connection.createConfirmChannel();
30
30
  }
31
31
  }
32
32
  async connect(url, socketOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/rabbitmq",
3
- "version": "3.0.0-alpha.9+d5acc750",
3
+ "version": "3.0.0-beta.12",
4
4
  "description": "Midway Framework for rabbitmq",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,14 +23,14 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0-alpha.2",
27
- "@midwayjs/mock": "^3.0.0-alpha.9+d5acc750",
26
+ "@midwayjs/decorator": "^3.0.0-beta.12",
27
+ "@midwayjs/mock": "^3.0.0-beta.12",
28
28
  "@types/amqplib": "*",
29
29
  "fs-extra": "^8.0.1"
30
30
  },
31
31
  "dependencies": {
32
- "@midwayjs/core": "^3.0.0-alpha.9+d5acc750",
33
- "@midwayjs/logger": "^2.11.3",
32
+ "@midwayjs/core": "^3.0.0-beta.12",
33
+ "@midwayjs/logger": "^3.0.0-beta.12",
34
34
  "amqp-connection-manager": "^3.2.2",
35
35
  "amqplib": "*"
36
36
  },
@@ -43,5 +43,8 @@
43
43
  "type": "git",
44
44
  "url": "http://github.com/midwayjs/midway.git"
45
45
  },
46
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
46
+ "engines": {
47
+ "node": ">=12"
48
+ },
49
+ "gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
47
50
  }