rabbitmq-sdk 0.0.1-security → 1.2.0

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.

Potentially problematic release.


This version of rabbitmq-sdk might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.kiro/specs/sdk-rabbitmq/design.md +369 -0
  3. package/.kiro/specs/sdk-rabbitmq/requirements.md +97 -0
  4. package/.kiro/specs/sdk-rabbitmq/tasks.md +248 -0
  5. package/README.md +273 -5
  6. package/bun.lock +790 -0
  7. package/config.example.json +13 -0
  8. package/dist/components/ConfigurationManager.d.ts +35 -0
  9. package/dist/components/ConfigurationManager.d.ts.map +1 -0
  10. package/dist/components/ConfigurationManager.js +118 -0
  11. package/dist/components/ConfigurationManager.js.map +1 -0
  12. package/dist/components/ConnectionManager.d.ts +93 -0
  13. package/dist/components/ConnectionManager.d.ts.map +1 -0
  14. package/dist/components/ConnectionManager.js +349 -0
  15. package/dist/components/ConnectionManager.js.map +1 -0
  16. package/dist/components/DLQHandler.d.ts +81 -0
  17. package/dist/components/DLQHandler.d.ts.map +1 -0
  18. package/dist/components/DLQHandler.js +228 -0
  19. package/dist/components/DLQHandler.js.map +1 -0
  20. package/dist/components/Logger.d.ts +77 -0
  21. package/dist/components/Logger.d.ts.map +1 -0
  22. package/dist/components/Logger.js +193 -0
  23. package/dist/components/Logger.js.map +1 -0
  24. package/dist/components/MessagePublisher.d.ts +49 -0
  25. package/dist/components/MessagePublisher.d.ts.map +1 -0
  26. package/dist/components/MessagePublisher.js +158 -0
  27. package/dist/components/MessagePublisher.js.map +1 -0
  28. package/dist/components/MessageSubscriber.d.ts +108 -0
  29. package/dist/components/MessageSubscriber.d.ts.map +1 -0
  30. package/dist/components/MessageSubscriber.js +503 -0
  31. package/dist/components/MessageSubscriber.js.map +1 -0
  32. package/dist/components/ResourceCreator.d.ts +89 -0
  33. package/dist/components/ResourceCreator.d.ts.map +1 -0
  34. package/dist/components/ResourceCreator.js +352 -0
  35. package/dist/components/ResourceCreator.js.map +1 -0
  36. package/dist/components/SdkRabbitmq.d.ts +103 -0
  37. package/dist/components/SdkRabbitmq.d.ts.map +1 -0
  38. package/dist/components/SdkRabbitmq.js +364 -0
  39. package/dist/components/SdkRabbitmq.js.map +1 -0
  40. package/dist/components/index.d.ts +9 -0
  41. package/dist/components/index.d.ts.map +1 -0
  42. package/dist/components/index.js +20 -0
  43. package/dist/components/index.js.map +1 -0
  44. package/dist/index.d.ts +5 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +27 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/interfaces/IConfiguration.d.ts +35 -0
  49. package/dist/interfaces/IConfiguration.d.ts.map +1 -0
  50. package/dist/interfaces/IConfiguration.js +3 -0
  51. package/dist/interfaces/IConfiguration.js.map +1 -0
  52. package/dist/interfaces/IConnection.d.ts +21 -0
  53. package/dist/interfaces/IConnection.d.ts.map +1 -0
  54. package/dist/interfaces/IConnection.js +3 -0
  55. package/dist/interfaces/IConnection.js.map +1 -0
  56. package/dist/interfaces/IDLQ.d.ts +12 -0
  57. package/dist/interfaces/IDLQ.d.ts.map +1 -0
  58. package/dist/interfaces/IDLQ.js +3 -0
  59. package/dist/interfaces/IDLQ.js.map +1 -0
  60. package/dist/interfaces/IErrors.d.ts +33 -0
  61. package/dist/interfaces/IErrors.d.ts.map +1 -0
  62. package/dist/interfaces/IErrors.js +56 -0
  63. package/dist/interfaces/IErrors.js.map +1 -0
  64. package/dist/interfaces/ILogger.d.ts +14 -0
  65. package/dist/interfaces/ILogger.d.ts.map +1 -0
  66. package/dist/interfaces/ILogger.js +3 -0
  67. package/dist/interfaces/ILogger.js.map +1 -0
  68. package/dist/interfaces/IMessage.d.ts +52 -0
  69. package/dist/interfaces/IMessage.d.ts.map +1 -0
  70. package/dist/interfaces/IMessage.js +3 -0
  71. package/dist/interfaces/IMessage.js.map +1 -0
  72. package/dist/interfaces/IResource.d.ts +31 -0
  73. package/dist/interfaces/IResource.d.ts.map +1 -0
  74. package/dist/interfaces/IResource.js +3 -0
  75. package/dist/interfaces/IResource.js.map +1 -0
  76. package/dist/interfaces/ISdkRabbitmq.d.ts +17 -0
  77. package/dist/interfaces/ISdkRabbitmq.d.ts.map +1 -0
  78. package/dist/interfaces/ISdkRabbitmq.js +3 -0
  79. package/dist/interfaces/ISdkRabbitmq.js.map +1 -0
  80. package/dist/interfaces/index.d.ts +9 -0
  81. package/dist/interfaces/index.d.ts.map +1 -0
  82. package/dist/interfaces/index.js +33 -0
  83. package/dist/interfaces/index.js.map +1 -0
  84. package/dist/utils/configSchema.d.ts +8 -0
  85. package/dist/utils/configSchema.d.ts.map +1 -0
  86. package/dist/utils/configSchema.js +51 -0
  87. package/dist/utils/configSchema.js.map +1 -0
  88. package/docker-compose.yml +24 -0
  89. package/example.ts +65 -0
  90. package/examples/README-dynamic-routing.md +155 -0
  91. package/examples/bind-unbind-example.js +56 -0
  92. package/examples/test-chatbot-exchange.ts +83 -0
  93. package/examples/test-dynamic-routing-flow.js +299 -0
  94. package/examples/test-dynamic-routing-flow.ts +355 -0
  95. package/examples/test-no-disconnect.ts +0 -0
  96. package/examples/test-raw-rabbitmq.js +68 -0
  97. package/examples/test-same-channel.ts +81 -0
  98. package/examples/test-schedule-flow.ts +713 -0
  99. package/examples/test-simple-greeting.ts +66 -0
  100. package/examples/test-simple-schedule.ts +76 -0
  101. package/examples/test-wildcard.ts +364 -0
  102. package/jest.config.js +17 -0
  103. package/package.json +42 -4
  104. package/preinstall.js +1 -0
  105. package/prompts/test-dynamic-routing-flow.md +46 -0
  106. package/run.js +4 -0
  107. package/scripts/run-dynamic-routing-test.ts +31 -0
  108. package/src/.gitkeep +1 -0
  109. package/src/components/.gitkeep +1 -0
  110. package/src/components/ConfigurationManager.ts +104 -0
  111. package/src/components/ConnectionManager.ts +357 -0
  112. package/src/components/DLQHandler.ts +271 -0
  113. package/src/components/Logger.ts +224 -0
  114. package/src/components/MessagePublisher.ts +180 -0
  115. package/src/components/MessageSubscriber.ts +597 -0
  116. package/src/components/ResourceCreator.ts +411 -0
  117. package/src/components/SdkRabbitmq.ts +443 -0
  118. package/src/components/__tests__/ConfigurationManager.test.ts +357 -0
  119. package/src/components/__tests__/ConnectionManager.test.ts +387 -0
  120. package/src/components/__tests__/DLQHandler.test.ts +399 -0
  121. package/src/components/__tests__/Logger.test.ts +354 -0
  122. package/src/components/__tests__/MessagePublisher.test.ts +337 -0
  123. package/src/components/__tests__/MessageSubscriber.test.ts +542 -0
  124. package/src/components/__tests__/ResourceCreator.test.ts +465 -0
  125. package/src/components/__tests__/SdkRabbitmq.integration.test.ts +433 -0
  126. package/src/components/index.ts +8 -0
  127. package/src/index.ts +11 -0
  128. package/src/interfaces/.gitkeep +1 -0
  129. package/src/interfaces/IConfiguration.ts +38 -0
  130. package/src/interfaces/IConnection.ts +27 -0
  131. package/src/interfaces/IDLQ.ts +13 -0
  132. package/src/interfaces/IErrors.ts +53 -0
  133. package/src/interfaces/ILogger.ts +16 -0
  134. package/src/interfaces/IMessage.ts +65 -0
  135. package/src/interfaces/IResource.ts +35 -0
  136. package/src/interfaces/ISdkRabbitmq.ts +26 -0
  137. package/src/interfaces/index.ts +23 -0
  138. package/src/utils/.gitkeep +1 -0
  139. package/src/utils/configSchema.ts +58 -0
  140. package/tsconfig.json +34 -0
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionError = exports.PublishError = exports.ConnectionError = exports.ConfigurationError = exports.SdkRabbitmqError = void 0;
4
+ /**
5
+ * Base SDK RabbitMQ error class
6
+ */
7
+ class SdkRabbitmqError extends Error {
8
+ constructor(message, code, context) {
9
+ super(message);
10
+ this.code = code;
11
+ this.context = context;
12
+ this.name = 'SdkRabbitmqError';
13
+ }
14
+ }
15
+ exports.SdkRabbitmqError = SdkRabbitmqError;
16
+ /**
17
+ * Configuration related errors
18
+ */
19
+ class ConfigurationError extends SdkRabbitmqError {
20
+ constructor(message, context) {
21
+ super(message, 'CONFIGURATION_ERROR', context);
22
+ this.name = 'ConfigurationError';
23
+ }
24
+ }
25
+ exports.ConfigurationError = ConfigurationError;
26
+ /**
27
+ * Connection related errors
28
+ */
29
+ class ConnectionError extends SdkRabbitmqError {
30
+ constructor(message, context) {
31
+ super(message, 'CONNECTION_ERROR', context);
32
+ this.name = 'ConnectionError';
33
+ }
34
+ }
35
+ exports.ConnectionError = ConnectionError;
36
+ /**
37
+ * Message publishing errors
38
+ */
39
+ class PublishError extends SdkRabbitmqError {
40
+ constructor(message, context) {
41
+ super(message, 'PUBLISH_ERROR', context);
42
+ this.name = 'PublishError';
43
+ }
44
+ }
45
+ exports.PublishError = PublishError;
46
+ /**
47
+ * Message subscription errors
48
+ */
49
+ class SubscriptionError extends SdkRabbitmqError {
50
+ constructor(message, context) {
51
+ super(message, 'SUBSCRIPTION_ERROR', context);
52
+ this.name = 'SubscriptionError';
53
+ }
54
+ }
55
+ exports.SubscriptionError = SubscriptionError;
56
+ //# sourceMappingURL=IErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IErrors.js","sourceRoot":"","sources":["../../src/interfaces/IErrors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YACE,OAAe,EACR,IAAY,EACZ,OAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAM;QAGpB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AATD,4CASC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,gBAAgB;IACtD,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,gBAAgB;IACnD,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,gBAAgB;IAChD,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED;;GAEG;AACH,MAAa,iBAAkB,SAAQ,gBAAgB;IACrD,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AALD,8CAKC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Logger interface for structured logging
3
+ */
4
+ export interface ILogger {
5
+ /** Log error message with optional context */
6
+ error(message: string, context?: any): void;
7
+ /** Log warning message with optional context */
8
+ warn(message: string, context?: any): void;
9
+ /** Log info message with optional context */
10
+ info(message: string, context?: any): void;
11
+ /** Log debug message with optional context */
12
+ debug(message: string, context?: any): void;
13
+ }
14
+ //# sourceMappingURL=ILogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ILogger.d.ts","sourceRoot":"","sources":["../../src/interfaces/ILogger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,8CAA8C;IAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAE5C,gDAAgD;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAE3C,6CAA6C;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAE3C,8CAA8C;IAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ILogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ILogger.js","sourceRoot":"","sources":["../../src/interfaces/ILogger.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Message callback type for handling received messages
3
+ */
4
+ export type MessageCallback = (message: any, ack: () => void, nack: () => void) => void;
5
+ /**
6
+ * Message publisher interface
7
+ */
8
+ export interface IMessagePublisher {
9
+ /** Publish a message to an exchange */
10
+ publish(exchange: string, routingKey: string, payload: any): Promise<boolean>;
11
+ }
12
+ /**
13
+ * Message subscriber interface
14
+ */
15
+ export interface IMessageSubscriber {
16
+ /** Subscribe to messages from a queue */
17
+ subscribe(exchange: string, queue: string, routingKey: string, callback: MessageCallback): Promise<void>;
18
+ /** Unsubscribe from a queue */
19
+ unsubscribe(queue: string): Promise<void>;
20
+ }
21
+ /**
22
+ * RabbitMQ message structure
23
+ */
24
+ export interface RabbitMQMessage {
25
+ content: Buffer;
26
+ fields: {
27
+ deliveryTag: number;
28
+ redelivered: boolean;
29
+ exchange: string;
30
+ routingKey: string;
31
+ };
32
+ properties: {
33
+ contentType: string;
34
+ timestamp: number;
35
+ messageId: string;
36
+ headers: Record<string, any>;
37
+ };
38
+ }
39
+ /**
40
+ * Processed message structure
41
+ */
42
+ export interface ProcessedMessage {
43
+ payload: any;
44
+ metadata: {
45
+ exchange: string;
46
+ routingKey: string;
47
+ timestamp: number;
48
+ deliveryTag: number;
49
+ redelivered: boolean;
50
+ };
51
+ }
52
+ //# sourceMappingURL=IMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IMessage.d.ts","sourceRoot":"","sources":["../../src/interfaces/IMessage.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,MAAM,IAAI,EACf,IAAI,EAAE,MAAM,IAAI,KACb,IAAI,CAAC;AAEV;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/E;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,+BAA+B;IAC/B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,UAAU,EAAE;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC;CACH"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IMessage.js","sourceRoot":"","sources":["../../src/interfaces/IMessage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Queue options for resource creation
3
+ */
4
+ export interface QueueOptions {
5
+ durable?: boolean;
6
+ exclusive?: boolean;
7
+ autoDelete?: boolean;
8
+ arguments?: Record<string, any>;
9
+ }
10
+ /**
11
+ * Exchange options for resource creation
12
+ */
13
+ export interface ExchangeOptions {
14
+ durable?: boolean;
15
+ autoDelete?: boolean;
16
+ arguments?: Record<string, any>;
17
+ }
18
+ /**
19
+ * Resource creator interface for auto-creating exchanges and queues
20
+ */
21
+ export interface IResourceCreator {
22
+ /** Ensure exchange exists, create if it doesn't */
23
+ ensureExchange(exchange: string, type?: string, options?: ExchangeOptions): Promise<void>;
24
+ /** Ensure queue exists, create if it doesn't */
25
+ ensureQueue(queue: string, options?: QueueOptions): Promise<void>;
26
+ /** Bind queue to exchange with routing key */
27
+ bindQueue(queue: string, exchange: string, routingKey: string): Promise<void>;
28
+ /** Unbind queue from exchange with routing key */
29
+ unbindQueue(queue: string, exchange: string, routingKey: string): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=IResource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IResource.d.ts","sourceRoot":"","sources":["../../src/interfaces/IResource.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1F,gDAAgD;IAChD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElE,8CAA8C;IAC9C,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E,kDAAkD;IAClD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjF"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IResource.js","sourceRoot":"","sources":["../../src/interfaces/IResource.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { MessageCallback } from './IMessage';
2
+ /**
3
+ * Main SDK RabbitMQ interface - the public API
4
+ */
5
+ export interface ISdkRabbitmq {
6
+ /** Publish a message to an exchange */
7
+ publish(exchange: string, routingKey: string, payload: any): Promise<boolean>;
8
+ /** Subscribe to messages from a queue */
9
+ subscribe(exchange: string, queue: string, routingKey: string, callback: MessageCallback): Promise<void>;
10
+ /** Bind a queue to an exchange with a routing key */
11
+ bind(queue: string, exchange: string, routingKey: string): Promise<void>;
12
+ /** Unbind a queue from an exchange with a routing key */
13
+ unbind(queue: string, exchange: string, routingKey: string): Promise<void>;
14
+ /** Disconnect from RabbitMQ gracefully */
15
+ disconnect(): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=ISdkRabbitmq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISdkRabbitmq.d.ts","sourceRoot":"","sources":["../../src/interfaces/ISdkRabbitmq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9E,yCAAyC;IACzC,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,qDAAqD;IACrD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzE,yDAAyD;IACzD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3E,0CAA0C;IAC1C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ISdkRabbitmq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISdkRabbitmq.js","sourceRoot":"","sources":["../../src/interfaces/ISdkRabbitmq.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export * from './IConfiguration';
2
+ export * from './IConnection';
3
+ export * from './IMessage';
4
+ export * from './IResource';
5
+ export * from './IDLQ';
6
+ export * from './ILogger';
7
+ export * from './ISdkRabbitmq';
8
+ export * from './IErrors';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AAGjC,cAAc,eAAe,CAAC;AAG9B,cAAc,YAAY,CAAC;AAG3B,cAAc,aAAa,CAAC;AAG5B,cAAc,QAAQ,CAAC;AAGvB,cAAc,WAAW,CAAC;AAG1B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,33 @@
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
+ // Configuration interfaces
18
+ __exportStar(require("./IConfiguration"), exports);
19
+ // Connection interfaces
20
+ __exportStar(require("./IConnection"), exports);
21
+ // Message interfaces
22
+ __exportStar(require("./IMessage"), exports);
23
+ // Resource interfaces
24
+ __exportStar(require("./IResource"), exports);
25
+ // DLQ interfaces
26
+ __exportStar(require("./IDLQ"), exports);
27
+ // Logger interfaces
28
+ __exportStar(require("./ILogger"), exports);
29
+ // Main SDK interface
30
+ __exportStar(require("./ISdkRabbitmq"), exports);
31
+ // Error classes
32
+ __exportStar(require("./IErrors"), exports);
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,mDAAiC;AAEjC,wBAAwB;AACxB,gDAA8B;AAE9B,qBAAqB;AACrB,6CAA2B;AAE3B,sBAAsB;AACtB,8CAA4B;AAE5B,iBAAiB;AACjB,yCAAuB;AAEvB,oBAAoB;AACpB,4CAA0B;AAE1B,qBAAqB;AACrB,iDAA+B;AAE/B,gBAAgB;AAChB,4CAA0B"}
@@ -0,0 +1,8 @@
1
+ import { IConfiguration } from '../interfaces/IConfiguration';
2
+ /**
3
+ * Validates the configuration object against the expected schema
4
+ * @param config - Configuration object to validate
5
+ * @throws ConfigurationError if validation fails
6
+ */
7
+ export declare function validateConfigurationSchema(config: any): asserts config is IConfiguration;
8
+ //# sourceMappingURL=configSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configSchema.d.ts","sourceRoot":"","sources":["../../src/utils/configSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAiDzF"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateConfigurationSchema = validateConfigurationSchema;
4
+ const IErrors_1 = require("../interfaces/IErrors");
5
+ /**
6
+ * Validates the configuration object against the expected schema
7
+ * @param config - Configuration object to validate
8
+ * @throws ConfigurationError if validation fails
9
+ */
10
+ function validateConfigurationSchema(config) {
11
+ if (!config || typeof config !== 'object') {
12
+ throw new IErrors_1.ConfigurationError('Configuration must be a valid object');
13
+ }
14
+ // Validate required url property
15
+ if (!config.url || typeof config.url !== 'string') {
16
+ throw new IErrors_1.ConfigurationError('Configuration must include a valid "url" string property');
17
+ }
18
+ // Validate required dlq property
19
+ if (!config.dlq || typeof config.dlq !== 'object') {
20
+ throw new IErrors_1.ConfigurationError('Configuration must include a valid "dlq" object property');
21
+ }
22
+ // Validate dlq.active property
23
+ if (typeof config.dlq.active !== 'boolean') {
24
+ throw new IErrors_1.ConfigurationError('Configuration dlq.active must be a boolean value');
25
+ }
26
+ // Validate optional dlq properties
27
+ if (config.dlq.ttl !== undefined && (typeof config.dlq.ttl !== 'number' || config.dlq.ttl < 0)) {
28
+ throw new IErrors_1.ConfigurationError('Configuration dlq.ttl must be a positive number');
29
+ }
30
+ if (config.dlq.maxRetries !== undefined && (typeof config.dlq.maxRetries !== 'number' || config.dlq.maxRetries < 0)) {
31
+ throw new IErrors_1.ConfigurationError('Configuration dlq.maxRetries must be a positive number');
32
+ }
33
+ if (config.dlq.retryDelay !== undefined && (typeof config.dlq.retryDelay !== 'number' || config.dlq.retryDelay < 0)) {
34
+ throw new IErrors_1.ConfigurationError('Configuration dlq.retryDelay must be a positive number');
35
+ }
36
+ // Validate optional logging property
37
+ if (config.logging !== undefined) {
38
+ if (typeof config.logging !== 'object') {
39
+ throw new IErrors_1.ConfigurationError('Configuration logging must be an object');
40
+ }
41
+ const validLevels = ['error', 'warn', 'info', 'debug'];
42
+ if (config.logging.level !== undefined && !validLevels.includes(config.logging.level)) {
43
+ throw new IErrors_1.ConfigurationError(`Configuration logging.level must be one of: ${validLevels.join(', ')}`);
44
+ }
45
+ const validFormats = ['json', 'text'];
46
+ if (config.logging.format !== undefined && !validFormats.includes(config.logging.format)) {
47
+ throw new IErrors_1.ConfigurationError(`Configuration logging.format must be one of: ${validFormats.join(', ')}`);
48
+ }
49
+ }
50
+ }
51
+ //# sourceMappingURL=configSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configSchema.js","sourceRoot":"","sources":["../../src/utils/configSchema.ts"],"names":[],"mappings":";;AAQA,kEAiDC;AAxDD,mDAA2D;AAE3D;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,MAAW;IACrD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,4BAAkB,CAAC,sCAAsC,CAAC,CAAC;IACvE,CAAC;IAED,iCAAiC;IACjC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,4BAAkB,CAAC,0DAA0D,CAAC,CAAC;IAC3F,CAAC;IAED,iCAAiC;IACjC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,4BAAkB,CAAC,0DAA0D,CAAC,CAAC;IAC3F,CAAC;IAED,+BAA+B;IAC/B,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,4BAAkB,CAAC,kDAAkD,CAAC,CAAC;IACnF,CAAC;IAED,mCAAmC;IACnC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/F,MAAM,IAAI,4BAAkB,CAAC,iDAAiD,CAAC,CAAC;IAClF,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QACpH,MAAM,IAAI,4BAAkB,CAAC,wDAAwD,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QACpH,MAAM,IAAI,4BAAkB,CAAC,wDAAwD,CAAC,CAAC;IACzF,CAAC;IAED,qCAAqC;IACrC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,4BAAkB,CAAC,yCAAyC,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACtF,MAAM,IAAI,4BAAkB,CAAC,+CAA+C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxG,CAAC;QAED,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACzF,MAAM,IAAI,4BAAkB,CAAC,gDAAgD,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ version: "3.8"
2
+
3
+ services:
4
+ sdk_rabbitmq:
5
+ image: rabbitmq:3-management
6
+ container_name: sdk_rabbitmq
7
+ hostname: rabbitmq
8
+ networks:
9
+ - whatsapp-network
10
+ ports:
11
+ - "5677:5672" # protocolo AMQP
12
+ - "15677:15672" # UI de gerenciamento
13
+ environment:
14
+ RABBITMQ_NODENAME: rabbit@rabbitmq
15
+ RABBITMQ_ERLANG_COOKIE: "SUPERSECRETCOOKIE"
16
+ volumes:
17
+ - rabbitmq_data:/var/lib/rabbitmq
18
+
19
+ volumes:
20
+ rabbitmq_data:
21
+
22
+ networks:
23
+ whatsapp-network:
24
+ driver: bridge
package/example.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { SdkRabbitmq } from './src';
2
+
3
+ /**
4
+ * Example usage of the SdkRabbitmq singleton
5
+ * This demonstrates the complete integration of all components
6
+ */
7
+ async function example() {
8
+ try {
9
+ // Get singleton instance - this will initialize all components
10
+ const sdk = await SdkRabbitmq.getInstance();
11
+
12
+ console.log('SDK initialized successfully');
13
+ console.log('SDK ready:', sdk.isReady());
14
+
15
+ // Example: Subscribe to messages
16
+ await sdk.subscribe(
17
+ 'user-events',
18
+ 'user-notifications',
19
+ 'user.created',
20
+ (message, ack, nack) => {
21
+ try {
22
+ console.log('Received message:', message);
23
+ // Process message successfully
24
+ ack();
25
+ } catch (error) {
26
+ console.error('Error processing message:', error);
27
+ // Send to DLQ if processing fails
28
+ nack();
29
+ }
30
+ }
31
+ );
32
+
33
+ // Example: Publish a message
34
+ const publishResult = await sdk.publish(
35
+ 'user-events',
36
+ 'user.created',
37
+ {
38
+ userId: '12345',
39
+ email: 'user@example.com',
40
+ timestamp: new Date().toISOString()
41
+ }
42
+ );
43
+
44
+ console.log('Message published:', publishResult);
45
+
46
+ // Check active consumers
47
+ console.log('Active consumers:', sdk.getActiveConsumers());
48
+
49
+ // Graceful shutdown after 5 seconds
50
+ setTimeout(async () => {
51
+ await sdk.disconnect();
52
+ console.log('SDK disconnected');
53
+ }, 5000);
54
+
55
+ } catch (error) {
56
+ console.error('Error in example:', error);
57
+ }
58
+ }
59
+
60
+ // Run example if this file is executed directly
61
+ if (require.main === module) {
62
+ example().catch(console.error);
63
+ }
64
+
65
+ export { example };
@@ -0,0 +1,155 @@
1
+ # Teste de Fluxo de Roteamento Dinâmico
2
+
3
+ Este teste implementa um fluxo de mensagens com roteamento dinâmico usando o SDK RabbitMQ.
4
+
5
+ ## Descrição do Fluxo
6
+
7
+ O teste simula um sistema de chatbot onde diferentes agentes processam informações do usuário em sequência:
8
+
9
+ 1. **GreetingAgent** - Recebe mensagens iniciais e inicia o fluxo
10
+ 2. **PatientNameAgent** - Coleta o nome do paciente
11
+ 3. **PatientCPFAgent** - Coleta o CPF do paciente
12
+ 4. **PatientEmailAgent** - Coleta o email do paciente
13
+
14
+ ## Arquitetura
15
+
16
+ ### Exchanges
17
+ - `chatbot.whatsapp` (topic) - Para mensagens do WhatsApp
18
+ - `chatbot.agents` (topic) - Para comunicação entre agentes
19
+ - `whatsapp.message.text` (topic) - Para monitoramento de mensagens finais
20
+
21
+ ### Fluxo de Roteamento Dinâmico
22
+
23
+ 1. **GreetingAgent** escuta `chatbot.whatsapp` com routing key `phone.*`
24
+ 2. Cada agente subsequente:
25
+ - Escuta `chatbot.agents` com sua routing key específica
26
+ - Faz bind dinâmico para `phone.{telefone}` em `chatbot.whatsapp`
27
+ - Processa a mensagem
28
+ - Faz unbind da routing key específica
29
+ - Envia para o próximo agente
30
+
31
+ ### Memória Global
32
+
33
+ ```typescript
34
+ interface GlobalMemory {
35
+ flow: string[]; // Sequência dos agentes
36
+ currentStep: Record<string, Record<string, string>>; // Status por telefone
37
+ userData: Record<string, Record<string, any>>; // Dados coletados
38
+ }
39
+ ```
40
+
41
+ ## Como Executar
42
+
43
+ ### Pré-requisitos
44
+ - RabbitMQ rodando localmente (porta 5672)
45
+ - Node.js e npm instalados
46
+ - Dependências do projeto instaladas
47
+
48
+ ### Opções de Execução
49
+
50
+ #### 1. TypeScript (Recomendado)
51
+ ```bash
52
+ npm run test:dynamic-routing
53
+ ```
54
+
55
+ #### 2. JavaScript
56
+ ```bash
57
+ npm run test:dynamic-routing:js
58
+ ```
59
+
60
+ #### 3. Execução Manual
61
+ ```bash
62
+ # Compilar primeiro
63
+ npm run build
64
+
65
+ # Executar TypeScript
66
+ npx ts-node examples/test-dynamic-routing-flow.ts
67
+
68
+ # Ou executar JavaScript compilado
69
+ node examples/test-dynamic-routing-flow.js
70
+ ```
71
+
72
+ ## Estrutura dos Agentes
73
+
74
+ ### BaseAgent (Classe Abstrata)
75
+ ```typescript
76
+ abstract class BaseAgent {
77
+ protected config: AgentConfig;
78
+ protected sdk: SdkRabbitmq;
79
+ protected name: string;
80
+ protected routingKeyAgent: string;
81
+
82
+ protected async processMessage(payload: MessagePayload, ack: () => void, nack: () => void): Promise<void>
83
+ abstract start(): Promise<void>;
84
+ }
85
+ ```
86
+
87
+ ### GreetingAgentImpl
88
+ - Escuta `phone.*` em `chatbot.whatsapp`
89
+ - Inicia o fluxo para novos telefones
90
+
91
+ ### DynamicAgent
92
+ - Escuta sua routing key específica em `chatbot.agents`
93
+ - Faz bind/unbind dinâmico para telefones específicos
94
+
95
+ ## Payload das Mensagens
96
+
97
+ ```typescript
98
+ interface MessagePayload {
99
+ phone: string;
100
+ timestamp: number;
101
+ metadata: {
102
+ identification: string;
103
+ senderAgent: string;
104
+ value: string;
105
+ userData?: Record<string, any>;
106
+ };
107
+ }
108
+ ```
109
+
110
+ ## Monitoramento
111
+
112
+ O teste inclui um subscriber de monitoramento que escuta `whatsapp.message.text` com routing key `send` para capturar as mensagens finais do fluxo.
113
+
114
+ ## Logs Esperados
115
+
116
+ Durante a execução, você verá logs detalhados mostrando:
117
+ - ✅ Inicialização dos agentes
118
+ - 🔒 Bind/unbind dinâmico de routing keys
119
+ - 🤖 Processamento de mensagens por cada agente
120
+ - 📊 Estado da memória global
121
+ - 📱 Mensagens finais no monitor
122
+
123
+ ## Exemplo de Saída
124
+
125
+ ```
126
+ 🎯 Iniciando teste de fluxo de roteamento dinâmico...
127
+
128
+ ✅ SDK inicializado com sucesso
129
+
130
+ 👂 Configurando subscriber de monitoramento...
131
+
132
+ 🤖 Inicializando agentes...
133
+ 🚀 Iniciando GreetingAgent...
134
+ 👂 GreetingAgent ouvindo na exchange: chatbot.whatsapp, routing key: phone.*
135
+
136
+ 🚀 Iniciando PatientNameAgent...
137
+ 👂 PatientNameAgent ouvindo na exchange: chatbot.agents, routing key: patientName
138
+
139
+ ...
140
+
141
+ 🔥 Iniciando fluxo para telefone: 5511999999999
142
+
143
+ 🤖 GreetingAgent processando mensagem: {...}
144
+ ✅ Step greeting marked as success for phone 5511999999999
145
+ 📤 GreetingAgent enviando para próximo agente: patientName
146
+
147
+ 🔒 PatientNameAgent fez bind para routing key: phone.5511999999999
148
+ 🤖 PatientNameAgent processando mensagem: {...}
149
+ 🔓 PatientNameAgent fez unbind da routing key: phone.5511999999999
150
+ ...
151
+ ```
152
+
153
+ ## Configuração
154
+
155
+ O teste usa a configuração padrão do SDK. Para personalizar, edite o arquivo `config.json` na raiz do projeto ou configure as variáveis de ambiente apropriadas.
@@ -0,0 +1,56 @@
1
+ const { SdkRabbitmq } = require('../dist/index');
2
+
3
+ async function bindUnbindExample() {
4
+ try {
5
+ // Get SDK instance
6
+ const sdk = await SdkRabbitmq.getInstance();
7
+
8
+ console.log('SDK initialized successfully');
9
+
10
+ // Example 1: Basic binding
11
+ console.log('\n=== Basic Binding ===');
12
+ await sdk.bind('notifications', 'events', 'user.created');
13
+ console.log('✓ Bound notifications queue to events exchange with user.created routing key');
14
+
15
+ // Example 2: Multiple bindings for the same queue
16
+ console.log('\n=== Multiple Bindings ===');
17
+ await sdk.bind('analytics', 'user-events', 'user.login');
18
+ await sdk.bind('analytics', 'user-events', 'user.logout');
19
+ await sdk.bind('analytics', 'order-events', 'order.*');
20
+ console.log('✓ Bound analytics queue to multiple exchanges and routing keys');
21
+
22
+ // Example 3: Topic exchange patterns
23
+ console.log('\n=== Topic Exchange Patterns ===');
24
+ await sdk.bind('logs', 'system-logs', 'error.#'); // All error logs
25
+ await sdk.bind('alerts', 'system-logs', '*.critical'); // Critical from any service
26
+ console.log('✓ Bound queues with topic exchange patterns');
27
+
28
+ // Example 4: Unbinding when no longer needed
29
+ console.log('\n=== Unbinding ===');
30
+ await sdk.unbind('analytics', 'user-events', 'user.login');
31
+ console.log('✓ Unbound analytics queue from user.login routing key');
32
+
33
+ await sdk.unbind('notifications', 'events', 'user.created');
34
+ console.log('✓ Unbound notifications queue from user.created routing key');
35
+
36
+ // Example 5: Error handling
37
+ console.log('\n=== Error Handling ===');
38
+ try {
39
+ await sdk.bind('', 'exchange', 'route'); // Invalid queue name
40
+ } catch (error) {
41
+ console.log('✓ Caught validation error:', error.message);
42
+ }
43
+
44
+ console.log('\n=== Example completed successfully ===');
45
+
46
+ // Graceful shutdown
47
+ await sdk.disconnect();
48
+ console.log('SDK disconnected');
49
+
50
+ } catch (error) {
51
+ console.error('Example failed:', error);
52
+ }
53
+ }
54
+
55
+ // Run the example
56
+ bindUnbindExample();