@geekmidas/events 0.1.0 → 1.0.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.
Files changed (240) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{BasicConnection-C4_Y0nIj.d.mts → BasicConnection-BTRsXiuH.d.cts} +3 -2
  3. package/dist/BasicConnection-BTRsXiuH.d.cts.map +1 -0
  4. package/dist/BasicConnection-Bz3F2rXA.cjs.map +1 -1
  5. package/dist/{BasicConnection-CddnULuT.d.cts → BasicConnection-DIxtA7jK.d.mts} +3 -2
  6. package/dist/BasicConnection-DIxtA7jK.d.mts.map +1 -0
  7. package/dist/BasicConnection-DOSOFSsW.mjs.map +1 -1
  8. package/dist/BasicPublisher-CaX8GCUi.mjs.map +1 -1
  9. package/dist/{BasicPublisher-DCBxaTwC.d.mts → BasicPublisher-CpJFK2oS.d.mts} +5 -3
  10. package/dist/BasicPublisher-CpJFK2oS.d.mts.map +1 -0
  11. package/dist/{BasicPublisher-V5hELHG9.d.cts → BasicPublisher-D1q0a2xp.d.cts} +5 -3
  12. package/dist/BasicPublisher-D1q0a2xp.d.cts.map +1 -0
  13. package/dist/BasicPublisher-afwuA4Xp.cjs.map +1 -1
  14. package/dist/{BasicSubscriber-BB3aKeph.d.mts → BasicSubscriber-6w0Af4DD.d.mts} +5 -3
  15. package/dist/BasicSubscriber-6w0Af4DD.d.mts.map +1 -0
  16. package/dist/{BasicSubscriber-Ckf3BkxS.cjs → BasicSubscriber-BN9fKRrU.cjs} +2 -4
  17. package/dist/BasicSubscriber-BN9fKRrU.cjs.map +1 -0
  18. package/dist/{BasicSubscriber-DPpJNUUY.mjs → BasicSubscriber-BgsKYQmi.mjs} +2 -4
  19. package/dist/BasicSubscriber-BgsKYQmi.mjs.map +1 -0
  20. package/dist/{BasicSubscriber-DOwgFw5j.d.cts → BasicSubscriber-DXxQewjc.d.cts} +5 -3
  21. package/dist/BasicSubscriber-DXxQewjc.d.cts.map +1 -0
  22. package/dist/{EventConnection-DZhn1Msl.d.cts → EventConnection-BaJRXdg7.d.cts} +2 -2
  23. package/dist/EventConnection-BaJRXdg7.d.cts.map +1 -0
  24. package/dist/EventConnection-ClLMoIUU.mjs.map +1 -1
  25. package/dist/EventConnection-F_N81SXu.cjs.map +1 -1
  26. package/dist/{EventConnection-DeXfLGom.d.mts → EventConnection-SOhtmxib.d.mts} +2 -2
  27. package/dist/EventConnection-SOhtmxib.d.mts.map +1 -0
  28. package/dist/EventConnection.d.cts +2 -2
  29. package/dist/EventConnection.d.mts +2 -2
  30. package/dist/{Publisher-C3m8JFXm.d.mts → Publisher-1CfcYRnm.d.mts} +4 -2
  31. package/dist/Publisher-1CfcYRnm.d.mts.map +1 -0
  32. package/dist/{Publisher-nXNVjL0e.d.cts → Publisher-BfNgvHwQ.d.cts} +4 -2
  33. package/dist/Publisher-BfNgvHwQ.d.cts.map +1 -0
  34. package/dist/Publisher-DS0aOh8r.mjs.map +1 -1
  35. package/dist/Publisher-ceu6OxCj.cjs.map +1 -1
  36. package/dist/Publisher.d.cts +2 -2
  37. package/dist/Publisher.d.mts +2 -2
  38. package/dist/{RabbitMQConnection-7cWp_-_Q.d.cts → RabbitMQConnection-Bm8VCI2R.d.cts} +3 -2
  39. package/dist/RabbitMQConnection-Bm8VCI2R.d.cts.map +1 -0
  40. package/dist/{RabbitMQConnection-BN_GybOv.cjs → RabbitMQConnection-CjBoCd9n.cjs} +2 -2
  41. package/dist/RabbitMQConnection-CjBoCd9n.cjs.map +1 -0
  42. package/dist/{RabbitMQConnection-C2HC7J7K.d.mts → RabbitMQConnection-Ck-ktCp_.d.mts} +3 -2
  43. package/dist/RabbitMQConnection-Ck-ktCp_.d.mts.map +1 -0
  44. package/dist/{RabbitMQConnection-eVOVS4Dl.mjs → RabbitMQConnection-DFLkr2vq.mjs} +2 -2
  45. package/dist/RabbitMQConnection-DFLkr2vq.mjs.map +1 -0
  46. package/dist/{RabbitMQPublisher-CSCn6gMA.cjs → RabbitMQPublisher-C94q6g8q.cjs} +1 -1
  47. package/dist/RabbitMQPublisher-C94q6g8q.cjs.map +1 -0
  48. package/dist/{RabbitMQPublisher-CpcbgrXj.d.cts → RabbitMQPublisher-COnxcWEZ.d.mts} +5 -3
  49. package/dist/RabbitMQPublisher-COnxcWEZ.d.mts.map +1 -0
  50. package/dist/{RabbitMQPublisher-DDZi15Ro.d.mts → RabbitMQPublisher-qQT7-1-p.d.cts} +5 -3
  51. package/dist/RabbitMQPublisher-qQT7-1-p.d.cts.map +1 -0
  52. package/dist/{RabbitMQPublisher-BZX0edgL.mjs → RabbitMQPublisher-yUqWNq-P.mjs} +1 -1
  53. package/dist/RabbitMQPublisher-yUqWNq-P.mjs.map +1 -0
  54. package/dist/{RabbitMQSubscriber-B5I-hBaT.mjs → RabbitMQSubscriber-BWniDtFs.mjs} +2 -3
  55. package/dist/RabbitMQSubscriber-BWniDtFs.mjs.map +1 -0
  56. package/dist/{RabbitMQSubscriber-BJ9PTGny.d.cts → RabbitMQSubscriber-C_sZjDPU.d.mts} +5 -3
  57. package/dist/RabbitMQSubscriber-C_sZjDPU.d.mts.map +1 -0
  58. package/dist/{RabbitMQSubscriber-CIvIw8MG.d.mts → RabbitMQSubscriber-D12sssMb.d.cts} +5 -3
  59. package/dist/RabbitMQSubscriber-D12sssMb.d.cts.map +1 -0
  60. package/dist/{RabbitMQSubscriber-Cj7qLIi6.cjs → RabbitMQSubscriber-DGEO-clQ.cjs} +2 -3
  61. package/dist/RabbitMQSubscriber-DGEO-clQ.cjs.map +1 -0
  62. package/dist/{SNSConnection-CAImaMM2.d.mts → SNSConnection-BDfQrVBO.d.cts} +3 -2
  63. package/dist/SNSConnection-BDfQrVBO.d.cts.map +1 -0
  64. package/dist/{SNSConnection-DVEE3XoC.mjs → SNSConnection-D8a31sJK.mjs} +1 -1
  65. package/dist/SNSConnection-D8a31sJK.mjs.map +1 -0
  66. package/dist/{SNSConnection-CZz_U56V.cjs → SNSConnection-DqLbiQ_X.cjs} +1 -1
  67. package/dist/SNSConnection-DqLbiQ_X.cjs.map +1 -0
  68. package/dist/{SNSConnection-Cqbr7-Ho.d.cts → SNSConnection-mHb10nQ6.d.mts} +3 -2
  69. package/dist/SNSConnection-mHb10nQ6.d.mts.map +1 -0
  70. package/dist/{SNSPublisher-DbWVH-g_.cjs → SNSPublisher-BRgwumLS.cjs} +2 -3
  71. package/dist/SNSPublisher-BRgwumLS.cjs.map +1 -0
  72. package/dist/{SNSPublisher-Dkhb4LU-.d.mts → SNSPublisher-CM7UAWtf.d.mts} +7 -6
  73. package/dist/SNSPublisher-CM7UAWtf.d.mts.map +1 -0
  74. package/dist/{SNSPublisher-Do-FMUyT.mjs → SNSPublisher-i4w_-RmP.mjs} +2 -3
  75. package/dist/SNSPublisher-i4w_-RmP.mjs.map +1 -0
  76. package/dist/{SNSPublisher-RVZFa7kL.d.cts → SNSPublisher-kpsSlGDn.d.cts} +7 -6
  77. package/dist/SNSPublisher-kpsSlGDn.d.cts.map +1 -0
  78. package/dist/{SNSSubscriber-e7eG48yJ.mjs → SNSSubscriber-BEf-H4p5.mjs} +5 -9
  79. package/dist/SNSSubscriber-BEf-H4p5.mjs.map +1 -0
  80. package/dist/{SNSSubscriber-B31JmkAE.d.mts → SNSSubscriber-DDB3--pm.d.cts} +4 -3
  81. package/dist/SNSSubscriber-DDB3--pm.d.cts.map +1 -0
  82. package/dist/{SNSSubscriber-k2UwKUxu.d.cts → SNSSubscriber-Dwo8391f.d.mts} +4 -3
  83. package/dist/SNSSubscriber-Dwo8391f.d.mts.map +1 -0
  84. package/dist/{SNSSubscriber-DpEwQ8Tb.cjs → SNSSubscriber-FYqSi346.cjs} +5 -9
  85. package/dist/SNSSubscriber-FYqSi346.cjs.map +1 -0
  86. package/dist/{SQSConnection-C5WFqZW7.d.mts → SQSConnection-B5Ep9Tma.d.cts} +3 -2
  87. package/dist/SQSConnection-B5Ep9Tma.d.cts.map +1 -0
  88. package/dist/{SQSConnection-geav2Rsn.d.cts → SQSConnection-BI_xOzyJ.d.mts} +3 -2
  89. package/dist/SQSConnection-BI_xOzyJ.d.mts.map +1 -0
  90. package/dist/{SQSConnection-BBlDWZLU.mjs → SQSConnection-BwHhXLIu.mjs} +1 -1
  91. package/dist/SQSConnection-BwHhXLIu.mjs.map +1 -0
  92. package/dist/{SQSConnection-DWYDtftQ.cjs → SQSConnection-Ctu3XY9E.cjs} +1 -1
  93. package/dist/SQSConnection-Ctu3XY9E.cjs.map +1 -0
  94. package/dist/{SQSPublisher-B3lS2zbu.mjs → SQSPublisher-BDGMw1uf.mjs} +1 -1
  95. package/dist/SQSPublisher-BDGMw1uf.mjs.map +1 -0
  96. package/dist/{SQSPublisher-CdsayOLV.d.mts → SQSPublisher-BN1ds6SN.d.mts} +5 -3
  97. package/dist/SQSPublisher-BN1ds6SN.d.mts.map +1 -0
  98. package/dist/{SQSPublisher-nzbSaXSH.cjs → SQSPublisher-C3Y_gOjV.cjs} +1 -1
  99. package/dist/SQSPublisher-C3Y_gOjV.cjs.map +1 -0
  100. package/dist/{SQSPublisher-Utb_FTe5.d.cts → SQSPublisher-DFTqwzRW.d.cts} +5 -3
  101. package/dist/SQSPublisher-DFTqwzRW.d.cts.map +1 -0
  102. package/dist/{SQSSubscriber-DcL9BbG1.cjs → SQSSubscriber-BB9TWyLA.cjs} +5 -12
  103. package/dist/SQSSubscriber-BB9TWyLA.cjs.map +1 -0
  104. package/dist/{SQSSubscriber-B6iL1EnX.d.cts → SQSSubscriber-BO2me_gs.d.cts} +4 -3
  105. package/dist/SQSSubscriber-BO2me_gs.d.cts.map +1 -0
  106. package/dist/{SQSSubscriber-DBeE4XAR.d.mts → SQSSubscriber-FyZFfr2-.d.mts} +4 -3
  107. package/dist/SQSSubscriber-FyZFfr2-.d.mts.map +1 -0
  108. package/dist/{SQSSubscriber-84pFnW1z.mjs → SQSSubscriber-ux7QEMdd.mjs} +5 -12
  109. package/dist/SQSSubscriber-ux7QEMdd.mjs.map +1 -0
  110. package/dist/Subscriber-Bd9hb_jp.mjs.map +1 -1
  111. package/dist/{Subscriber-Cff9EIpv.d.mts → Subscriber-BxT-KzFJ.d.mts} +4 -2
  112. package/dist/Subscriber-BxT-KzFJ.d.mts.map +1 -0
  113. package/dist/{Subscriber-CpAwcUzb.d.cts → Subscriber-DDD_4Nlx.d.cts} +4 -2
  114. package/dist/Subscriber-DDD_4Nlx.d.cts.map +1 -0
  115. package/dist/Subscriber-saVOWuMq.cjs.map +1 -1
  116. package/dist/Subscriber.d.cts +2 -2
  117. package/dist/Subscriber.d.mts +2 -2
  118. package/dist/basic/BasicConnection.d.cts +2 -2
  119. package/dist/basic/BasicConnection.d.mts +2 -2
  120. package/dist/basic/BasicPublisher.d.cts +3 -3
  121. package/dist/basic/BasicPublisher.d.mts +3 -3
  122. package/dist/basic/BasicSubscriber.cjs +1 -1
  123. package/dist/basic/BasicSubscriber.d.cts +3 -3
  124. package/dist/basic/BasicSubscriber.d.mts +3 -3
  125. package/dist/basic/BasicSubscriber.mjs +1 -1
  126. package/dist/basic/index.cjs +1 -1
  127. package/dist/basic/index.d.cts +4 -4
  128. package/dist/basic/index.d.mts +4 -4
  129. package/dist/basic/index.mjs +1 -1
  130. package/dist/index.d.cts +4 -4
  131. package/dist/index.d.mts +4 -4
  132. package/dist/rabbitmq/RabbitMQConnection.cjs +1 -1
  133. package/dist/rabbitmq/RabbitMQConnection.d.cts +2 -2
  134. package/dist/rabbitmq/RabbitMQConnection.d.mts +2 -2
  135. package/dist/rabbitmq/RabbitMQConnection.mjs +1 -1
  136. package/dist/rabbitmq/RabbitMQPublisher.cjs +1 -1
  137. package/dist/rabbitmq/RabbitMQPublisher.d.cts +3 -3
  138. package/dist/rabbitmq/RabbitMQPublisher.d.mts +3 -3
  139. package/dist/rabbitmq/RabbitMQPublisher.mjs +1 -1
  140. package/dist/rabbitmq/RabbitMQSubscriber.cjs +1 -1
  141. package/dist/rabbitmq/RabbitMQSubscriber.d.cts +3 -3
  142. package/dist/rabbitmq/RabbitMQSubscriber.d.mts +3 -3
  143. package/dist/rabbitmq/RabbitMQSubscriber.mjs +1 -1
  144. package/dist/rabbitmq/index.cjs +3 -3
  145. package/dist/rabbitmq/index.d.cts +4 -4
  146. package/dist/rabbitmq/index.d.mts +4 -4
  147. package/dist/rabbitmq/index.mjs +3 -3
  148. package/dist/sns/SNSConnection.cjs +1 -1
  149. package/dist/sns/SNSConnection.d.cts +2 -2
  150. package/dist/sns/SNSConnection.d.mts +2 -2
  151. package/dist/sns/SNSConnection.mjs +1 -1
  152. package/dist/sns/SNSPublisher.cjs +1 -1
  153. package/dist/sns/SNSPublisher.d.cts +3 -3
  154. package/dist/sns/SNSPublisher.d.mts +3 -3
  155. package/dist/sns/SNSPublisher.mjs +1 -1
  156. package/dist/sns/SNSSubscriber.cjs +3 -3
  157. package/dist/sns/SNSSubscriber.d.cts +3 -3
  158. package/dist/sns/SNSSubscriber.d.mts +3 -3
  159. package/dist/sns/SNSSubscriber.mjs +3 -3
  160. package/dist/sns/index.cjs +5 -5
  161. package/dist/sns/index.d.cts +4 -4
  162. package/dist/sns/index.d.mts +4 -4
  163. package/dist/sns/index.mjs +5 -5
  164. package/dist/sqs/SQSConnection.cjs +1 -1
  165. package/dist/sqs/SQSConnection.d.cts +2 -2
  166. package/dist/sqs/SQSConnection.d.mts +2 -2
  167. package/dist/sqs/SQSConnection.mjs +1 -1
  168. package/dist/sqs/SQSPublisher.cjs +1 -1
  169. package/dist/sqs/SQSPublisher.d.cts +3 -3
  170. package/dist/sqs/SQSPublisher.d.mts +3 -3
  171. package/dist/sqs/SQSPublisher.mjs +1 -1
  172. package/dist/sqs/SQSSubscriber.cjs +1 -1
  173. package/dist/sqs/SQSSubscriber.d.cts +3 -3
  174. package/dist/sqs/SQSSubscriber.d.mts +3 -3
  175. package/dist/sqs/SQSSubscriber.mjs +1 -1
  176. package/dist/sqs/index.cjs +3 -3
  177. package/dist/sqs/index.d.cts +4 -4
  178. package/dist/sqs/index.d.mts +4 -4
  179. package/dist/sqs/index.mjs +3 -3
  180. package/dist/types-B63qHVOG.mjs.map +1 -1
  181. package/dist/types-CvSMEO5z.cjs.map +1 -1
  182. package/dist/{types-D0g-o6wX.d.mts → types-DSVsPgKd.d.mts} +2 -1
  183. package/dist/types-DSVsPgKd.d.mts.map +1 -0
  184. package/dist/{types-DEGUg5BA.d.cts → types-Dmbp1U-6.d.cts} +2 -1
  185. package/dist/types-Dmbp1U-6.d.cts.map +1 -0
  186. package/dist/types.d.cts +1 -1
  187. package/dist/types.d.mts +1 -1
  188. package/package.json +3 -3
  189. package/src/EventConnection.ts +31 -31
  190. package/src/Publisher.ts +78 -78
  191. package/src/Subscriber.ts +91 -91
  192. package/src/__tests__/EventConnection.spec.ts +42 -0
  193. package/src/__tests__/Publisher.spec.ts +96 -0
  194. package/src/__tests__/Subscriber.spec.ts +91 -23
  195. package/src/basic/BasicConnection.ts +35 -35
  196. package/src/basic/BasicPublisher.ts +8 -8
  197. package/src/basic/BasicSubscriber.ts +13 -16
  198. package/src/basic/__tests__/BasicSubscriber.spec.ts +116 -116
  199. package/src/index.ts +13 -13
  200. package/src/rabbitmq/RabbitMQConnection.ts +139 -139
  201. package/src/rabbitmq/RabbitMQPublisher.ts +48 -48
  202. package/src/rabbitmq/RabbitMQSubscriber.ts +100 -102
  203. package/src/rabbitmq/__tests__/RabbitMQPublisher.spec.ts +364 -364
  204. package/src/rabbitmq/__tests__/RabbitMQSubscriber.spec.ts +204 -204
  205. package/src/rabbitmq/index.ts +3 -3
  206. package/src/sns/SNSConnection.ts +76 -76
  207. package/src/sns/SNSPublisher.ts +54 -56
  208. package/src/sns/SNSSubscriber.ts +187 -191
  209. package/src/sns/__tests__/SNS-SQS-Integration.spec.ts +321 -321
  210. package/src/sns/__tests__/SNSPublisher.spec.ts +449 -0
  211. package/src/sns/__tests__/SNSSubscriber.spec.ts +527 -0
  212. package/src/sns/index.ts +3 -3
  213. package/src/sqs/SQSConnection.ts +75 -75
  214. package/src/sqs/SQSPublisher.ts +93 -93
  215. package/src/sqs/SQSSubscriber.ts +157 -165
  216. package/src/sqs/__tests__/SQSPublisher.spec.ts +178 -178
  217. package/src/sqs/index.ts +3 -3
  218. package/src/types.ts +28 -29
  219. package/tsconfig.json +9 -0
  220. package/tsdown.config.ts +1 -1
  221. package/dist/BasicSubscriber-Ckf3BkxS.cjs.map +0 -1
  222. package/dist/BasicSubscriber-DPpJNUUY.mjs.map +0 -1
  223. package/dist/RabbitMQConnection-BN_GybOv.cjs.map +0 -1
  224. package/dist/RabbitMQConnection-eVOVS4Dl.mjs.map +0 -1
  225. package/dist/RabbitMQPublisher-BZX0edgL.mjs.map +0 -1
  226. package/dist/RabbitMQPublisher-CSCn6gMA.cjs.map +0 -1
  227. package/dist/RabbitMQSubscriber-B5I-hBaT.mjs.map +0 -1
  228. package/dist/RabbitMQSubscriber-Cj7qLIi6.cjs.map +0 -1
  229. package/dist/SNSConnection-CZz_U56V.cjs.map +0 -1
  230. package/dist/SNSConnection-DVEE3XoC.mjs.map +0 -1
  231. package/dist/SNSPublisher-DbWVH-g_.cjs.map +0 -1
  232. package/dist/SNSPublisher-Do-FMUyT.mjs.map +0 -1
  233. package/dist/SNSSubscriber-DpEwQ8Tb.cjs.map +0 -1
  234. package/dist/SNSSubscriber-e7eG48yJ.mjs.map +0 -1
  235. package/dist/SQSConnection-BBlDWZLU.mjs.map +0 -1
  236. package/dist/SQSConnection-DWYDtftQ.cjs.map +0 -1
  237. package/dist/SQSPublisher-B3lS2zbu.mjs.map +0 -1
  238. package/dist/SQSPublisher-nzbSaXSH.cjs.map +0 -1
  239. package/dist/SQSSubscriber-84pFnW1z.mjs.map +0 -1
  240. package/dist/SQSSubscriber-DcL9BbG1.cjs.map +0 -1
@@ -9,370 +9,370 @@ const RABBITMQ_URL = 'amqp://geekmidas:geekmidas@localhost:5672';
9
9
 
10
10
  // Helper to generate unique exchange names
11
11
  const uniqueExchange = () =>
12
- `test-exchange-${Date.now()}-${Math.random().toString(36).substring(7)}`;
12
+ `test-exchange-${Date.now()}-${Math.random().toString(36).substring(7)}`;
13
13
 
14
14
  describe('RabbitMQPublisher - Integration Tests', () => {
15
- describe('constructor', () => {
16
- it('should create instance with default configuration', () => {
17
- const connection = new RabbitMQConnection({
18
- url: RABBITMQ_URL,
19
- exchange: uniqueExchange(),
20
- });
21
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
22
-
23
- expect(publisher).toBeDefined();
24
- });
25
-
26
- it('should connect lazily on first publish', async () => {
27
- const testExchange = uniqueExchange();
28
- const connection = new RabbitMQConnection({
29
- url: RABBITMQ_URL,
30
- exchange: testExchange,
31
- });
32
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
33
-
34
- // Should not throw - connection happens on publish
35
- await publisher.publish([
36
- { type: 'user.created', payload: { userId: 'test' } },
37
- ]);
38
-
39
- await connection.close();
40
- });
41
-
42
- it('should work with custom exchange type', async () => {
43
- const testExchange = uniqueExchange();
44
- const connection = new RabbitMQConnection({
45
- url: RABBITMQ_URL,
46
- exchange: testExchange,
47
- exchangeType: 'direct',
48
- });
49
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
50
-
51
- await publisher.publish([
52
- { type: 'user.created', payload: { userId: 'test' } },
53
- ]);
54
-
55
- await connection.close();
56
- });
57
-
58
- it('should apply custom timeout', async () => {
59
- const testExchange = uniqueExchange();
60
- const connection = new RabbitMQConnection({
61
- url: RABBITMQ_URL,
62
- exchange: testExchange,
63
- timeout: 10000,
64
- });
65
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
66
-
67
- await publisher.publish([
68
- { type: 'user.created', payload: { userId: 'test' } },
69
- ]);
70
-
71
- await connection.close();
72
- });
73
- });
74
-
75
- describe('fromConnectionString', () => {
76
- it('should parse basic connection string with autoConnect=true', async () => {
77
- const testExchange = uniqueExchange();
78
- const publisher =
79
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
80
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true`,
81
- );
82
-
83
- // Should already be connected
84
- await publisher.publish([
85
- { type: 'user.created', payload: { userId: 'test' } },
86
- ]);
87
-
88
- await publisher.close();
89
- });
90
-
91
- it('should parse connection string with custom exchange', async () => {
92
- const testExchange = uniqueExchange();
93
- const publisher =
94
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
95
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true`,
96
- );
97
-
98
- await publisher.publish([
99
- { type: 'user.created', payload: { userId: 'test' } },
100
- ]);
101
-
102
- await publisher.close();
103
- });
104
-
105
- it('should parse connection string with type parameter', async () => {
106
- const testExchange = uniqueExchange();
107
- const publisher =
108
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
109
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&type=fanout&autoConnect=true`,
110
- );
111
-
112
- await publisher.publish([
113
- { type: 'user.created', payload: { userId: 'test' } },
114
- ]);
115
-
116
- await publisher.close();
117
- });
118
-
119
- it('should parse connection string with timeout parameter', async () => {
120
- const testExchange = uniqueExchange();
121
- const publisher =
122
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
123
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true&timeout=10000`,
124
- );
125
-
126
- await publisher.publish([
127
- { type: 'user.created', payload: { userId: 'test' } },
128
- ]);
129
-
130
- await publisher.close();
131
- });
132
-
133
- it('should not auto-connect by default', async () => {
134
- const testExchange = uniqueExchange();
135
- const publisher =
136
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
137
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}`,
138
- );
139
-
140
- // Should connect lazily on publish
141
- await publisher.publish([
142
- { type: 'user.created', payload: { userId: 'test' } },
143
- ]);
144
-
145
- await publisher.close();
146
- });
147
-
148
- it('should respect autoConnect=false', async () => {
149
- const testExchange = uniqueExchange();
150
- const publisher =
151
- await RabbitMQPublisher.fromConnectionString<TestMessage>(
152
- `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=false`,
153
- );
154
-
155
- // Should connect lazily on publish
156
- await publisher.publish([
157
- { type: 'user.created', payload: { userId: 'test' } },
158
- ]);
159
-
160
- await publisher.close();
161
- });
162
- });
163
-
164
- describe('publish', () => {
165
- it('should publish single message successfully', async () => {
166
- const testExchange = uniqueExchange();
167
- const connection = new RabbitMQConnection({
168
- url: RABBITMQ_URL,
169
- exchange: testExchange,
170
- });
171
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
172
-
173
- const messages: TestMessage[] = [
174
- {
175
- type: 'user.created',
176
- payload: { userId: '123', email: 'test@example.com' },
177
- },
178
- ];
179
-
180
- await publisher.publish(messages);
181
- await connection.close();
182
- });
183
-
184
- it('should publish multiple messages with different routing keys', async () => {
185
- const testExchange = uniqueExchange();
186
- const connection = new RabbitMQConnection({
187
- url: RABBITMQ_URL,
188
- exchange: testExchange,
189
- });
190
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
191
-
192
- const messages: TestMessage[] = [
193
- { type: 'user.created', payload: { userId: '1' } },
194
- { type: 'user.updated', payload: { userId: '2' } },
195
- { type: 'user.created', payload: { userId: '3' } },
196
- { type: 'user.updated', payload: { userId: '4' } },
197
- ];
198
-
199
- await publisher.publish(messages);
200
- await connection.close();
201
- });
202
-
203
- it('should serialize complex payloads to JSON', async () => {
204
- const testExchange = uniqueExchange();
205
- const connection = new RabbitMQConnection({
206
- url: RABBITMQ_URL,
207
- exchange: testExchange,
208
- });
209
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
210
-
211
- const complexPayload = {
212
- userId: '123',
213
- email: 'test@example.com',
214
- metadata: {
215
- createdAt: new Date().toISOString(),
216
- tags: ['new', 'active'],
217
- nested: {
218
- deep: {
219
- value: true,
220
- },
221
- },
222
- },
223
- };
224
-
225
- await publisher.publish([
226
- { type: 'user.created', payload: complexPayload },
227
- ]);
228
-
229
- await connection.close();
230
- });
231
-
232
- it('should handle large batch of messages', async () => {
233
- const testExchange = uniqueExchange();
234
- const connection = new RabbitMQConnection({
235
- url: RABBITMQ_URL,
236
- exchange: testExchange,
237
- });
238
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
239
-
240
- // Create 100 messages
241
- const messages: TestMessage[] = Array.from({ length: 100 }, (_, i) => ({
242
- type: i % 2 === 0 ? 'user.created' : 'user.updated',
243
- payload: { userId: `user-${i}`, index: i },
244
- }));
245
-
246
- await publisher.publish(messages);
247
- await connection.close();
248
- });
249
-
250
- it('should handle empty array', async () => {
251
- const testExchange = uniqueExchange();
252
- const connection = new RabbitMQConnection({
253
- url: RABBITMQ_URL,
254
- exchange: testExchange,
255
- });
256
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
257
-
258
- await publisher.publish([]);
259
- await connection.close();
260
- });
261
- });
262
-
263
- describe('close', () => {
264
- it('should close connection gracefully', async () => {
265
- const testExchange = uniqueExchange();
266
- const connection = new RabbitMQConnection({
267
- url: RABBITMQ_URL,
268
- exchange: testExchange,
269
- });
270
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
271
-
272
- await publisher.publish([
273
- { type: 'user.created', payload: { userId: 'test' } },
274
- ]);
275
-
276
- await connection.close();
277
- });
278
-
279
- it('should allow reconnection after close', async () => {
280
- const testExchange = uniqueExchange();
281
- const connection = new RabbitMQConnection({
282
- url: RABBITMQ_URL,
283
- exchange: testExchange,
284
- });
285
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
286
-
287
- await publisher.publish([
288
- { type: 'user.created', payload: { userId: '1' } },
289
- ]);
290
-
291
- await connection.close();
292
-
293
- // Should reconnect on next publish
294
- await publisher.publish([
295
- { type: 'user.created', payload: { userId: '2' } },
296
- ]);
297
-
298
- await connection.close();
299
- });
300
-
301
- it('should not throw error if already closed', async () => {
302
- const testExchange = uniqueExchange();
303
- const connection = new RabbitMQConnection({
304
- url: RABBITMQ_URL,
305
- exchange: testExchange,
306
- });
307
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
308
-
309
- await publisher.publish([
310
- { type: 'user.created', payload: { userId: 'test' } },
311
- ]);
312
-
313
- await connection.close();
314
- await expect(connection.close()).resolves.toBeUndefined();
315
- });
316
-
317
- it('should handle close without ever connecting', async () => {
318
- const testExchange = uniqueExchange();
319
- const connection = new RabbitMQConnection({
320
- url: RABBITMQ_URL,
321
- exchange: testExchange,
322
- });
323
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
324
-
325
- await expect(connection.close()).resolves.toBeUndefined();
326
- });
327
- });
328
-
329
- describe('connection error handling', () => {
330
- it('should throw error for invalid hostname', async () => {
331
- const testExchange = uniqueExchange();
332
- const connection = new RabbitMQConnection({
333
- url: 'amqp://geekmidas:geekmidas@invalid-host:5672',
334
- exchange: testExchange,
335
- timeout: 1000, // Short timeout for faster test
336
- });
337
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
338
-
339
- await expect(
340
- publisher.publish([
341
- { type: 'user.created', payload: { userId: '123' } },
342
- ]),
343
- ).rejects.toThrow();
344
- });
345
-
346
- it('should throw error for invalid credentials', async () => {
347
- const testExchange = uniqueExchange();
348
- const connection = new RabbitMQConnection({
349
- url: 'amqp://wrong:wrong@localhost:5672',
350
- exchange: testExchange,
351
- timeout: 1000, // Short timeout for faster test
352
- });
353
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
354
-
355
- await expect(
356
- publisher.publish([
357
- { type: 'user.created', payload: { userId: '123' } },
358
- ]),
359
- ).rejects.toThrow();
360
- });
361
-
362
- it('should throw error for invalid port', async () => {
363
- const testExchange = uniqueExchange();
364
- const connection = new RabbitMQConnection({
365
- url: 'amqp://geekmidas:geekmidas@localhost:9999',
366
- exchange: testExchange,
367
- timeout: 1000, // Short timeout for faster test
368
- });
369
- const publisher = new RabbitMQPublisher<TestMessage>(connection);
370
-
371
- await expect(
372
- publisher.publish([
373
- { type: 'user.created', payload: { userId: '123' } },
374
- ]),
375
- ).rejects.toThrow();
376
- });
377
- });
15
+ describe('constructor', () => {
16
+ it('should create instance with default configuration', () => {
17
+ const connection = new RabbitMQConnection({
18
+ url: RABBITMQ_URL,
19
+ exchange: uniqueExchange(),
20
+ });
21
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
22
+
23
+ expect(publisher).toBeDefined();
24
+ });
25
+
26
+ it('should connect lazily on first publish', async () => {
27
+ const testExchange = uniqueExchange();
28
+ const connection = new RabbitMQConnection({
29
+ url: RABBITMQ_URL,
30
+ exchange: testExchange,
31
+ });
32
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
33
+
34
+ // Should not throw - connection happens on publish
35
+ await publisher.publish([
36
+ { type: 'user.created', payload: { userId: 'test' } },
37
+ ]);
38
+
39
+ await connection.close();
40
+ });
41
+
42
+ it('should work with custom exchange type', async () => {
43
+ const testExchange = uniqueExchange();
44
+ const connection = new RabbitMQConnection({
45
+ url: RABBITMQ_URL,
46
+ exchange: testExchange,
47
+ exchangeType: 'direct',
48
+ });
49
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
50
+
51
+ await publisher.publish([
52
+ { type: 'user.created', payload: { userId: 'test' } },
53
+ ]);
54
+
55
+ await connection.close();
56
+ });
57
+
58
+ it('should apply custom timeout', async () => {
59
+ const testExchange = uniqueExchange();
60
+ const connection = new RabbitMQConnection({
61
+ url: RABBITMQ_URL,
62
+ exchange: testExchange,
63
+ timeout: 10000,
64
+ });
65
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
66
+
67
+ await publisher.publish([
68
+ { type: 'user.created', payload: { userId: 'test' } },
69
+ ]);
70
+
71
+ await connection.close();
72
+ });
73
+ });
74
+
75
+ describe('fromConnectionString', () => {
76
+ it('should parse basic connection string with autoConnect=true', async () => {
77
+ const testExchange = uniqueExchange();
78
+ const publisher =
79
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
80
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true`,
81
+ );
82
+
83
+ // Should already be connected
84
+ await publisher.publish([
85
+ { type: 'user.created', payload: { userId: 'test' } },
86
+ ]);
87
+
88
+ await publisher.close();
89
+ });
90
+
91
+ it('should parse connection string with custom exchange', async () => {
92
+ const testExchange = uniqueExchange();
93
+ const publisher =
94
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
95
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true`,
96
+ );
97
+
98
+ await publisher.publish([
99
+ { type: 'user.created', payload: { userId: 'test' } },
100
+ ]);
101
+
102
+ await publisher.close();
103
+ });
104
+
105
+ it('should parse connection string with type parameter', async () => {
106
+ const testExchange = uniqueExchange();
107
+ const publisher =
108
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
109
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&type=fanout&autoConnect=true`,
110
+ );
111
+
112
+ await publisher.publish([
113
+ { type: 'user.created', payload: { userId: 'test' } },
114
+ ]);
115
+
116
+ await publisher.close();
117
+ });
118
+
119
+ it('should parse connection string with timeout parameter', async () => {
120
+ const testExchange = uniqueExchange();
121
+ const publisher =
122
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
123
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=true&timeout=10000`,
124
+ );
125
+
126
+ await publisher.publish([
127
+ { type: 'user.created', payload: { userId: 'test' } },
128
+ ]);
129
+
130
+ await publisher.close();
131
+ });
132
+
133
+ it('should not auto-connect by default', async () => {
134
+ const testExchange = uniqueExchange();
135
+ const publisher =
136
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
137
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}`,
138
+ );
139
+
140
+ // Should connect lazily on publish
141
+ await publisher.publish([
142
+ { type: 'user.created', payload: { userId: 'test' } },
143
+ ]);
144
+
145
+ await publisher.close();
146
+ });
147
+
148
+ it('should respect autoConnect=false', async () => {
149
+ const testExchange = uniqueExchange();
150
+ const publisher =
151
+ await RabbitMQPublisher.fromConnectionString<TestMessage>(
152
+ `rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}&autoConnect=false`,
153
+ );
154
+
155
+ // Should connect lazily on publish
156
+ await publisher.publish([
157
+ { type: 'user.created', payload: { userId: 'test' } },
158
+ ]);
159
+
160
+ await publisher.close();
161
+ });
162
+ });
163
+
164
+ describe('publish', () => {
165
+ it('should publish single message successfully', async () => {
166
+ const testExchange = uniqueExchange();
167
+ const connection = new RabbitMQConnection({
168
+ url: RABBITMQ_URL,
169
+ exchange: testExchange,
170
+ });
171
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
172
+
173
+ const messages: TestMessage[] = [
174
+ {
175
+ type: 'user.created',
176
+ payload: { userId: '123', email: 'test@example.com' },
177
+ },
178
+ ];
179
+
180
+ await publisher.publish(messages);
181
+ await connection.close();
182
+ });
183
+
184
+ it('should publish multiple messages with different routing keys', async () => {
185
+ const testExchange = uniqueExchange();
186
+ const connection = new RabbitMQConnection({
187
+ url: RABBITMQ_URL,
188
+ exchange: testExchange,
189
+ });
190
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
191
+
192
+ const messages: TestMessage[] = [
193
+ { type: 'user.created', payload: { userId: '1' } },
194
+ { type: 'user.updated', payload: { userId: '2' } },
195
+ { type: 'user.created', payload: { userId: '3' } },
196
+ { type: 'user.updated', payload: { userId: '4' } },
197
+ ];
198
+
199
+ await publisher.publish(messages);
200
+ await connection.close();
201
+ });
202
+
203
+ it('should serialize complex payloads to JSON', async () => {
204
+ const testExchange = uniqueExchange();
205
+ const connection = new RabbitMQConnection({
206
+ url: RABBITMQ_URL,
207
+ exchange: testExchange,
208
+ });
209
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
210
+
211
+ const complexPayload = {
212
+ userId: '123',
213
+ email: 'test@example.com',
214
+ metadata: {
215
+ createdAt: new Date().toISOString(),
216
+ tags: ['new', 'active'],
217
+ nested: {
218
+ deep: {
219
+ value: true,
220
+ },
221
+ },
222
+ },
223
+ };
224
+
225
+ await publisher.publish([
226
+ { type: 'user.created', payload: complexPayload },
227
+ ]);
228
+
229
+ await connection.close();
230
+ });
231
+
232
+ it('should handle large batch of messages', async () => {
233
+ const testExchange = uniqueExchange();
234
+ const connection = new RabbitMQConnection({
235
+ url: RABBITMQ_URL,
236
+ exchange: testExchange,
237
+ });
238
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
239
+
240
+ // Create 100 messages
241
+ const messages: TestMessage[] = Array.from({ length: 100 }, (_, i) => ({
242
+ type: i % 2 === 0 ? 'user.created' : 'user.updated',
243
+ payload: { userId: `user-${i}`, index: i },
244
+ }));
245
+
246
+ await publisher.publish(messages);
247
+ await connection.close();
248
+ });
249
+
250
+ it('should handle empty array', async () => {
251
+ const testExchange = uniqueExchange();
252
+ const connection = new RabbitMQConnection({
253
+ url: RABBITMQ_URL,
254
+ exchange: testExchange,
255
+ });
256
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
257
+
258
+ await publisher.publish([]);
259
+ await connection.close();
260
+ });
261
+ });
262
+
263
+ describe('close', () => {
264
+ it('should close connection gracefully', async () => {
265
+ const testExchange = uniqueExchange();
266
+ const connection = new RabbitMQConnection({
267
+ url: RABBITMQ_URL,
268
+ exchange: testExchange,
269
+ });
270
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
271
+
272
+ await publisher.publish([
273
+ { type: 'user.created', payload: { userId: 'test' } },
274
+ ]);
275
+
276
+ await connection.close();
277
+ });
278
+
279
+ it('should allow reconnection after close', async () => {
280
+ const testExchange = uniqueExchange();
281
+ const connection = new RabbitMQConnection({
282
+ url: RABBITMQ_URL,
283
+ exchange: testExchange,
284
+ });
285
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
286
+
287
+ await publisher.publish([
288
+ { type: 'user.created', payload: { userId: '1' } },
289
+ ]);
290
+
291
+ await connection.close();
292
+
293
+ // Should reconnect on next publish
294
+ await publisher.publish([
295
+ { type: 'user.created', payload: { userId: '2' } },
296
+ ]);
297
+
298
+ await connection.close();
299
+ });
300
+
301
+ it('should not throw error if already closed', async () => {
302
+ const testExchange = uniqueExchange();
303
+ const connection = new RabbitMQConnection({
304
+ url: RABBITMQ_URL,
305
+ exchange: testExchange,
306
+ });
307
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
308
+
309
+ await publisher.publish([
310
+ { type: 'user.created', payload: { userId: 'test' } },
311
+ ]);
312
+
313
+ await connection.close();
314
+ await expect(connection.close()).resolves.toBeUndefined();
315
+ });
316
+
317
+ it('should handle close without ever connecting', async () => {
318
+ const testExchange = uniqueExchange();
319
+ const connection = new RabbitMQConnection({
320
+ url: RABBITMQ_URL,
321
+ exchange: testExchange,
322
+ });
323
+ const _publisher = new RabbitMQPublisher<TestMessage>(connection);
324
+
325
+ await expect(connection.close()).resolves.toBeUndefined();
326
+ });
327
+ });
328
+
329
+ describe('connection error handling', () => {
330
+ it('should throw error for invalid hostname', async () => {
331
+ const testExchange = uniqueExchange();
332
+ const connection = new RabbitMQConnection({
333
+ url: 'amqp://geekmidas:geekmidas@invalid-host:5672',
334
+ exchange: testExchange,
335
+ timeout: 1000, // Short timeout for faster test
336
+ });
337
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
338
+
339
+ await expect(
340
+ publisher.publish([
341
+ { type: 'user.created', payload: { userId: '123' } },
342
+ ]),
343
+ ).rejects.toThrow();
344
+ });
345
+
346
+ it('should throw error for invalid credentials', async () => {
347
+ const testExchange = uniqueExchange();
348
+ const connection = new RabbitMQConnection({
349
+ url: 'amqp://wrong:wrong@localhost:5672',
350
+ exchange: testExchange,
351
+ timeout: 1000, // Short timeout for faster test
352
+ });
353
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
354
+
355
+ await expect(
356
+ publisher.publish([
357
+ { type: 'user.created', payload: { userId: '123' } },
358
+ ]),
359
+ ).rejects.toThrow();
360
+ });
361
+
362
+ it('should throw error for invalid port', async () => {
363
+ const testExchange = uniqueExchange();
364
+ const connection = new RabbitMQConnection({
365
+ url: 'amqp://geekmidas:geekmidas@localhost:9999',
366
+ exchange: testExchange,
367
+ timeout: 1000, // Short timeout for faster test
368
+ });
369
+ const publisher = new RabbitMQPublisher<TestMessage>(connection);
370
+
371
+ await expect(
372
+ publisher.publish([
373
+ { type: 'user.created', payload: { userId: '123' } },
374
+ ]),
375
+ ).rejects.toThrow();
376
+ });
377
+ });
378
378
  });