@geekmidas/events 10.0.0-alpha.98 → 10.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.
- package/CHANGELOG.md +116 -0
- package/README.md +1 -46
- package/dist/BasicConnection-CQsJpx2J.d.cts +27 -0
- package/dist/BasicConnection-CQsJpx2J.d.cts.map +1 -0
- package/dist/BasicConnection-CxfNEvlb.cjs +48 -0
- package/dist/BasicConnection-CxfNEvlb.cjs.map +1 -0
- package/dist/BasicConnection-DcRelT64.d.mts +27 -0
- package/dist/BasicConnection-DcRelT64.d.mts.map +1 -0
- package/dist/BasicConnection-hl-Ogz3a.mjs +42 -0
- package/dist/BasicConnection-hl-Ogz3a.mjs.map +1 -0
- package/dist/BasicPublisher-C-hMX2Hy.d.mts +14 -0
- package/dist/BasicPublisher-C-hMX2Hy.d.mts.map +1 -0
- package/dist/BasicPublisher-CGMXg2I2.d.cts +14 -0
- package/dist/BasicPublisher-CGMXg2I2.d.cts.map +1 -0
- package/dist/BasicPublisher-CXAVKxgq.cjs +20 -0
- package/dist/BasicPublisher-CXAVKxgq.cjs.map +1 -0
- package/dist/BasicPublisher-DogbeHAH.mjs +14 -0
- package/dist/BasicPublisher-DogbeHAH.mjs.map +1 -0
- package/dist/BasicSubscriber-BJSZN22M.mjs +16 -0
- package/dist/BasicSubscriber-BJSZN22M.mjs.map +1 -0
- package/dist/BasicSubscriber-HzSJ_MbB.d.mts +14 -0
- package/dist/BasicSubscriber-HzSJ_MbB.d.mts.map +1 -0
- package/dist/BasicSubscriber-mVJRMXhZ.cjs +22 -0
- package/dist/BasicSubscriber-mVJRMXhZ.cjs.map +1 -0
- package/dist/BasicSubscriber-uW3IOyBj.d.cts +14 -0
- package/dist/BasicSubscriber-uW3IOyBj.d.cts.map +1 -0
- package/dist/EventConnection-4niMI6D8.d.mts +13 -0
- package/dist/EventConnection-4niMI6D8.d.mts.map +1 -0
- package/dist/EventConnection-BkA9FSVL.cjs +45 -0
- package/dist/EventConnection-BkA9FSVL.cjs.map +1 -0
- package/dist/EventConnection-Kr32GAzq.mjs +40 -0
- package/dist/EventConnection-Kr32GAzq.mjs.map +1 -0
- package/dist/EventConnection-dP42P87q.d.cts +13 -0
- package/dist/EventConnection-dP42P87q.d.cts.map +1 -0
- package/dist/EventConnection.cjs +5 -0
- package/dist/EventConnection.d.cts +3 -0
- package/dist/EventConnection.d.mts +3 -0
- package/dist/EventConnection.mjs +4 -0
- package/dist/PgBossConnection-B71ssr72.cjs +80 -0
- package/dist/PgBossConnection-B71ssr72.cjs.map +1 -0
- package/dist/PgBossConnection-Bj_Wo1lQ.mjs +74 -0
- package/dist/PgBossConnection-Bj_Wo1lQ.mjs.map +1 -0
- package/dist/PgBossConnection-DCfLGoHx.d.mts +32 -0
- package/dist/PgBossConnection-DCfLGoHx.d.mts.map +1 -0
- package/dist/PgBossConnection-oto_CAbP.d.cts +32 -0
- package/dist/PgBossConnection-oto_CAbP.d.cts.map +1 -0
- package/dist/PgBossPublisher-Bwo7qSoH.mjs +35 -0
- package/dist/PgBossPublisher-Bwo7qSoH.mjs.map +1 -0
- package/dist/PgBossPublisher-CqjigBVC.d.mts +20 -0
- package/dist/PgBossPublisher-CqjigBVC.d.mts.map +1 -0
- package/dist/PgBossPublisher-FTdYh58W.cjs +41 -0
- package/dist/PgBossPublisher-FTdYh58W.cjs.map +1 -0
- package/dist/PgBossPublisher-JIiB1zpA.d.cts +20 -0
- package/dist/PgBossPublisher-JIiB1zpA.d.cts.map +1 -0
- package/dist/PgBossSubscriber-BUiB1JKf.d.mts +24 -0
- package/dist/PgBossSubscriber-BUiB1JKf.d.mts.map +1 -0
- package/dist/PgBossSubscriber-BubVfuWm.cjs +52 -0
- package/dist/PgBossSubscriber-BubVfuWm.cjs.map +1 -0
- package/dist/PgBossSubscriber-Cozijfdj.d.cts +24 -0
- package/dist/PgBossSubscriber-Cozijfdj.d.cts.map +1 -0
- package/dist/PgBossSubscriber-DopATe80.mjs +46 -0
- package/dist/PgBossSubscriber-DopATe80.mjs.map +1 -0
- package/dist/Publisher-CKloIGh6.cjs +79 -0
- package/dist/Publisher-CKloIGh6.cjs.map +1 -0
- package/dist/Publisher-ChLTrUeP.mjs +74 -0
- package/dist/Publisher-ChLTrUeP.mjs.map +1 -0
- package/dist/Publisher-DDee6xau.d.cts +21 -0
- package/dist/Publisher-DDee6xau.d.cts.map +1 -0
- package/dist/Publisher-VHumMkrP.d.mts +21 -0
- package/dist/Publisher-VHumMkrP.d.mts.map +1 -0
- package/dist/Publisher.cjs +4 -0
- package/dist/Publisher.d.cts +3 -0
- package/dist/Publisher.d.mts +3 -0
- package/dist/Publisher.mjs +4 -0
- package/dist/RabbitMQConnection-BtKZjtZY.mjs +107 -0
- package/dist/RabbitMQConnection-BtKZjtZY.mjs.map +1 -0
- package/dist/RabbitMQConnection-DV9t3VYp.d.mts +44 -0
- package/dist/RabbitMQConnection-DV9t3VYp.d.mts.map +1 -0
- package/dist/RabbitMQConnection-DmMMosT4.cjs +113 -0
- package/dist/RabbitMQConnection-DmMMosT4.cjs.map +1 -0
- package/dist/RabbitMQConnection-jNME_eR7.d.cts +44 -0
- package/dist/RabbitMQConnection-jNME_eR7.d.cts.map +1 -0
- package/dist/RabbitMQPublisher-C94q6g8q.cjs +45 -0
- package/dist/RabbitMQPublisher-C94q6g8q.cjs.map +1 -0
- package/dist/RabbitMQPublisher-DKmgwqVj.d.mts +25 -0
- package/dist/RabbitMQPublisher-DKmgwqVj.d.mts.map +1 -0
- package/dist/RabbitMQPublisher-d257OHLa.d.cts +25 -0
- package/dist/RabbitMQPublisher-d257OHLa.d.cts.map +1 -0
- package/dist/RabbitMQPublisher-yUqWNq-P.mjs +39 -0
- package/dist/RabbitMQPublisher-yUqWNq-P.mjs.map +1 -0
- package/dist/RabbitMQSubscriber-BF7JGfYm.d.cts +27 -0
- package/dist/RabbitMQSubscriber-BF7JGfYm.d.cts.map +1 -0
- package/dist/RabbitMQSubscriber-BWniDtFs.mjs +56 -0
- package/dist/RabbitMQSubscriber-BWniDtFs.mjs.map +1 -0
- package/dist/RabbitMQSubscriber-CdbUy5mB.d.mts +27 -0
- package/dist/RabbitMQSubscriber-CdbUy5mB.d.mts.map +1 -0
- package/dist/RabbitMQSubscriber-DGEO-clQ.cjs +62 -0
- package/dist/RabbitMQSubscriber-DGEO-clQ.cjs.map +1 -0
- package/dist/SNSConnection-CAcbLQOy.cjs +76 -0
- package/dist/SNSConnection-CAcbLQOy.cjs.map +1 -0
- package/dist/SNSConnection-CG4iEwA8.d.mts +41 -0
- package/dist/SNSConnection-CG4iEwA8.d.mts.map +1 -0
- package/dist/SNSConnection-CVjH93lb.mjs +70 -0
- package/dist/SNSConnection-CVjH93lb.mjs.map +1 -0
- package/dist/SNSConnection-Dol9FuxA.d.cts +41 -0
- package/dist/SNSConnection-Dol9FuxA.d.cts.map +1 -0
- package/dist/SNSPublisher-CjlMS3Z2.mjs +41 -0
- package/dist/SNSPublisher-CjlMS3Z2.mjs.map +1 -0
- package/dist/SNSPublisher-D50dPCEh.d.mts +22 -0
- package/dist/SNSPublisher-D50dPCEh.d.mts.map +1 -0
- package/dist/SNSPublisher-DQunY4NM.d.cts +22 -0
- package/dist/SNSPublisher-DQunY4NM.d.cts.map +1 -0
- package/dist/SNSPublisher-DV_8GGsi.cjs +47 -0
- package/dist/SNSPublisher-DV_8GGsi.cjs.map +1 -0
- package/dist/SNSSubscriber-BWaCQFl6.mjs +139 -0
- package/dist/SNSSubscriber-BWaCQFl6.mjs.map +1 -0
- package/dist/SNSSubscriber-CUgHK4W2.d.mts +55 -0
- package/dist/SNSSubscriber-CUgHK4W2.d.mts.map +1 -0
- package/dist/SNSSubscriber-ZE_-Hsps.cjs +145 -0
- package/dist/SNSSubscriber-ZE_-Hsps.cjs.map +1 -0
- package/dist/SNSSubscriber-ZGJjhXFQ.d.cts +55 -0
- package/dist/SNSSubscriber-ZGJjhXFQ.d.cts.map +1 -0
- package/dist/SQSConnection-BtEkDha8.d.cts +41 -0
- package/dist/SQSConnection-BtEkDha8.d.cts.map +1 -0
- package/dist/SQSConnection-CT3S7_zP.mjs +70 -0
- package/dist/SQSConnection-CT3S7_zP.mjs.map +1 -0
- package/dist/SQSConnection-DVy43GCV.d.mts +41 -0
- package/dist/SQSConnection-DVy43GCV.d.mts.map +1 -0
- package/dist/SQSConnection-Y0mdVTcB.cjs +76 -0
- package/dist/SQSConnection-Y0mdVTcB.cjs.map +1 -0
- package/dist/SQSPublisher-B-32CC4G.mjs +57 -0
- package/dist/SQSPublisher-B-32CC4G.mjs.map +1 -0
- package/dist/SQSPublisher-CgUduk6H.cjs +63 -0
- package/dist/SQSPublisher-CgUduk6H.cjs.map +1 -0
- package/dist/SQSPublisher-kyl5HW3N.d.cts +25 -0
- package/dist/SQSPublisher-kyl5HW3N.d.cts.map +1 -0
- package/dist/SQSPublisher-qDE5Fp-N.d.mts +25 -0
- package/dist/SQSPublisher-qDE5Fp-N.d.mts.map +1 -0
- package/dist/SQSSubscriber-C4UA2hKq.cjs +120 -0
- package/dist/SQSSubscriber-C4UA2hKq.cjs.map +1 -0
- package/dist/SQSSubscriber-CDvaG4ij.d.cts +44 -0
- package/dist/SQSSubscriber-CDvaG4ij.d.cts.map +1 -0
- package/dist/SQSSubscriber-CQdSFzpe.mjs +114 -0
- package/dist/SQSSubscriber-CQdSFzpe.mjs.map +1 -0
- package/dist/SQSSubscriber-JfFuAAoP.d.mts +44 -0
- package/dist/SQSSubscriber-JfFuAAoP.d.mts.map +1 -0
- package/dist/Subscriber-CG_QUQZs.d.cts +21 -0
- package/dist/Subscriber-CG_QUQZs.d.cts.map +1 -0
- package/dist/Subscriber-CghW0A02.cjs +88 -0
- package/dist/Subscriber-CghW0A02.cjs.map +1 -0
- package/dist/Subscriber-DiYHmuF0.d.mts +21 -0
- package/dist/Subscriber-DiYHmuF0.d.mts.map +1 -0
- package/dist/Subscriber-bnkFtSvt.mjs +83 -0
- package/dist/Subscriber-bnkFtSvt.mjs.map +1 -0
- package/dist/Subscriber.cjs +4 -0
- package/dist/Subscriber.d.cts +3 -0
- package/dist/Subscriber.d.mts +3 -0
- package/dist/Subscriber.mjs +4 -0
- package/dist/basic/BasicConnection.cjs +4 -0
- package/dist/basic/BasicConnection.d.cts +3 -0
- package/dist/basic/BasicConnection.d.mts +3 -0
- package/dist/basic/BasicConnection.mjs +4 -0
- package/dist/basic/BasicPublisher.cjs +3 -0
- package/dist/basic/BasicPublisher.d.cts +4 -0
- package/dist/basic/BasicPublisher.d.mts +4 -0
- package/dist/basic/BasicPublisher.mjs +3 -0
- package/dist/basic/BasicSubscriber.cjs +3 -0
- package/dist/basic/BasicSubscriber.d.cts +4 -0
- package/dist/basic/BasicSubscriber.d.mts +4 -0
- package/dist/basic/BasicSubscriber.mjs +3 -0
- package/dist/basic/index.cjs +7 -100
- package/dist/basic/index.d.cts +5 -45
- package/dist/basic/index.d.mts +5 -45
- package/dist/basic/index.mjs +5 -96
- package/dist/{rolldown-runtime-C0BPl7ul.cjs → chunk-CUT6urMc.cjs} +10 -23
- package/dist/index.cjs +8 -87
- package/dist/index.d.cts +5 -102
- package/dist/index.d.mts +5 -102
- package/dist/index.mjs +5 -71
- package/dist/pgboss/PgBossConnection.cjs +4 -0
- package/dist/pgboss/PgBossConnection.d.cts +3 -0
- package/dist/pgboss/PgBossConnection.d.mts +3 -0
- package/dist/pgboss/PgBossConnection.mjs +4 -0
- package/dist/pgboss/PgBossPublisher.cjs +3 -0
- package/dist/pgboss/PgBossPublisher.d.cts +4 -0
- package/dist/pgboss/PgBossPublisher.d.mts +4 -0
- package/dist/pgboss/PgBossPublisher.mjs +3 -0
- package/dist/pgboss/PgBossSubscriber.cjs +3 -0
- package/dist/pgboss/PgBossSubscriber.d.cts +4 -0
- package/dist/pgboss/PgBossSubscriber.d.mts +4 -0
- package/dist/pgboss/PgBossSubscriber.mjs +3 -0
- package/dist/pgboss/index.cjs +7 -247
- package/dist/pgboss/index.d.cts +5 -107
- package/dist/pgboss/index.d.mts +5 -107
- package/dist/pgboss/index.mjs +5 -240
- package/dist/rabbitmq/RabbitMQConnection.cjs +4 -0
- package/dist/rabbitmq/RabbitMQConnection.d.cts +3 -0
- package/dist/rabbitmq/RabbitMQConnection.d.mts +3 -0
- package/dist/rabbitmq/RabbitMQConnection.mjs +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.cjs +3 -0
- package/dist/rabbitmq/RabbitMQPublisher.d.cts +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.d.mts +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.mjs +3 -0
- package/dist/rabbitmq/RabbitMQSubscriber.cjs +3 -0
- package/dist/rabbitmq/RabbitMQSubscriber.d.cts +4 -0
- package/dist/rabbitmq/RabbitMQSubscriber.d.mts +4 -0
- package/dist/rabbitmq/RabbitMQSubscriber.mjs +3 -0
- package/dist/rabbitmq/index.cjs +7 -243
- package/dist/rabbitmq/index.d.cts +5 -92
- package/dist/rabbitmq/index.d.mts +5 -92
- package/dist/rabbitmq/index.mjs +5 -237
- package/dist/sns/SNSConnection.cjs +4 -0
- package/dist/sns/SNSConnection.d.cts +3 -0
- package/dist/sns/SNSConnection.d.mts +3 -0
- package/dist/sns/SNSConnection.mjs +4 -0
- package/dist/sns/SNSPublisher.cjs +3 -0
- package/dist/sns/SNSPublisher.d.cts +4 -0
- package/dist/sns/SNSPublisher.d.mts +4 -0
- package/dist/sns/SNSPublisher.mjs +3 -0
- package/dist/sns/SNSSubscriber.cjs +6 -0
- package/dist/sns/SNSSubscriber.d.cts +4 -0
- package/dist/sns/SNSSubscriber.d.mts +4 -0
- package/dist/sns/SNSSubscriber.mjs +6 -0
- package/dist/sns/index.cjs +9 -551
- package/dist/sns/index.d.cts +5 -273
- package/dist/sns/index.d.mts +5 -273
- package/dist/sns/index.mjs +7 -527
- package/dist/sqs/SQSConnection.cjs +4 -0
- package/dist/sqs/SQSConnection.d.cts +3 -0
- package/dist/sqs/SQSConnection.d.mts +3 -0
- package/dist/sqs/SQSConnection.mjs +4 -0
- package/dist/sqs/SQSPublisher.cjs +3 -0
- package/dist/sqs/SQSPublisher.d.cts +4 -0
- package/dist/sqs/SQSPublisher.d.mts +4 -0
- package/dist/sqs/SQSPublisher.mjs +3 -0
- package/dist/sqs/SQSSubscriber.cjs +3 -0
- package/dist/sqs/SQSSubscriber.d.cts +4 -0
- package/dist/sqs/SQSSubscriber.d.mts +4 -0
- package/dist/sqs/SQSSubscriber.mjs +3 -0
- package/dist/sqs/index.cjs +7 -35
- package/dist/sqs/index.d.cts +5 -118
- package/dist/sqs/index.d.mts +5 -118
- package/dist/sqs/index.mjs +5 -24
- package/dist/types-BrdcSEnd.mjs +18 -0
- package/dist/types-BrdcSEnd.mjs.map +1 -0
- package/dist/types-Byv8N9ma.cjs +24 -0
- package/dist/types-Byv8N9ma.cjs.map +1 -0
- package/dist/types-Dh9Jyinx.d.mts +67 -0
- package/dist/types-Dh9Jyinx.d.mts.map +1 -0
- package/dist/types-Dj23od3e.d.cts +67 -0
- package/dist/types-Dj23od3e.d.cts.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/package.json +12 -40
- package/src/EventConnection.ts +43 -0
- package/src/Publisher.ts +98 -0
- package/src/Subscriber.ts +113 -0
- package/src/__tests__/EventConnection.spec.ts +42 -0
- package/src/__tests__/Publisher.spec.ts +96 -0
- package/src/__tests__/Subscriber.spec.ts +109 -0
- package/src/basic/BasicConnection.ts +47 -0
- package/src/basic/BasicPublisher.ts +15 -0
- package/src/basic/BasicSubscriber.ts +21 -0
- package/src/basic/__tests__/BasicSubscriber.spec.ts +166 -0
- package/src/basic/index.ts +3 -0
- package/src/index.ts +25 -0
- package/src/pgboss/PgBossConnection.ts +91 -0
- package/src/pgboss/PgBossPublisher.ts +49 -0
- package/src/pgboss/PgBossSubscriber.ts +81 -0
- package/src/pgboss/__tests__/pgboss.spec.ts +196 -0
- package/src/pgboss/__tests__/setup.ts +21 -0
- package/src/pgboss/index.ts +5 -0
- package/src/rabbitmq/RabbitMQConnection.ts +148 -0
- package/src/rabbitmq/RabbitMQPublisher.ts +67 -0
- package/src/rabbitmq/RabbitMQSubscriber.ts +111 -0
- package/src/rabbitmq/__tests__/RabbitMQPublisher.spec.ts +378 -0
- package/src/rabbitmq/__tests__/RabbitMQSubscriber.spec.ts +292 -0
- package/src/rabbitmq/index.ts +6 -0
- package/src/sns/SNSConnection.ts +98 -0
- package/src/sns/SNSPublisher.ts +62 -0
- package/src/sns/SNSSubscriber.ts +218 -0
- package/src/sns/__tests__/SNS-SQS-Integration.spec.ts +389 -0
- package/src/sns/__tests__/SNSPublisher.spec.ts +449 -0
- package/src/sns/__tests__/SNSSubscriber.spec.ts +527 -0
- package/src/sns/index.ts +6 -0
- package/src/sqs/SQSConnection.ts +97 -0
- package/src/sqs/SQSPublisher.ts +105 -0
- package/src/sqs/SQSSubscriber.ts +181 -0
- package/src/sqs/__tests__/SQSPublisher.spec.ts +189 -0
- package/src/sqs/index.ts +6 -0
- package/src/types.ts +76 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +10 -0
- package/dist/SQSSubscriber-BEJBfNTe.mjs +0 -264
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +0 -1
- package/dist/SQSSubscriber-COTqWvOk.cjs +0 -288
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +0 -1
- package/dist/basic/index.cjs.map +0 -1
- package/dist/basic/index.d.cts.map +0 -1
- package/dist/basic/index.d.mts.map +0 -1
- package/dist/basic/index.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/pgboss/index.cjs.map +0 -1
- package/dist/pgboss/index.d.cts.map +0 -1
- package/dist/pgboss/index.d.mts.map +0 -1
- package/dist/pgboss/index.mjs.map +0 -1
- package/dist/rabbitmq/index.cjs.map +0 -1
- package/dist/rabbitmq/index.d.cts.map +0 -1
- package/dist/rabbitmq/index.d.mts.map +0 -1
- package/dist/rabbitmq/index.mjs.map +0 -1
- package/dist/registry-DIx25Q5s.d.cts +0 -255
- package/dist/registry-DIx25Q5s.d.cts.map +0 -1
- package/dist/registry-DIx25Q5s.d.mts +0 -255
- package/dist/registry-DIx25Q5s.d.mts.map +0 -1
- package/dist/registry-DXLY1Xf6.mjs +0 -99
- package/dist/registry-DXLY1Xf6.mjs.map +0 -1
- package/dist/registry-DlT36229.cjs +0 -122
- package/dist/registry-DlT36229.cjs.map +0 -1
- package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
- package/dist/sns/index.cjs.map +0 -1
- package/dist/sns/index.d.cts.map +0 -1
- package/dist/sns/index.d.mts.map +0 -1
- package/dist/sns/index.mjs.map +0 -1
- package/dist/sns/snsUrl.cjs +0 -92
- package/dist/sns/snsUrl.cjs.map +0 -1
- package/dist/sns/snsUrl.d.cts +0 -57
- package/dist/sns/snsUrl.d.cts.map +0 -1
- package/dist/sns/snsUrl.d.mts +0 -57
- package/dist/sns/snsUrl.d.mts.map +0 -1
- package/dist/sns/snsUrl.mjs +0 -82
- package/dist/sns/snsUrl.mjs.map +0 -1
- package/dist/sqs/index.cjs.map +0 -1
- package/dist/sqs/index.d.cts.map +0 -1
- package/dist/sqs/index.d.mts.map +0 -1
- package/dist/sqs/index.mjs.map +0 -1
- package/dist/sqs/sqsUrl.cjs +0 -93
- package/dist/sqs/sqsUrl.cjs.map +0 -1
- package/dist/sqs/sqsUrl.d.cts +0 -56
- package/dist/sqs/sqsUrl.d.cts.map +0 -1
- package/dist/sqs/sqsUrl.d.mts +0 -56
- package/dist/sqs/sqsUrl.d.mts.map +0 -1
- package/dist/sqs/sqsUrl.mjs +0 -83
- package/dist/sqs/sqsUrl.mjs.map +0 -1
- package/dist/telemetry-DG3l807O.cjs +0 -309
- package/dist/telemetry-DG3l807O.cjs.map +0 -1
- package/dist/telemetry-DjjgJMul.mjs +0 -244
- package/dist/telemetry-DjjgJMul.mjs.map +0 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { PublishableMessage } from '../../types';
|
|
3
|
+
import { RabbitMQConnection } from '../RabbitMQConnection';
|
|
4
|
+
import { RabbitMQPublisher } from '../RabbitMQPublisher';
|
|
5
|
+
import { RabbitMQSubscriber } from '../RabbitMQSubscriber';
|
|
6
|
+
|
|
7
|
+
type TestMessage = PublishableMessage<'user.created' | 'user.updated', any>;
|
|
8
|
+
|
|
9
|
+
const RABBITMQ_URL = 'amqp://geekmidas:geekmidas@localhost:5672';
|
|
10
|
+
|
|
11
|
+
// Helper to generate unique exchange names
|
|
12
|
+
const uniqueExchange = () =>
|
|
13
|
+
`test-exchange-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
14
|
+
|
|
15
|
+
describe('RabbitMQSubscriber - Integration Tests', () => {
|
|
16
|
+
it('should receive published messages', async () => {
|
|
17
|
+
const testExchange = uniqueExchange();
|
|
18
|
+
const connection = new RabbitMQConnection({
|
|
19
|
+
url: RABBITMQ_URL,
|
|
20
|
+
exchange: testExchange,
|
|
21
|
+
});
|
|
22
|
+
await connection.connect();
|
|
23
|
+
|
|
24
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
25
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection);
|
|
26
|
+
|
|
27
|
+
const receivedMessages: TestMessage[] = [];
|
|
28
|
+
|
|
29
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
30
|
+
receivedMessages.push(message);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Wait a bit for consumer to be ready
|
|
34
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
35
|
+
|
|
36
|
+
await publisher.publish([
|
|
37
|
+
{ type: 'user.created', payload: { userId: '123' } },
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
// Wait for message to be processed
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
42
|
+
|
|
43
|
+
expect(receivedMessages).toHaveLength(1);
|
|
44
|
+
expect(receivedMessages[0].payload.userId).toBe('123');
|
|
45
|
+
|
|
46
|
+
await connection.close();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should receive multiple messages', async () => {
|
|
50
|
+
const testExchange = uniqueExchange();
|
|
51
|
+
const connection = new RabbitMQConnection({
|
|
52
|
+
url: RABBITMQ_URL,
|
|
53
|
+
exchange: testExchange,
|
|
54
|
+
});
|
|
55
|
+
await connection.connect();
|
|
56
|
+
|
|
57
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
58
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection);
|
|
59
|
+
|
|
60
|
+
const receivedMessages: TestMessage[] = [];
|
|
61
|
+
|
|
62
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
63
|
+
receivedMessages.push(message);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
67
|
+
|
|
68
|
+
await publisher.publish([
|
|
69
|
+
{ type: 'user.created', payload: { userId: '1' } },
|
|
70
|
+
{ type: 'user.created', payload: { userId: '2' } },
|
|
71
|
+
{ type: 'user.created', payload: { userId: '3' } },
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
75
|
+
|
|
76
|
+
expect(receivedMessages).toHaveLength(3);
|
|
77
|
+
|
|
78
|
+
await connection.close();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should only receive subscribed message types', async () => {
|
|
82
|
+
const testExchange = uniqueExchange();
|
|
83
|
+
const connection = new RabbitMQConnection({
|
|
84
|
+
url: RABBITMQ_URL,
|
|
85
|
+
exchange: testExchange,
|
|
86
|
+
});
|
|
87
|
+
await connection.connect();
|
|
88
|
+
|
|
89
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
90
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection);
|
|
91
|
+
|
|
92
|
+
const receivedMessages: TestMessage[] = [];
|
|
93
|
+
|
|
94
|
+
// Only subscribe to user.created
|
|
95
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
96
|
+
receivedMessages.push(message);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
100
|
+
|
|
101
|
+
await publisher.publish([
|
|
102
|
+
{ type: 'user.created', payload: { userId: '1' } },
|
|
103
|
+
{ type: 'user.updated', payload: { userId: '2' } },
|
|
104
|
+
{ type: 'user.created', payload: { userId: '3' } },
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
108
|
+
|
|
109
|
+
expect(receivedMessages).toHaveLength(2);
|
|
110
|
+
expect(receivedMessages.every((m) => m.payload.userId !== '2')).toBe(true);
|
|
111
|
+
|
|
112
|
+
await connection.close();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should subscribe to multiple message types', async () => {
|
|
116
|
+
const testExchange = uniqueExchange();
|
|
117
|
+
const connection = new RabbitMQConnection({
|
|
118
|
+
url: RABBITMQ_URL,
|
|
119
|
+
exchange: testExchange,
|
|
120
|
+
});
|
|
121
|
+
await connection.connect();
|
|
122
|
+
|
|
123
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
124
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection);
|
|
125
|
+
|
|
126
|
+
const receivedMessages: TestMessage[] = [];
|
|
127
|
+
|
|
128
|
+
await subscriber.subscribe(
|
|
129
|
+
['user.created', 'user.updated'],
|
|
130
|
+
async (message) => {
|
|
131
|
+
receivedMessages.push(message);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
136
|
+
|
|
137
|
+
await publisher.publish([
|
|
138
|
+
{ type: 'user.created', payload: { userId: '1' } },
|
|
139
|
+
{ type: 'user.updated', payload: { userId: '2' } },
|
|
140
|
+
{ type: 'user.created', payload: { userId: '3' } },
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
144
|
+
|
|
145
|
+
expect(receivedMessages).toHaveLength(3);
|
|
146
|
+
|
|
147
|
+
await connection.close();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should handle message processing errors with nack', async () => {
|
|
151
|
+
const testExchange = uniqueExchange();
|
|
152
|
+
const connection = new RabbitMQConnection({
|
|
153
|
+
url: RABBITMQ_URL,
|
|
154
|
+
exchange: testExchange,
|
|
155
|
+
});
|
|
156
|
+
await connection.connect();
|
|
157
|
+
|
|
158
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
159
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection);
|
|
160
|
+
|
|
161
|
+
let processCount = 0;
|
|
162
|
+
|
|
163
|
+
await subscriber.subscribe(['user.created'], async (_message) => {
|
|
164
|
+
processCount++;
|
|
165
|
+
if (processCount === 1) {
|
|
166
|
+
// Fail first time
|
|
167
|
+
throw new Error('Processing error');
|
|
168
|
+
}
|
|
169
|
+
// Success on retry
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
173
|
+
|
|
174
|
+
await publisher.publish([
|
|
175
|
+
{ type: 'user.created', payload: { userId: '123' } },
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
// Wait for initial processing and retry
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
180
|
+
|
|
181
|
+
// Should have been processed twice (initial + retry after nack)
|
|
182
|
+
expect(processCount).toBeGreaterThanOrEqual(2);
|
|
183
|
+
|
|
184
|
+
await connection.close();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should work with custom queue name', async () => {
|
|
188
|
+
const testExchange = uniqueExchange();
|
|
189
|
+
const queueName = `test-queue-${Date.now()}`;
|
|
190
|
+
|
|
191
|
+
const connection = new RabbitMQConnection({
|
|
192
|
+
url: RABBITMQ_URL,
|
|
193
|
+
exchange: testExchange,
|
|
194
|
+
});
|
|
195
|
+
await connection.connect();
|
|
196
|
+
|
|
197
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
198
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection, {
|
|
199
|
+
queueName,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const receivedMessages: TestMessage[] = [];
|
|
203
|
+
|
|
204
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
205
|
+
receivedMessages.push(message);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
209
|
+
|
|
210
|
+
await publisher.publish([
|
|
211
|
+
{ type: 'user.created', payload: { userId: '123' } },
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
215
|
+
|
|
216
|
+
expect(receivedMessages).toHaveLength(1);
|
|
217
|
+
|
|
218
|
+
await connection.close();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should work with prefetch limit', async () => {
|
|
222
|
+
const testExchange = uniqueExchange();
|
|
223
|
+
const connection = new RabbitMQConnection({
|
|
224
|
+
url: RABBITMQ_URL,
|
|
225
|
+
exchange: testExchange,
|
|
226
|
+
});
|
|
227
|
+
await connection.connect();
|
|
228
|
+
|
|
229
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
230
|
+
const subscriber = new RabbitMQSubscriber<TestMessage>(connection, {
|
|
231
|
+
prefetch: 1,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const receivedMessages: TestMessage[] = [];
|
|
235
|
+
|
|
236
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
237
|
+
receivedMessages.push(message);
|
|
238
|
+
// Slow processing
|
|
239
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
243
|
+
|
|
244
|
+
// Publish multiple messages
|
|
245
|
+
await publisher.publish([
|
|
246
|
+
{ type: 'user.created', payload: { userId: '1' } },
|
|
247
|
+
{ type: 'user.created', payload: { userId: '2' } },
|
|
248
|
+
{ type: 'user.created', payload: { userId: '3' } },
|
|
249
|
+
]);
|
|
250
|
+
|
|
251
|
+
// Wait for all to be processed
|
|
252
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
253
|
+
|
|
254
|
+
expect(receivedMessages).toHaveLength(3);
|
|
255
|
+
|
|
256
|
+
await connection.close();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should work with fromConnectionString', async () => {
|
|
260
|
+
const testExchange = uniqueExchange();
|
|
261
|
+
const subscriber =
|
|
262
|
+
await RabbitMQSubscriber.fromConnectionString<TestMessage>(
|
|
263
|
+
`rabbitmq://geekmidas:geekmidas@localhost:5672?exchange=${testExchange}`,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const connection = new RabbitMQConnection({
|
|
267
|
+
url: RABBITMQ_URL,
|
|
268
|
+
exchange: testExchange,
|
|
269
|
+
});
|
|
270
|
+
await connection.connect();
|
|
271
|
+
|
|
272
|
+
const publisher = new RabbitMQPublisher<TestMessage>(connection);
|
|
273
|
+
|
|
274
|
+
const receivedMessages: TestMessage[] = [];
|
|
275
|
+
|
|
276
|
+
await subscriber.subscribe(['user.created'], async (message) => {
|
|
277
|
+
receivedMessages.push(message);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
281
|
+
|
|
282
|
+
await publisher.publish([
|
|
283
|
+
{ type: 'user.created', payload: { userId: '123' } },
|
|
284
|
+
]);
|
|
285
|
+
|
|
286
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
287
|
+
|
|
288
|
+
expect(receivedMessages).toHaveLength(1);
|
|
289
|
+
|
|
290
|
+
await connection.close();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { RabbitMQConnectionConfig } from './RabbitMQConnection';
|
|
2
|
+
export { RabbitMQConnection } from './RabbitMQConnection';
|
|
3
|
+
export type { RabbitMQPublisherOptions } from './RabbitMQPublisher';
|
|
4
|
+
export { RabbitMQPublisher } from './RabbitMQPublisher';
|
|
5
|
+
export type { RabbitMQSubscriberOptions } from './RabbitMQSubscriber';
|
|
6
|
+
export { RabbitMQSubscriber } from './RabbitMQSubscriber';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SNSClient, type SNSClientConfig } from '@aws-sdk/client-sns';
|
|
2
|
+
import type { EventConnection } from '../types';
|
|
3
|
+
import { EventPublisherType } from '../types';
|
|
4
|
+
|
|
5
|
+
export interface SNSConnectionConfig {
|
|
6
|
+
topicArn: string;
|
|
7
|
+
region?: string;
|
|
8
|
+
endpoint?: string; // Custom endpoint (e.g., for LocalStack)
|
|
9
|
+
credentials?: {
|
|
10
|
+
accessKeyId: string;
|
|
11
|
+
secretAccessKey: string;
|
|
12
|
+
sessionToken?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class SNSConnection implements EventConnection {
|
|
17
|
+
readonly type = EventPublisherType.SNS;
|
|
18
|
+
private client: SNSClient;
|
|
19
|
+
private connected = false;
|
|
20
|
+
private config: SNSConnectionConfig;
|
|
21
|
+
|
|
22
|
+
constructor(config: SNSConnectionConfig) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
|
|
25
|
+
const clientConfig: SNSClientConfig = {
|
|
26
|
+
region: config.region,
|
|
27
|
+
endpoint: config.endpoint,
|
|
28
|
+
credentials: config.credentials,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
this.client = new SNSClient(clientConfig);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create an SNSConnection from a connection string
|
|
36
|
+
* Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566
|
|
37
|
+
*/
|
|
38
|
+
static async fromConnectionString(
|
|
39
|
+
connectionString: string,
|
|
40
|
+
): Promise<SNSConnection> {
|
|
41
|
+
const url = new URL(connectionString);
|
|
42
|
+
const params = url.searchParams;
|
|
43
|
+
|
|
44
|
+
const topicArn = params.get('topicArn');
|
|
45
|
+
if (!topicArn) {
|
|
46
|
+
throw new Error('topicArn parameter is required in connection string');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const config: SNSConnectionConfig = {
|
|
50
|
+
topicArn,
|
|
51
|
+
region: params.get('region') || undefined,
|
|
52
|
+
endpoint: params.get('endpoint') || undefined,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Parse credentials if provided
|
|
56
|
+
const accessKeyId = params.get('accessKeyId');
|
|
57
|
+
const secretAccessKey = params.get('secretAccessKey');
|
|
58
|
+
if (accessKeyId && secretAccessKey) {
|
|
59
|
+
config.credentials = {
|
|
60
|
+
accessKeyId,
|
|
61
|
+
secretAccessKey,
|
|
62
|
+
sessionToken: params.get('sessionToken') || undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const connection = new SNSConnection(config);
|
|
67
|
+
await connection.connect();
|
|
68
|
+
return connection;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async connect(): Promise<void> {
|
|
72
|
+
// SNS doesn't have a traditional connection, but we mark as connected
|
|
73
|
+
this.connected = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async close(): Promise<void> {
|
|
77
|
+
this.client.destroy();
|
|
78
|
+
this.connected = false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
isConnected(): boolean {
|
|
82
|
+
return this.connected;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the underlying SNS client
|
|
87
|
+
*/
|
|
88
|
+
get snsClient(): SNSClient {
|
|
89
|
+
return this.client;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get the topic ARN for this connection
|
|
94
|
+
*/
|
|
95
|
+
get topicArn(): string {
|
|
96
|
+
return this.config.topicArn;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PublishCommand } from '@aws-sdk/client-sns';
|
|
2
|
+
import type { EventPublisher, PublishableMessage } from '../types';
|
|
3
|
+
import type { SNSConnection } from './SNSConnection';
|
|
4
|
+
|
|
5
|
+
export type SNSPublisherOptions = {};
|
|
6
|
+
|
|
7
|
+
export class SNSPublisher<TMessage extends PublishableMessage<string, any>>
|
|
8
|
+
implements EventPublisher<TMessage>
|
|
9
|
+
{
|
|
10
|
+
constructor(
|
|
11
|
+
private connection: SNSConnection,
|
|
12
|
+
_options: SNSPublisherOptions = {},
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create an SNSPublisher from a connection string
|
|
17
|
+
* Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566
|
|
18
|
+
*/
|
|
19
|
+
static async fromConnectionString<
|
|
20
|
+
TMessage extends PublishableMessage<string, any>,
|
|
21
|
+
>(connectionString: string): Promise<SNSPublisher<TMessage>> {
|
|
22
|
+
const { SNSConnection } = await import('./SNSConnection');
|
|
23
|
+
const connection =
|
|
24
|
+
await SNSConnection.fromConnectionString(connectionString);
|
|
25
|
+
|
|
26
|
+
return new SNSPublisher<TMessage>(connection);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async publish(messages: TMessage[]): Promise<void> {
|
|
30
|
+
if (messages.length === 0) return;
|
|
31
|
+
|
|
32
|
+
if (!this.connection.isConnected()) {
|
|
33
|
+
await this.connection.connect();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Publish all messages
|
|
37
|
+
await Promise.all(messages.map((message) => this.publishMessage(message)));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private async publishMessage(message: TMessage): Promise<void> {
|
|
41
|
+
const command = new PublishCommand({
|
|
42
|
+
TopicArn: this.connection.topicArn,
|
|
43
|
+
Message: JSON.stringify({
|
|
44
|
+
type: message.type,
|
|
45
|
+
payload: message.payload,
|
|
46
|
+
}),
|
|
47
|
+
MessageAttributes: {
|
|
48
|
+
type: {
|
|
49
|
+
DataType: 'String',
|
|
50
|
+
StringValue: message.type,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await this.connection.snsClient.send(command);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async close(): Promise<void> {
|
|
59
|
+
// Publisher doesn't own the connection
|
|
60
|
+
// Connection should be closed by whoever created it
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { SubscribeCommand, UnsubscribeCommand } from '@aws-sdk/client-sns';
|
|
2
|
+
import {
|
|
3
|
+
CreateQueueCommand,
|
|
4
|
+
DeleteQueueCommand,
|
|
5
|
+
GetQueueAttributesCommand,
|
|
6
|
+
SetQueueAttributesCommand,
|
|
7
|
+
SQSClient,
|
|
8
|
+
} from '@aws-sdk/client-sqs';
|
|
9
|
+
import { SQSConnection } from '../sqs/SQSConnection';
|
|
10
|
+
import { SQSSubscriber } from '../sqs/SQSSubscriber';
|
|
11
|
+
import type { EventSubscriber, PublishableMessage } from '../types';
|
|
12
|
+
import type { SNSConnection } from './SNSConnection';
|
|
13
|
+
|
|
14
|
+
export interface SNSSubscriberOptions {
|
|
15
|
+
queueName?: string; // Optional queue name (defaults to auto-generated)
|
|
16
|
+
createQueue?: boolean; // Auto-create SQS queue (default: true)
|
|
17
|
+
deleteQueueOnClose?: boolean; // Delete queue when subscriber closes (default: false for named queues, true for auto-generated)
|
|
18
|
+
waitTimeSeconds?: number; // SQS long polling (default: 20)
|
|
19
|
+
maxMessages?: number; // Max messages per poll (default: 10)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* SNS Subscriber - receives push-based messages from SNS via SQS queue
|
|
24
|
+
*
|
|
25
|
+
* Architecture:
|
|
26
|
+
* SNS Topic → (push) → SQS Queue → Subscriber
|
|
27
|
+
*
|
|
28
|
+
* This subscriber automatically:
|
|
29
|
+
* 1. Creates an SQS queue (or uses existing one)
|
|
30
|
+
* 2. Subscribes the queue to the SNS topic
|
|
31
|
+
* 3. Receives messages pushed from SNS to the queue
|
|
32
|
+
* 4. Filters messages by topic ARN and message type
|
|
33
|
+
* 5. Processes and acknowledges messages
|
|
34
|
+
*
|
|
35
|
+
* Note: While SQS long-polling is used internally to receive messages,
|
|
36
|
+
* this is an implementation detail of the SNS push delivery mechanism.
|
|
37
|
+
* Messages are pushed from SNS to SQS, and we receive those pushed messages.
|
|
38
|
+
*/
|
|
39
|
+
export class SNSSubscriber<TMessage extends PublishableMessage<string, any>>
|
|
40
|
+
implements EventSubscriber<TMessage>
|
|
41
|
+
{
|
|
42
|
+
private sqsClient: SQSClient;
|
|
43
|
+
private queueUrl?: string;
|
|
44
|
+
private queueArn?: string;
|
|
45
|
+
private subscriptionArn?: string;
|
|
46
|
+
private sqsSubscriber?: SQSSubscriber<TMessage>;
|
|
47
|
+
private options: Required<SNSSubscriberOptions>;
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
private connection: SNSConnection,
|
|
51
|
+
options: SNSSubscriberOptions = {},
|
|
52
|
+
) {
|
|
53
|
+
this.options = {
|
|
54
|
+
queueName:
|
|
55
|
+
options.queueName ||
|
|
56
|
+
`sns-sub-${Date.now()}-${Math.random().toString(36).substring(7)}`,
|
|
57
|
+
createQueue: options.createQueue ?? true,
|
|
58
|
+
deleteQueueOnClose: options.deleteQueueOnClose ?? !options.queueName, // Delete auto-generated queues
|
|
59
|
+
waitTimeSeconds: options.waitTimeSeconds ?? 20,
|
|
60
|
+
maxMessages: options.maxMessages ?? 10,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Create SQS client with same config as SNS
|
|
64
|
+
this.sqsClient = new SQSClient({
|
|
65
|
+
region: (this.connection as any).config.region,
|
|
66
|
+
endpoint: (this.connection as any).config.endpoint,
|
|
67
|
+
credentials: (this.connection as any).config.credentials,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create an SNSSubscriber from a connection string
|
|
73
|
+
* Format: sns://?topicArn=...&queueName=myqueue®ion=us-east-1
|
|
74
|
+
*/
|
|
75
|
+
static async fromConnectionString<
|
|
76
|
+
TMessage extends PublishableMessage<string, any>,
|
|
77
|
+
>(connectionString: string): Promise<SNSSubscriber<TMessage>> {
|
|
78
|
+
const url = new URL(connectionString);
|
|
79
|
+
const params = url.searchParams;
|
|
80
|
+
|
|
81
|
+
const { SNSConnection } = await import('./SNSConnection');
|
|
82
|
+
const connection =
|
|
83
|
+
await SNSConnection.fromConnectionString(connectionString);
|
|
84
|
+
|
|
85
|
+
const options: SNSSubscriberOptions = {
|
|
86
|
+
queueName: params.get('queueName') || undefined,
|
|
87
|
+
createQueue: params.get('createQueue') !== 'false',
|
|
88
|
+
deleteQueueOnClose: params.get('deleteQueueOnClose') === 'true',
|
|
89
|
+
waitTimeSeconds: params.get('waitTimeSeconds')
|
|
90
|
+
? Number.parseInt(params.get('waitTimeSeconds')!, 10)
|
|
91
|
+
: undefined,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return new SNSSubscriber<TMessage>(connection, options);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async subscribe(
|
|
98
|
+
messages: TMessage['type'][],
|
|
99
|
+
listener: (payload: TMessage) => Promise<void>,
|
|
100
|
+
): Promise<void> {
|
|
101
|
+
// Setup SQS queue and SNS subscription
|
|
102
|
+
await this.setupQueue();
|
|
103
|
+
await this.subscribeToTopic();
|
|
104
|
+
|
|
105
|
+
// Create SQS connection for the subscriber
|
|
106
|
+
const sqsConnection = new SQSConnection({
|
|
107
|
+
queueUrl: this.queueUrl!,
|
|
108
|
+
region: (this.connection as any).config.region,
|
|
109
|
+
endpoint: (this.connection as any).config.endpoint,
|
|
110
|
+
credentials: (this.connection as any).config.credentials,
|
|
111
|
+
});
|
|
112
|
+
await sqsConnection.connect();
|
|
113
|
+
|
|
114
|
+
// Use SQSSubscriber to receive messages, with topic filtering
|
|
115
|
+
this.sqsSubscriber = new SQSSubscriber<TMessage>(sqsConnection, {
|
|
116
|
+
waitTimeSeconds: this.options.waitTimeSeconds,
|
|
117
|
+
maxMessages: this.options.maxMessages,
|
|
118
|
+
expectedTopicArn: this.connection.topicArn,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await this.sqsSubscriber.subscribe(messages, listener);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Stop receiving messages and clean up resources
|
|
126
|
+
*/
|
|
127
|
+
async stop(): Promise<void> {
|
|
128
|
+
// Stop SQS subscriber
|
|
129
|
+
if (this.sqsSubscriber) {
|
|
130
|
+
this.sqsSubscriber.stop();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Unsubscribe from topic
|
|
134
|
+
if (this.subscriptionArn) {
|
|
135
|
+
try {
|
|
136
|
+
const command = new UnsubscribeCommand({
|
|
137
|
+
SubscriptionArn: this.subscriptionArn,
|
|
138
|
+
});
|
|
139
|
+
await this.connection.snsClient.send(command);
|
|
140
|
+
} catch (_error) {}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Delete queue if configured
|
|
144
|
+
if (this.queueUrl && this.options.deleteQueueOnClose) {
|
|
145
|
+
try {
|
|
146
|
+
const command = new DeleteQueueCommand({
|
|
147
|
+
QueueUrl: this.queueUrl,
|
|
148
|
+
});
|
|
149
|
+
await this.sqsClient.send(command);
|
|
150
|
+
} catch (_error) {}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.sqsClient.destroy();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private async setupQueue(): Promise<void> {
|
|
157
|
+
if (this.options.createQueue) {
|
|
158
|
+
// Create queue
|
|
159
|
+
const createCommand = new CreateQueueCommand({
|
|
160
|
+
QueueName: this.options.queueName,
|
|
161
|
+
});
|
|
162
|
+
const response = await this.sqsClient.send(createCommand);
|
|
163
|
+
this.queueUrl = response.QueueUrl!;
|
|
164
|
+
} else {
|
|
165
|
+
throw new Error('Queue must exist or createQueue option must be true');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Get queue ARN
|
|
169
|
+
const attrsCommand = new GetQueueAttributesCommand({
|
|
170
|
+
QueueUrl: this.queueUrl,
|
|
171
|
+
AttributeNames: ['QueueArn'],
|
|
172
|
+
});
|
|
173
|
+
const attrsResponse = await this.sqsClient.send(attrsCommand);
|
|
174
|
+
this.queueArn = attrsResponse.Attributes?.QueueArn!;
|
|
175
|
+
|
|
176
|
+
// Set queue policy to allow SNS
|
|
177
|
+
await this.setQueuePolicy();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private async setQueuePolicy(): Promise<void> {
|
|
181
|
+
const policy = {
|
|
182
|
+
Version: '2012-10-17',
|
|
183
|
+
Statement: [
|
|
184
|
+
{
|
|
185
|
+
Effect: 'Allow',
|
|
186
|
+
Principal: '*',
|
|
187
|
+
Action: 'SQS:SendMessage',
|
|
188
|
+
Resource: this.queueArn,
|
|
189
|
+
Condition: {
|
|
190
|
+
ArnEquals: {
|
|
191
|
+
'aws:SourceArn': this.connection.topicArn,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const command = new SetQueueAttributesCommand({
|
|
199
|
+
QueueUrl: this.queueUrl,
|
|
200
|
+
Attributes: {
|
|
201
|
+
Policy: JSON.stringify(policy),
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
await this.sqsClient.send(command);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private async subscribeToTopic(): Promise<void> {
|
|
209
|
+
const command = new SubscribeCommand({
|
|
210
|
+
TopicArn: this.connection.topicArn,
|
|
211
|
+
Protocol: 'sqs',
|
|
212
|
+
Endpoint: this.queueArn,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const response = await this.connection.snsClient.send(command);
|
|
216
|
+
this.subscriptionArn = response.SubscriptionArn!;
|
|
217
|
+
}
|
|
218
|
+
}
|