From b0c265cb1afe00a2a601207321b28397fc1a5ff6 Mon Sep 17 00:00:00 2001 From: Weyoss Date: Sun, 6 Feb 2022 16:39:40 +0300 Subject: [PATCH] Allow managing namespaces, update HTTP API, test --- CHANGELOG.md | 2 +- docs/api/queue-manager.md | 59 ++- docs/http-api.md | 427 ++++++++++-------- .../controllers/api/api-controller.ts | 3 +- .../api/main/scheduled-messages/context.ts | 11 - .../delete-scheduled-message.handler.ts | 14 +- .../get-scheduled-messages.handler.ts | 14 +- .../purge-scheduled-messages.handler.ts | 11 +- .../get-acknowledged.handler.ts | 14 +- .../get-dead-lettered.handler.ts | 14 +- .../get-published.handler.ts | 14 +- .../delete-namespace.handler.ts | 13 + .../delete-namespace.request.DTO.ts | 3 + .../delete-namespace.response.DTO.ts | 3 + .../get-namespace-queues.handler.ts | 13 + .../get-namespace-queues.request.DTO.ts | 3 + .../get-namespace-queues.response.DTO.ts | 12 + .../get-namespaces/get-namespaces.handler.ts | 13 + .../get-namespaces.request.DTO.ts | 1 + .../get-namespaces.response.DTO.ts | 16 + .../api/namespaces/namespaces.controller.ts | 56 +++ .../queue/acknowledged-messages/controller.ts | 0 .../delete-acknowledged-message.handler.ts | 13 + ...delete-acknowledged-message.request.DTO.ts | 0 ...elete-acknowledged-message.response.DTO.ts | 0 .../get-acknowledged-messages.handler.ts | 13 + .../get-acknowledged-messages.request.DTO.ts | 0 .../get-acknowledged-messages.response.DTO.ts | 0 .../purge-acknowledged-messages.handler.ts | 13 + ...purge-acknowledged-messages.request.DTO.ts | 0 ...urge-acknowledged-messages.response.DTO.ts | 0 .../requeue-acknowledged-message.handler.ts | 13 + ...equeue-acknowledged-message.request.DTO.ts | 0 ...queue-acknowledged-message.response.DTO.ts | 0 .../queue/consumer/time-series/controller.ts | 0 .../get-consumer-acknowledged.handler.ts | 13 + .../get-consumer-acknowledged.request.DTO.ts | 0 .../get-consumer-acknowledged.response.DTO.ts | 0 .../get-consumer-dead-lettered.handler.ts | 13 + .../get-consumer-dead-lettered.request.DTO.ts | 0 ...get-consumer-dead-lettered.response.DTO.ts | 0 .../dead-lettered-messages/controller.ts | 0 .../delete-dead-lettered-message.handler.ts | 13 + ...elete-dead-lettered-message.request.DTO.ts | 0 ...lete-dead-lettered-message.response.DTO.ts | 0 .../get-dead-lettered-messages.handler.ts | 13 + .../get-dead-lettered-messages.request.DTO.ts | 0 ...get-dead-lettered-messages.response.DTO.ts | 0 .../purge-dead-lettered-messages.handler.ts | 13 + ...urge-dead-lettered-messages.request.DTO.ts | 0 ...rge-dead-lettered-messages.response.DTO.ts | 0 .../requeue-dead-lettered-message.handler.ts | 13 + ...queue-dead-lettered-message.request.DTO.ts | 0 ...ueue-dead-lettered-message.response.DTO.ts | 0 .../delete-queue/delete-queue.handler.ts | 13 + .../delete-queue/delete-queue.request.DTO.ts | 0 .../delete-queue/delete-queue.response.DTO.ts | 0 .../controller.ts | 0 ...e-pending-message-with-priority.handler.ts | 13 + ...nding-message-with-priority.request.DTO.ts | 0 ...ding-message-with-priority.response.DTO.ts | 0 ...-pending-messages-with-priority.handler.ts | 13 + ...ding-messages-with-priority.request.DTO.ts | 0 ...ing-messages-with-priority.response.DTO.ts | 0 ...-pending-messages-with-priority.handler.ts | 13 + ...ding-messages-with-priority.request.DTO.ts | 0 ...ing-messages-with-priority.response.DTO.ts | 0 .../queue/pending-messages/controller.ts | 0 .../delete-pending-message.handler.ts | 13 + .../delete-pending-message.request.DTO.ts | 0 .../delete-pending-message.response.DTO.ts | 0 .../get-pending-messages.handler.ts | 13 + .../get-pending-messages.request.DTO.ts | 0 .../get-pending-messages.response.DTO.ts | 0 .../purge-pending-messages.handler.ts | 13 + .../purge-pending-messages.request.DTO.ts | 0 .../purge-pending-messages.response.DTO.ts | 0 .../api/namespaces/queue/queue.controller.ts | 34 ++ .../queue/time-series/controller.ts | 0 .../get-queue-acknowledged.handler.ts | 13 + .../get-queue-acknowledged.request.DTO.ts | 0 .../get-queue-acknowledged.response.DTO.ts | 0 .../get-queue-dead-lettered.handler.ts | 13 + .../get-queue-dead-lettered.request.DTO.ts | 0 .../get-queue-dead-lettered.response.DTO.ts | 0 .../get-queue-published.handler.ts | 13 + .../get-queue-published.request.DTO.ts | 0 .../get-queue-published.response.DTO.ts | 0 .../queues/get-queues/get-queues.handler.ts | 16 +- .../delete-acknowledged-message.handler.ts | 9 - .../get-acknowledged-messages.handler.ts | 9 - .../purge-acknowledged-messages.handler.ts | 9 - .../requeue-acknowledged-message.handler.ts | 9 - .../get-consumer-acknowledged.handler.ts | 9 - .../get-consumer-dead-lettered.handler.ts | 9 - .../controllers/api/queues/queue/context.ts | 14 - .../delete-dead-lettered-message.handler.ts | 9 - .../get-dead-lettered-messages.handler.ts | 9 - .../purge-dead-lettered-messages.handler.ts | 9 - .../requeue-dead-lettered-message.handler.ts | 9 - .../delete-queue/delete-queue.handler.ts | 11 - ...e-pending-message-with-priority.handler.ts | 9 - ...-pending-messages-with-priority.handler.ts | 9 - ...-pending-messages-with-priority.handler.ts | 9 - .../delete-pending-message.handler.ts | 9 - .../get-pending-messages.handler.ts | 9 - .../purge-pending-messages.handler.ts | 9 - .../api/queues/queue/time-series/context.ts | 12 - .../get-queue-acknowledged.handler.ts | 9 - .../get-queue-dead-lettered.handler.ts | 9 - .../get-queue-published.handler.ts | 9 - .../api/queues/queues.controller.ts | 30 -- .../dto/namespaces/namespace-request.DTO.ts | 7 + .../dto/no-content-http-response.DTO.ts | 5 +- .../common/dto/queues/message.DTO.ts | 16 +- .../common/dto/queues/queue-request.DTO.ts | 7 +- src/monitor-server/lib/routing.ts | 68 ++- .../services/consumer-time-series.service.ts | 4 +- .../services/messages.service.ts | 81 ++-- src/monitor-server/services/queues.service.ts | 24 +- src/monitor-server/types/common.ts | 12 +- src/monitor-server/utils/validate-dto.ts | 6 +- .../workers/websocket-main-stream.worker.ts | 2 +- .../workers/websocket-online-stream.worker.ts | 2 +- src/system/app/message/message-metadata.ts | 15 + src/system/app/message/message.ts | 20 +- src/system/app/producer/producer.ts | 5 + src/system/app/queue-manager/common.ts | 2 +- .../queue-manager/queue-manager-frontend.ts | 28 +- src/system/app/queue-manager/queue-manager.ts | 105 ++++- .../redis-client/lua/publish-message.lua | 33 +- src/system/common/redis-keys/redis-keys.ts | 21 +- tests/http-api/test00001.test.ts | 2 +- tests/http-api/test00002.test.ts | 8 +- tests/http-api/test00006.test.ts | 50 +- tests/http-api/test00007.test.ts | 4 +- tests/http-api/test00008.test.ts | 4 +- tests/http-api/test00009.test.ts | 4 +- tests/http-api/test00010.test.ts | 6 +- tests/http-api/test00011.test.ts | 4 +- tests/http-api/test00012.test.ts | 4 +- tests/http-api/test00013.test.ts | 4 +- tests/http-api/test00014.test.ts | 4 +- tests/http-api/test00015.test.ts | 4 +- tests/http-api/test00016.test.ts | 4 +- tests/http-api/test00017.test.ts | 4 +- tests/http-api/test00018.test.ts | 4 +- tests/http-api/test00019.test.ts | 8 +- tests/http-api/test00020.test.ts | 8 +- tests/http-api/test00021.test.ts | 8 +- tests/http-api/test00022.test.ts | 10 +- tests/http-api/test00023.test.ts | 2 +- tests/http-api/test00024.test.ts | 2 +- tests/http-api/test00025.test.ts | 2 +- tests/http-api/test00026.test.ts | 2 +- tests/http-api/test00027.test.ts | 4 +- tests/http-api/test00028.test.ts | 4 +- tests/http-api/test00034.test.ts | 2 +- tests/purging-queues/test00006.test.ts | 8 +- tests/purging-queues/test00007.test.ts | 6 +- tests/purging-queues/test00008.test.ts | 54 +++ tests/scheduling-messages/test00008.test.ts | 2 +- types/index.ts | 28 ++ 163 files changed, 1311 insertions(+), 676 deletions(-) delete mode 100644 src/monitor-server/controllers/api/main/scheduled-messages/context.ts create mode 100644 src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.handler.ts create mode 100644 src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.request.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.response.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.handler.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.request.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.response.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.handler.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.request.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.response.DTO.ts create mode 100644 src/monitor-server/controllers/api/namespaces/namespaces.controller.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.response.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/consumer/time-series/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.response.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/delete-queue/delete-queue.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/delete-queue/delete-queue.response.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.response.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/delete-pending-message/delete-pending-message.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/get-pending-messages/get-pending-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/pending-messages/purge-pending-messages/purge-pending-messages.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/queue.controller.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/controller.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.response.DTO.ts (100%) create mode 100644 src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.handler.ts rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-published/get-queue-published.request.DTO.ts (100%) rename src/monitor-server/controllers/api/{queues => namespaces}/queue/time-series/get-queue-published/get-queue-published.response.DTO.ts (100%) delete mode 100644 src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/context.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/time-series/context.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts delete mode 100644 src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.handler.ts create mode 100644 src/monitor-server/controllers/common/dto/namespaces/namespace-request.DTO.ts create mode 100644 tests/purging-queues/test00008.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2c026e..1d587d16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,7 +96,7 @@ * Allow to delete a message queue alongside with its related data. * Make sure to release queue lock before returning. * Improve QueueManager API method names, update docs. -* Update QueueManager API reference (add deleteMessageQueue() method). +* Update QueueManager API reference (add deleteQueue() method). * Fix QueueManager broken method references in the Web UI. * Rename purgeScheduledMessages() to purgeScheduledQueue(). * Test deleting queues, wait for a heartbeat before returning during startup. diff --git a/docs/api/queue-manager.md b/docs/api/queue-manager.md index 8400a6ac..5e691e52 100644 --- a/docs/api/queue-manager.md +++ b/docs/api/queue-manager.md @@ -15,10 +15,13 @@ QueueManager.getSingletonInstance(config, (err, queueManager) => { ## Table of Content 1. [QueueManager.getSingletonInstance()](#queuemanagergetsingletoninstance) -2. [QueueManager.prototype.getMessageQueues()](#queuemanagerprototypegetmessagequeues) -3. [QueueManager.prototype.getQueueMetrics()](#queuemanagerprototypegetqueuemetrics) -4. [QueueManager.prototype.deleteMessageQueue()](#queuemanagerprototypedeletemessagequeue) -5. [QueueManager.prototype.quit()](#queuemanagerprototypequit) +2. [QueueManager.prototype.getQueues()](#queuemanagerprototypegetqueues) +3. [QueueManager.prototype.getNamespaces()](#queuemanagerprototypegetnamespaces) +4. [QueueManager.prototype.getNamespaceQueues()]() +5. [QueueManager.prototype.getQueueMetrics()](#queuemanagerprototypegetqueuemetrics) +6. [QueueManager.prototype.deleteQueue()](#queuemanagerprototypedeletequeue) +7. [QueueManager.prototype.deleteNamespace()](#queuemanagerprototypedeletenamespace) +8. [QueueManager.prototype.quit()](#queuemanagerprototypequit) ## Public Static Methods @@ -35,10 +38,10 @@ getSingletonInstance(cb) ## Public Methods -### QueueManager.prototype.getMessageQueues() +### QueueManager.prototype.getQueues() ```javascript -getMessageQueues(cb); +getQueues(cb); ``` **Parameters** @@ -48,6 +51,32 @@ getMessageQueues(cb); - `messageQueues[*].ns` *(string).* Queue namespace. - `messageQueues[*].name` *(string).* Queue name. +### QueueManager.prototype.getNamespaces() + +```javascript +getQueues(cb); +``` + +**Parameters** +- `cb(err, namespaces)` *(Function): Required.* Callback function. + - `err` *(Error | null | undefined).* Error object. + - `namespaces` *(Array).* Namespaces. + +### QueueManager.prototype.getNamespaceQueues() + +```javascript +getNamespaceQueues(ns, cb); +``` + +**Parameters** + +- `ns` *(string): Required.* Namespace. +- `cb(err, messageQueues)` *(Function): Required.* Callback function. + - `err` *(Error | null | undefined).* Error object. + - `messageQueues` *(Array).* + - `messageQueues[*].ns` *(string).* Queue namespace. + - `messageQueues[*].name` *(string).* Queue name. + ### QueueManager.prototype.getQueueMetrics() ```javascript @@ -67,10 +96,10 @@ getQueueMetrics(queue, cb); - `queueMetrics.pending` *(number).* Pending messages count. - `queueMetrics.pendingWithPriority` *(number).* Pending messages with priority count. -### QueueManager.prototype.deleteMessageQueue() +### QueueManager.prototype.deleteQueue() ```javascript -deleteMessageQueue(queue, cb); +deleteQueue(queue, cb); ``` **Parameters** @@ -83,6 +112,20 @@ deleteMessageQueue(queue, cb); Before deleting a message queue, make sure that the given queue is not being in use. Otherwise, an error will be returned. +### QueueManager.prototype.deleteNamespace() + +```javascript +deleteNamespace(ns, cb); +``` + +**Parameters** + +- `ns` *(string): Required.* Namespace. +- `cb(err)` *(Function): Required.* Callback function. + - `err` *(Error | null | undefined).* Error object. + +Before deleting a namespace, make sure that all queues from the given namespace are not being in use. Otherwise, an error will be returned. + ### QueueManager.prototype.quit() ```javascript diff --git a/docs/http-api.md b/docs/http-api.md index 02e735d2..ced682a0 100644 --- a/docs/http-api.md +++ b/docs/http-api.md @@ -15,27 +15,30 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ## Table of Content -1. Queues +1. Queues & Namespaces 1. [GET /api/queues](#get-apiqueues) - 2. [DELETE /api/queues/:queueName/ns/:ns](#delete-apiqueuesqueuenamensns) + 2. [GET /api/ns](#get-apins) + 3. [DELETE /api/ns/:ns](#delete-apinsns) + 4. [GET /api/ns/:ns/queues](#get-apinsnsqueues) + 5. [DELETE /api/ns/:ns/queues/:queueName](#delete-apinsnsqueuesqueuename) 2. Acknowledged Messages - 1. [GET /api/queues/:queueName/ns/:ns/acknowledged-messages](#get-apiqueuesqueuenamensnsacknowledged-messages) - 2. [DELETE /api/queues/:queueName/ns/:ns/acknowledged-messages](#delete-apiqueuesqueuenamensnsacknowledged-messages) - 3. [DELETE /api/queues/:queueName/ns/:ns/acknowledged-messages/:id](#delete-apiqueuesqueuenamensnsacknowledged-messagesid) - 4. [POST /api/queues/:queueName/ns/:ns/acknowledged-messages/:id/requeue](#post-apiqueuesqueuenamensnsacknowledged-messagesidrequeue) + 1. [GET /api/ns/:ns/queues/:queueName/acknowledged-messages](#get-apinsnsqueuesqueuenameacknowledged-messages) + 2. [DELETE /api/ns/:ns/queues/:queueName/acknowledged-messages](#delete-apinsnsqueuesqueuenameacknowledged-messages) + 3. [DELETE /api/ns/:ns/queues/:queueName/acknowledged-messages/:id](#delete-apinsnsqueuesqueuenameacknowledged-messagesid) + 4. [POST /api/ns/:ns/queues/:queueName/acknowledged-messages/:id/requeue](#post-apinsnsqueuesqueuenameacknowledged-messagesidrequeue) 3. Dead-lettered Messages - 1. [GET /api/queues/:queueName/ns/:ns/dead-lettered-messages](#get-apiqueuesqueuenamensnsdead-lettered-messages) - 2. [DELETE /api/queues/:queueName/ns/:ns/dead-lettered-messages](#delete-apiqueuesqueuenamensnsdead-lettered-messages) - 3. [DELETE /api/queues/:queueName/ns/:ns/dead-lettered-messages/:id](#delete-apiqueuesqueuenamensnsdead-lettered-messagesid) - 4. [POST /api/queues/:queueName/ns/:ns/dead-lettered-messages/:id/requeue](#post-apiqueuesqueuenamensnsdead-lettered-messagesidrequeue) + 1. [GET /api/ns/:ns/queues/:queueName/dead-lettered-messages](#get-apinsnsqueuesqueuenamedead-lettered-messages) + 2. [DELETE /api/ns/:ns/queues/:queueName/dead-lettered-messages](#delete-apinsnsqueuesqueuenamedead-lettered-messages) + 3. [DELETE /api/ns/:ns/queues/:queueName/dead-lettered-messages/:id](#delete-apinsnsqueuesqueuenamedead-lettered-messagesid) + 4. [POST /api/ns/:ns/queues/:queueName/dead-lettered-messages/:id/requeue](#post-apinsnsqueuesqueuenamedead-lettered-messagesidrequeue) 4. Pending Messages - 1. [GET /api/queues/:queueName/ns/:ns/pending-messages](#delete-apiqueuesqueuenamensnspending-messages) - 2. [DELETE /api/queues/:queueName/ns/:ns/pending-messages](#delete-apiqueuesqueuenamensnspending-messages) - 3. [DELETE /api/queues/:queueName/ns/:ns/pending-messages/:id](#delete-apiqueuesqueuenamensnspending-messagesid) + 1. [GET /api/ns/:ns/queues/:queueName/pending-messages](#delete-apinsnsqueuesqueuenamepending-messages) + 2. [DELETE /api/ns/:ns/queues/:queueName/pending-messages](#delete-apinsnsqueuesqueuenamepending-messages) + 3. [DELETE /api/ns/:ns/queues/:queueName/pending-messages/:id](#delete-apinsnsqueuesqueuenamepending-messagesid) 5. Pending Messages with Priority - 1. [GET /api/queues/:queueName/ns/:ns/pending-messages-with-priority](#get-apiqueuesqueuenamensnspending-messages-with-priority) - 2. [DELETE /api/queues/:queueName/ns/:ns/pending-messages-with-priority](#delete-apiqueuesqueuenamensnspending-messages-with-priority) - 3. [DELETE /api/queues/:queueName/ns/:ns/pending-messages-with-priority/:id](#delete-apiqueuesqueuenamensnspending-messages-with-priorityid) + 1. [GET /api/ns/:ns/queues/:queueName/pending-messages-with-priority](#get-apinsnsqueuesqueuenamepending-messages-with-priority) + 2. [DELETE /api/ns/:ns/queues/:queueName/pending-messages-with-priority](#delete-apinsnsqueuesqueuenamepending-messages-with-priority) + 3. [DELETE /api/ns/:ns/queues/:queueName/pending-messages-with-priority/:id](#delete-apinsnsqueuesqueuenamepending-messages-with-priorityid) 6. Scheduled Messages 1. [GET /api/main/scheduled-messages](#get-apimainscheduled-messages) 2. [DELETE /api/main/scheduled-messages](#delete-apimainscheduled-messages) @@ -49,8 +52,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 3, - "items": [ + "data": [ { "ns": "my-application", "name": "notifications" @@ -67,7 +69,60 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( } ``` -### DELETE /api/queues/:queueName/ns/:ns +### GET /api/ns + +**Response body** + +```text +{ + "data": [ + "namespace_a", + "namespace_b", + "testing" + ] +} +``` + +### DELETE /api/ns/:ns + +**Path parameters** + +* `ns` (string): Required. Namespace. + +**Response Body** + +```text +204 No Content +``` + +### GET /api/ns/:ns/queues + +**Path parameters** + +* `ns` (string): Required. Namespace. + +**Response Body** + +```text +{ + "data": [ + { + "ns": "my-app-namespace", + "name": "notifications" + }, + { + "ns": "my-app-namespace", + "name": "orders" + }, + { + "ns": "my-app-namespace", + "name": "confirmation_emails" + } + ] +} +``` + +### DELETE /api/ns/:ns/queues/:queueName **Path parameters** @@ -82,7 +137,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ## Acknowledged Messages -### GET /api/queues/:queueName/ns/:ns/acknowledged-messages +### GET /api/ns/:ns/queues/:queueName/acknowledged-messages **Path parameters** @@ -98,43 +153,45 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 1, - "items": [ - { - "sequenceId": 0, - "message": { - "body": { - "hello": "world" - }, - "priority": null, - "scheduledCron": null, - "scheduledDelay": null, - "scheduledRepeatPeriod": null, - "scheduledRepeat": 0, - "scheduledCronFired": false, - "attempts": 0, - "scheduledRepeatCount": 0, - "delayed": false, - "expired": false, - "queue": { - "ns": "my-application", - "name": "test_queue" - }, - "createdAt": 1635702165317, - "publishedAt": 1737595989746, - "scheduledAt": null, - "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", - "ttl": 0, - "retryDelay": 0, - "retryThreshold": 3, - "consumeTimeout": 0 + "data": { + "total": 1, + "items": [ + { + "sequenceId": 0, + "message": { + "body": { + "hello": "world" + }, + "priority": null, + "scheduledCron": null, + "scheduledDelay": null, + "scheduledRepeatPeriod": null, + "scheduledRepeat": 0, + "scheduledCronFired": false, + "attempts": 0, + "scheduledRepeatCount": 0, + "delayed": false, + "expired": false, + "queue": { + "ns": "my-application", + "name": "test_queue" + }, + "createdAt": 1635702165317, + "publishedAt": 1737595989746, + "scheduledAt": null, + "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", + "ttl": 0, + "retryDelay": 0, + "retryThreshold": 3, + "consumeTimeout": 0 + } } - } - ] + ] + } } ``` -### DELETE /api/queues/:queueName/ns/:ns/acknowledged-messages +### DELETE /api/ns/:ns/queues/:queueName/acknowledged-messages **Path parameters** @@ -147,7 +204,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### DELETE /api/queues/:queueName/ns/:ns/acknowledged-messages/:id +### DELETE /api/ns/:ns/queues/:queueName/acknowledged-messages/:id **Path parameters** @@ -165,7 +222,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### POST /api/queues/:queueName/ns/:ns/acknowledged-messages/:id/requeue +### POST /api/ns/:ns/queues/:queueName/acknowledged-messages/:id/requeue **Path parameters** @@ -186,7 +243,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ## Dead-lettered Messages -### GET /api/queues/:queueName/ns/:ns/dead-lettered-messages +### GET /api/ns/:ns/queues/:queueName/dead-lettered-messages **Path parameters** @@ -202,41 +259,43 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 1, - "items": [ - { - "sequenceId": 0, - "message": { - "body": { "hello": "world" }, - "priority": null, - "scheduledCron": null, - "scheduledDelay": null, - "scheduledRepeatPeriod": null, - "scheduledRepeat": 0, - "scheduledCronFired": false, - "attempts": 2, - "scheduledRepeatCount": 0, - "delayed": false, - "expired": false, - "queue": { - "ns": "my-application", - "name": "test_queue" - }, - "createdAt": 1635702165317, - "publishedAt": 1737595989746, - "scheduledAt": 1637523400376, - "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", - "ttl": 0, - "retryDelay": 0, - "retryThreshold": 3, - "consumeTimeout": 0 + "data": { + "total": 1, + "items": [ + { + "sequenceId": 0, + "message": { + "body": { "hello": "world" }, + "priority": null, + "scheduledCron": null, + "scheduledDelay": null, + "scheduledRepeatPeriod": null, + "scheduledRepeat": 0, + "scheduledCronFired": false, + "attempts": 2, + "scheduledRepeatCount": 0, + "delayed": false, + "expired": false, + "queue": { + "ns": "my-application", + "name": "test_queue" + }, + "createdAt": 1635702165317, + "publishedAt": 1737595989746, + "scheduledAt": 1637523400376, + "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", + "ttl": 0, + "retryDelay": 0, + "retryThreshold": 3, + "consumeTimeout": 0 + } } - } - ] + ] + } } ``` -### DELETE /api/queues/:queueName/ns/:ns/dead-lettered-messages +### DELETE /api/ns/:ns/queues/:queueName/dead-lettered-messages **Path parameters** @@ -249,7 +308,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### DELETE /api/queues/:queueName/ns/:ns/dead-lettered-messages/:id +### DELETE /api/ns/:ns/queues/:queueName/dead-lettered-messages/:id **Path parameters** @@ -267,7 +326,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### POST /api/queues/:queueName/ns/:ns/dead-lettered-messages/:id/requeue +### POST /api/ns/:ns/queues/:queueName/dead-lettered-messages/:id/requeue **Path parameters** @@ -288,7 +347,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ## Pending Messages -### GET /api/queues/:queueName/ns/:ns/pending-messages +### GET /api/ns/:ns/queues/:queueName/pending-messages **Path parameters** @@ -305,41 +364,43 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 1, - "items": [ - { - "sequenceId": 0, - "message": { - "body": { "hello": "world" }, - "priority": null, - "scheduledCron": null, - "scheduledDelay": null, - "scheduledRepeatPeriod": null, - "scheduledRepeat": 0, - "scheduledCronFired": false, - "attempts": 0, - "scheduledRepeatCount": 0, - "delayed": false, - "expired": false, - "queue": { - "ns": "my-application", - "name": "test_queue" - }, - "createdAt": 1635702165317, - "publishedAt": 1635702167654, - "scheduledAt": null, - "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", - "ttl": 0, - "retryDelay": 0, - "retryThreshold": 3, - "consumeTimeout": 0 + "data": { + "total": 1, + "items": [ + { + "sequenceId": 0, + "message": { + "body": { "hello": "world" }, + "priority": null, + "scheduledCron": null, + "scheduledDelay": null, + "scheduledRepeatPeriod": null, + "scheduledRepeat": 0, + "scheduledCronFired": false, + "attempts": 0, + "scheduledRepeatCount": 0, + "delayed": false, + "expired": false, + "queue": { + "ns": "my-application", + "name": "test_queue" + }, + "createdAt": 1635702165317, + "publishedAt": 1635702167654, + "scheduledAt": null, + "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", + "ttl": 0, + "retryDelay": 0, + "retryThreshold": 3, + "consumeTimeout": 0 + } } - } - ] + ] + } } ``` -### DELETE /api/queues/:queueName/ns/:ns/pending-messages +### DELETE /api/ns/:ns/queues/:queueName/pending-messages **Path parameters** @@ -352,7 +413,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### DELETE /api/queues/:queueName/ns/:ns/pending-messages/:id +### DELETE /api/ns/:ns/queues/:queueName/pending-messages/:id **Path parameters** @@ -372,7 +433,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ## Pending Messages with Priority -### GET /api/queues/:queueName/ns/:ns/pending-messages-with-priority +### GET /api/ns/:ns/queues/:queueName/pending-messages-with-priority **Path parameters** @@ -388,38 +449,40 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 1, - "items": [ - { - "body": { "hello": "world" }, - "priority": 4, - "scheduledCron": null, - "scheduledDelay": null, - "scheduledRepeatPeriod": null, - "scheduledRepeat": 0, - "scheduledCronFired": false, - "attempts": 0, - "scheduledRepeatCount": 0, - "delayed": false, - "expired": false, - "queue": { - "ns": "my-application", - "name": "test_queue" - }, - "createdAt": 1635702165317, - "publishedAt": 1635702167654, - "scheduledAt": null, - "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", - "ttl": 0, - "retryDelay": 0, - "retryThreshold": 3, - "consumeTimeout": 0 - } - ] + "data": { + "total": 1, + "items": [ + { + "body": { "hello": "world" }, + "priority": 4, + "scheduledCron": null, + "scheduledDelay": null, + "scheduledRepeatPeriod": null, + "scheduledRepeat": 0, + "scheduledCronFired": false, + "attempts": 0, + "scheduledRepeatCount": 0, + "delayed": false, + "expired": false, + "queue": { + "ns": "my-application", + "name": "test_queue" + }, + "createdAt": 1635702165317, + "publishedAt": 1635702167654, + "scheduledAt": null, + "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", + "ttl": 0, + "retryDelay": 0, + "retryThreshold": 3, + "consumeTimeout": 0 + } + ] + } } ``` -### DELETE /api/queues/:queueName/ns/:ns/pending-messages-with-priority +### DELETE /api/ns/:ns/queues/:queueName/pending-messages-with-priority **Path parameters** @@ -432,7 +495,7 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( 204 No Content ``` -### DELETE /api/queues/:queueName/ns/:ns/pending-messages-with-priority/:id +### DELETE /api/ns/:ns/queues/:queueName/pending-messages-with-priority/:id **Path parameters** @@ -459,34 +522,36 @@ To start using the HTTP API, you should first [configure and launch the Web UI]( ```text { - "total": 1, - "items": [ - { - "body": { "hello": "world" }, - "priority": null, - "scheduledCron": null, - "scheduledDelay": null, - "scheduledRepeatPeriod": 10000, - "scheduledRepeat": 6, - "scheduledCronFired": false, - "attempts": 0, - "scheduledRepeatCount": 0, - "delayed": false, - "expired": false, - "queue": { - "ns": "my-application", - "name": "test_queue" - }, - "createdAt": 1635702165317, - "publishedAt": null, - "scheduledAt": 1635702163487, - "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", - "ttl": 0, - "retryDelay": 0, - "retryThreshold": 3, - "consumeTimeout": 0 - } - ] + "data": { + "total": 1, + "items": [ + { + "body": { "hello": "world" }, + "priority": null, + "scheduledCron": null, + "scheduledDelay": null, + "scheduledRepeatPeriod": 10000, + "scheduledRepeat": 6, + "scheduledCronFired": false, + "attempts": 0, + "scheduledRepeatCount": 0, + "delayed": false, + "expired": false, + "queue": { + "ns": "my-application", + "name": "test_queue" + }, + "createdAt": 1635702165317, + "publishedAt": null, + "scheduledAt": 1635702163487, + "uuid": "9e7b8046-200c-48de-aa9f-2caf0a172a83", + "ttl": 0, + "retryDelay": 0, + "retryThreshold": 3, + "consumeTimeout": 0 + } + ] + } } ``` diff --git a/src/monitor-server/controllers/api/api-controller.ts b/src/monitor-server/controllers/api/api-controller.ts index a2420a8a..d45f3662 100644 --- a/src/monitor-server/controllers/api/api-controller.ts +++ b/src/monitor-server/controllers/api/api-controller.ts @@ -1,8 +1,9 @@ import { IRouteController } from '../../lib/routing'; import { mainController } from './main/main.controller'; import { queuesController } from './queues/queues.controller'; +import { namespacesController } from './namespaces/namespaces.controller'; export const apiController: IRouteController = { path: '/api', - actions: [mainController, queuesController], + actions: [mainController, namespacesController, queuesController], }; diff --git a/src/monitor-server/controllers/api/main/scheduled-messages/context.ts b/src/monitor-server/controllers/api/main/scheduled-messages/context.ts deleted file mode 100644 index 54619f52..00000000 --- a/src/monitor-server/controllers/api/main/scheduled-messages/context.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { TRequestContext } from '../../../../types/common'; -import { GetScheduledMessagesRequestDTO } from './get-scheduled-messages/get-scheduled-messages.request.DTO'; -import { GetMessagesResponseBodyDataDTO } from '../../../common/dto/queues/get-messages-response-body.DTO'; -import { DeleteScheduledMessageRequestDTO } from './delete-scheduled-message/delete-scheduled-message-request.DTO'; - -export type TGetScheduledMessagesContext = TRequestContext< - GetScheduledMessagesRequestDTO, - GetMessagesResponseBodyDataDTO ->; -export type TDeleteScheduledMessageContext = - TRequestContext; diff --git a/src/monitor-server/controllers/api/main/scheduled-messages/delete-scheduled-message/delete-scheduled-message.handler.ts b/src/monitor-server/controllers/api/main/scheduled-messages/delete-scheduled-message/delete-scheduled-message.handler.ts index f0ef82b7..0c14b34c 100644 --- a/src/monitor-server/controllers/api/main/scheduled-messages/delete-scheduled-message/delete-scheduled-message.handler.ts +++ b/src/monitor-server/controllers/api/main/scheduled-messages/delete-scheduled-message/delete-scheduled-message.handler.ts @@ -1,9 +1,13 @@ -import { TApplication } from '../../../../../types/common'; -import { TDeleteScheduledMessageContext } from '../context'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { DeleteScheduledMessageRequestDTO } from './delete-scheduled-message-request.DTO'; +import { DeleteScheduledMessageResponseDTO } from './delete-scheduled-message-response.DTO'; -export function DeleteScheduledMessageHandler(app: TApplication) { - return async (ctx: TDeleteScheduledMessageContext) => { +export const DeleteScheduledMessageHandler: TRouteControllerActionHandler< + DeleteScheduledMessageRequestDTO, + DeleteScheduledMessageResponseDTO +> = (app) => { + return async (ctx) => { const { messagesService } = app.context.services; return messagesService.deleteScheduledMessage(ctx.state.dto); }; -} +}; diff --git a/src/monitor-server/controllers/api/main/scheduled-messages/get-scheduled-messages/get-scheduled-messages.handler.ts b/src/monitor-server/controllers/api/main/scheduled-messages/get-scheduled-messages/get-scheduled-messages.handler.ts index 092f7d0c..76f137fd 100644 --- a/src/monitor-server/controllers/api/main/scheduled-messages/get-scheduled-messages/get-scheduled-messages.handler.ts +++ b/src/monitor-server/controllers/api/main/scheduled-messages/get-scheduled-messages/get-scheduled-messages.handler.ts @@ -1,9 +1,13 @@ -import { TApplication } from '../../../../../types/common'; -import { TGetScheduledMessagesContext } from '../context'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { GetScheduledMessagesRequestDTO } from './get-scheduled-messages.request.DTO'; +import { GetScheduledMessagesResponseDTO } from './get-scheduled-messages.response.DTO'; -export function GetScheduledMessagesHandler(app: TApplication) { - return async (ctx: TGetScheduledMessagesContext) => { +export const GetScheduledMessagesHandler: TRouteControllerActionHandler< + GetScheduledMessagesRequestDTO, + GetScheduledMessagesResponseDTO +> = (app) => { + return async (ctx) => { const { messagesService } = app.context.services; return messagesService.getScheduledMessages(ctx.state.dto); }; -} +}; diff --git a/src/monitor-server/controllers/api/main/scheduled-messages/purge-scheduled-messages/purge-scheduled-messages.handler.ts b/src/monitor-server/controllers/api/main/scheduled-messages/purge-scheduled-messages/purge-scheduled-messages.handler.ts index f59586a0..1b538d83 100644 --- a/src/monitor-server/controllers/api/main/scheduled-messages/purge-scheduled-messages/purge-scheduled-messages.handler.ts +++ b/src/monitor-server/controllers/api/main/scheduled-messages/purge-scheduled-messages/purge-scheduled-messages.handler.ts @@ -1,8 +1,13 @@ -import { TApplication } from '../../../../../types/common'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { PurgeScheduledMessagesRequestDTO } from './purge-scheduled-messages.request.DTO'; +import { PurgeScheduledMessagesResponseDTO } from './purge-scheduled-messages.response.DTO'; -export function PurgeScheduledMessagesHandler(app: TApplication) { +export const PurgeScheduledMessagesHandler: TRouteControllerActionHandler< + PurgeScheduledMessagesRequestDTO, + PurgeScheduledMessagesResponseDTO +> = (app) => { return async () => { const { messagesService } = app.context.services; return messagesService.purgeScheduledMessages(); }; -} +}; diff --git a/src/monitor-server/controllers/api/main/time-series/get-acknowledged/get-acknowledged.handler.ts b/src/monitor-server/controllers/api/main/time-series/get-acknowledged/get-acknowledged.handler.ts index a5c87507..be316ee4 100644 --- a/src/monitor-server/controllers/api/main/time-series/get-acknowledged/get-acknowledged.handler.ts +++ b/src/monitor-server/controllers/api/main/time-series/get-acknowledged/get-acknowledged.handler.ts @@ -1,9 +1,13 @@ -import { TApplication } from '../../../../../types/common'; -import { TTimeSeriesRequestContext } from '../../../queues/queue/time-series/context'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { GetAcknowledgedRequestDTO } from './get-acknowledged.request.DTO'; +import { GetAcknowledgedResponseDTO } from './get-acknowledged.response.DTO'; -export function GetAcknowledgedHandler(app: TApplication) { - return async (ctx: TTimeSeriesRequestContext) => { +export const GetAcknowledgedHandler: TRouteControllerActionHandler< + GetAcknowledgedRequestDTO, + GetAcknowledgedResponseDTO +> = (app) => { + return async (ctx) => { const { globalTimeSeriesService } = app.context.services; return globalTimeSeriesService.acknowledged(ctx.state.dto); }; -} +}; diff --git a/src/monitor-server/controllers/api/main/time-series/get-dead-lettered/get-dead-lettered.handler.ts b/src/monitor-server/controllers/api/main/time-series/get-dead-lettered/get-dead-lettered.handler.ts index 9d2043fd..a7ccbf01 100644 --- a/src/monitor-server/controllers/api/main/time-series/get-dead-lettered/get-dead-lettered.handler.ts +++ b/src/monitor-server/controllers/api/main/time-series/get-dead-lettered/get-dead-lettered.handler.ts @@ -1,9 +1,13 @@ -import { TApplication } from '../../../../../types/common'; -import { TTimeSeriesRequestContext } from '../../../queues/queue/time-series/context'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { GetDeadLetteredRequestDTO } from './get-dead-lettered.request.DTO'; +import { GetDeadLetteredResponseDTO } from './get-dead-lettered.response.DTO'; -export function GetDeadLetteredHandler(app: TApplication) { - return async (ctx: TTimeSeriesRequestContext) => { +export const GetDeadLetteredHandler: TRouteControllerActionHandler< + GetDeadLetteredRequestDTO, + GetDeadLetteredResponseDTO +> = (app) => { + return async (ctx) => { const { globalTimeSeriesService } = app.context.services; return globalTimeSeriesService.deadLettered(ctx.state.dto); }; -} +}; diff --git a/src/monitor-server/controllers/api/main/time-series/get-published-time-series/get-published.handler.ts b/src/monitor-server/controllers/api/main/time-series/get-published-time-series/get-published.handler.ts index 64a86f5b..0760d498 100644 --- a/src/monitor-server/controllers/api/main/time-series/get-published-time-series/get-published.handler.ts +++ b/src/monitor-server/controllers/api/main/time-series/get-published-time-series/get-published.handler.ts @@ -1,9 +1,13 @@ -import { TApplication } from '../../../../../types/common'; -import { TTimeSeriesRequestContext } from '../../../queues/queue/time-series/context'; +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { GetPublishedRequestDTO } from './get-published.request.DTO'; +import { GetPublishedResponseDTO } from './get-published.response.DTO'; -export function GetPublishedHandler(app: TApplication) { - return async (ctx: TTimeSeriesRequestContext) => { +export const GetPublishedHandler: TRouteControllerActionHandler< + GetPublishedRequestDTO, + GetPublishedResponseDTO +> = (app) => { + return async (ctx) => { const { globalTimeSeriesService } = app.context.services; return globalTimeSeriesService.published(ctx.state.dto); }; -} +}; diff --git a/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.handler.ts b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.handler.ts new file mode 100644 index 00000000..f4a7b70f --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../lib/routing'; +import { DeleteNamespaceRequestDTO } from './delete-namespace.request.DTO'; +import { DeleteNamespaceResponseDTO } from './delete-namespace.response.DTO'; + +export const DeleteNamespaceHandler: TRouteControllerActionHandler< + DeleteNamespaceRequestDTO, + DeleteNamespaceResponseDTO +> = (app) => { + return async (ctx) => { + const { queuesService } = app.context.services; + return queuesService.deleteNamespace(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.request.DTO.ts new file mode 100644 index 00000000..f468a1af --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.request.DTO.ts @@ -0,0 +1,3 @@ +import { NamespaceRequestDTO } from '../../../common/dto/namespaces/namespace-request.DTO'; + +export class DeleteNamespaceRequestDTO extends NamespaceRequestDTO {} diff --git a/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.response.DTO.ts new file mode 100644 index 00000000..800a5863 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/delete-namespace/delete-namespace.response.DTO.ts @@ -0,0 +1,3 @@ +import { NoContentHttpResponseDTO } from '../../../common/dto/no-content-http-response.DTO'; + +export class DeleteNamespaceResponseDTO extends NoContentHttpResponseDTO {} diff --git a/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.handler.ts b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.handler.ts new file mode 100644 index 00000000..6afbf80c --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../lib/routing'; +import { GetNamespaceQueuesRequestDTO } from './get-namespace-queues.request.DTO'; +import { GetNamespaceQueuesResponseDTO } from './get-namespace-queues.response.DTO'; + +export const GetNamespaceQueuesHandler: TRouteControllerActionHandler< + GetNamespaceQueuesRequestDTO, + GetNamespaceQueuesResponseDTO +> = (app) => { + return async (ctx) => { + const { queuesService } = app.context.services; + return queuesService.getNamespaceQueues(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.request.DTO.ts new file mode 100644 index 00000000..50d17594 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.request.DTO.ts @@ -0,0 +1,3 @@ +import { NamespaceRequestDTO } from '../../../common/dto/namespaces/namespace-request.DTO'; + +export class GetNamespaceQueuesRequestDTO extends NamespaceRequestDTO {} diff --git a/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.response.DTO.ts new file mode 100644 index 00000000..a0eac488 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespace-queues/get-namespace-queues.response.DTO.ts @@ -0,0 +1,12 @@ +import { IsInt, ValidateNested } from 'class-validator'; +import { Type } from 'class-transformer'; +import { GetQueuesResponseBodyDTO } from '../../queues/get-queues/get-queues.response.DTO'; + +export class GetNamespaceQueuesResponseDTO { + @IsInt() + status!: number; + + @ValidateNested() + @Type(() => GetQueuesResponseBodyDTO) + body!: GetQueuesResponseBodyDTO; +} diff --git a/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.handler.ts b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.handler.ts new file mode 100644 index 00000000..4be2f453 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../lib/routing'; +import { GetNamespacesRequestDTO } from './get-namespaces.request.DTO'; +import { GetNamespacesResponseDTO } from './get-namespaces.response.DTO'; + +export const GetNamespacesHandler: TRouteControllerActionHandler< + GetNamespacesRequestDTO, + GetNamespacesResponseDTO +> = (app) => { + return async () => { + const { queuesService } = app.context.services; + return queuesService.getNamespaces(); + }; +}; diff --git a/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.request.DTO.ts new file mode 100644 index 00000000..7fda428b --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.request.DTO.ts @@ -0,0 +1 @@ +export class GetNamespacesRequestDTO {} diff --git a/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.response.DTO.ts new file mode 100644 index 00000000..61621949 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/get-namespaces/get-namespaces.response.DTO.ts @@ -0,0 +1,16 @@ +import { IsInt, IsString, ValidateNested } from 'class-validator'; +import { Type } from 'class-transformer'; + +export class GetNamespacesResponseBodyDTO { + @IsString({ each: true }) + data!: string[]; +} + +export class GetNamespacesResponseDTO { + @IsInt() + status!: number; + + @ValidateNested() + @Type(() => GetNamespacesResponseBodyDTO) + body!: GetNamespacesResponseBodyDTO; +} diff --git a/src/monitor-server/controllers/api/namespaces/namespaces.controller.ts b/src/monitor-server/controllers/api/namespaces/namespaces.controller.ts new file mode 100644 index 00000000..6b20f75a --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/namespaces.controller.ts @@ -0,0 +1,56 @@ +import { + ERouteControllerActionMethod, + ERouteControllerActionPayload, + IRouteController, +} from '../../../lib/routing'; +import { GetNamespacesRequestDTO } from './get-namespaces/get-namespaces.request.DTO'; +import { GetNamespacesResponseDTO } from './get-namespaces/get-namespaces.response.DTO'; +import { GetNamespacesHandler } from './get-namespaces/get-namespaces.handler'; +import { GetNamespaceQueuesHandler } from './get-namespace-queues/get-namespace-queues.handler'; +import { GetNamespaceQueuesRequestDTO } from './get-namespace-queues/get-namespace-queues.request.DTO'; +import { GetNamespaceQueuesResponseDTO } from './get-namespace-queues/get-namespace-queues.response.DTO'; +import { DeleteNamespaceHandler } from './delete-namespace/delete-namespace.handler'; +import { DeleteNamespaceRequestDTO } from './delete-namespace/delete-namespace.request.DTO'; +import { DeleteNamespaceResponseDTO } from './delete-namespace/delete-namespace.response.DTO'; +import { queueController } from './queue/queue.controller'; + +export const namespacesController: IRouteController = { + path: '/ns', + actions: [ + { + path: '/', + method: ERouteControllerActionMethod.GET, + payload: [], + Handler: GetNamespacesHandler, + RequestDTO: GetNamespacesRequestDTO, + ResponseDTO: GetNamespacesResponseDTO, + }, + { + path: '/:ns', + actions: [ + { + path: '/', + method: ERouteControllerActionMethod.DELETE, + payload: [ERouteControllerActionPayload.PATH], + Handler: DeleteNamespaceHandler, + RequestDTO: DeleteNamespaceRequestDTO, + ResponseDTO: DeleteNamespaceResponseDTO, + }, + { + path: '/queues', + actions: [ + { + path: '/', + method: ERouteControllerActionMethod.GET, + payload: [ERouteControllerActionPayload.PATH], + Handler: GetNamespaceQueuesHandler, + RequestDTO: GetNamespaceQueuesRequestDTO, + ResponseDTO: GetNamespaceQueuesResponseDTO, + }, + queueController, + ], + }, + ], + }, + ], +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts new file mode 100644 index 00000000..600f818d --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { DeleteAcknowledgedMessageRequestDTO } from './delete-acknowledged-message.request.DTO'; +import { DeleteAcknowledgedMessageResponseDTO } from './delete-acknowledged-message.response.DTO'; + +export const DeleteAcknowledgedMessageHandler: TRouteControllerActionHandler< + DeleteAcknowledgedMessageRequestDTO, + DeleteAcknowledgedMessageResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.deleteAcknowledgedMessage(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts new file mode 100644 index 00000000..b1aa1cbd --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetAcknowledgedMessagesRequestDTO } from './get-acknowledged-messages.request.DTO'; +import { GetAcknowledgedMessagesResponseDTO } from './get-acknowledged-messages.response.DTO'; + +export const GetAcknowledgedMessagesHandler: TRouteControllerActionHandler< + GetAcknowledgedMessagesRequestDTO, + GetAcknowledgedMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.getAcknowledgedMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts new file mode 100644 index 00000000..d8b49e27 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { PurgeAcknowledgedMessagesRequestDTO } from './purge-acknowledged-messages.request.DTO'; +import { PurgeAcknowledgedMessagesResponseDTO } from './purge-acknowledged-messages.response.DTO'; + +export const PurgeAcknowledgedMessagesHandler: TRouteControllerActionHandler< + PurgeAcknowledgedMessagesRequestDTO, + PurgeAcknowledgedMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.purgeAcknowledgedMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts new file mode 100644 index 00000000..caf83d40 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { RequeueAcknowledgedMessageRequestDTO } from './requeue-acknowledged-message.request.DTO'; +import { RequeueAcknowledgedMessageResponseDTO } from './requeue-acknowledged-message.response.DTO'; + +export const RequeueAcknowledgedMessageHandler: TRouteControllerActionHandler< + RequeueAcknowledgedMessageRequestDTO, + RequeueAcknowledgedMessageResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + await messagesService.requeueAcknowledgedMessage(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.response.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/consumer/time-series/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts new file mode 100644 index 00000000..41791b5c --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../../lib/routing'; +import { GetConsumerAcknowledgedRequestDTO } from './get-consumer-acknowledged.request.DTO'; +import { GetConsumerAcknowledgedResponseDTO } from './get-consumer-acknowledged.response.DTO'; + +export const GetConsumerAcknowledgedHandler: TRouteControllerActionHandler< + GetConsumerAcknowledgedRequestDTO, + GetConsumerAcknowledgedResponseDTO +> = (app) => { + return async (ctx) => { + const { consumerTimeSeriesService } = app.context.services; + return consumerTimeSeriesService.acknowledged(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts new file mode 100644 index 00000000..7c378fab --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../../lib/routing'; +import { GetConsumerDeadLetteredRequestDTO } from './get-consumer-dead-lettered.request.DTO'; +import { GetConsumerDeadLetteredResponseDTO } from './get-consumer-dead-lettered.response.DTO'; + +export const GetConsumerDeadLetteredHandler: TRouteControllerActionHandler< + GetConsumerDeadLetteredRequestDTO, + GetConsumerDeadLetteredResponseDTO +> = (app) => { + return async (ctx) => { + const { consumerTimeSeriesService } = app.context.services; + return consumerTimeSeriesService.deadLettered(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.response.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts new file mode 100644 index 00000000..97c2fdfd --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { DeleteDeadLetteredMessageRequestDTO } from './delete-dead-lettered-message.request.DTO'; +import { DeleteDeadLetteredMessageResponseDTO } from './delete-dead-lettered-message.response.DTO'; + +export const DeleteDeadLetteredMessageHandler: TRouteControllerActionHandler< + DeleteDeadLetteredMessageRequestDTO, + DeleteDeadLetteredMessageResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.deleteDeadLetteredMessage(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts new file mode 100644 index 00000000..650acaf7 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetDeadLetteredMessagesRequestDTO } from './get-dead-lettered-messages.request.DTO'; +import { GetDeadLetteredMessagesResponseDTO } from './get-dead-lettered-messages.response.DTO'; + +export const GetDeadLetteredMessagesHandler: TRouteControllerActionHandler< + GetDeadLetteredMessagesRequestDTO, + GetDeadLetteredMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.getDeadLetteredMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts new file mode 100644 index 00000000..f931faba --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { PurgeDeadLetteredMessagesRequestDTO } from './purge-dead-lettered-messages.request.DTO'; +import { PurgeDeadLetteredMessagesResponseDTO } from './purge-dead-lettered-messages.response.DTO'; + +export const PurgeDeadLetteredMessagesHandler: TRouteControllerActionHandler< + PurgeDeadLetteredMessagesRequestDTO, + PurgeDeadLetteredMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.purgeDeadLetteredMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts new file mode 100644 index 00000000..ad387136 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { RequeueDeadLetteredMessageRequestDTO } from './requeue-dead-lettered-message.request.DTO'; +import { RequeueDeadLetteredMessageResponseDTO } from './requeue-dead-lettered-message.response.DTO'; + +export const RequeueDeadLetteredMessageHandler: TRouteControllerActionHandler< + RequeueDeadLetteredMessageRequestDTO, + RequeueDeadLetteredMessageResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + await messagesService.requeueDeadLetteredMessage(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.handler.ts new file mode 100644 index 00000000..e19fd3f0 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../lib/routing'; +import { DeleteQueueRequestDTO } from './delete-queue.request.DTO'; +import { DeleteQueueResponseDTO } from './delete-queue.response.DTO'; + +export const DeleteQueueHandler: TRouteControllerActionHandler< + DeleteQueueRequestDTO, + DeleteQueueResponseDTO +> = (app) => { + return async (ctx) => { + const { queuesService } = app.context.services; + return queuesService.deleteQueue(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/delete-queue/delete-queue.response.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts new file mode 100644 index 00000000..a327ef81 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { DeletePendingMessageWithPriorityRequestDTO } from './delete-pending-message-with-priority.request.DTO'; +import { DeletePendingMessageWithPriorityResponseDTO } from './delete-pending-message-with-priority.response.DTO'; + +export const DeletePendingMessageWithPriorityHandler: TRouteControllerActionHandler< + DeletePendingMessageWithPriorityRequestDTO, + DeletePendingMessageWithPriorityResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.deletePendingMessageWithPriority(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts new file mode 100644 index 00000000..a2d081fe --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetPendingMessagesWithPriorityRequestDTO } from './get-pending-messages-with-priority.request.DTO'; +import { GetPendingMessagesWithPriorityResponseDTO } from './get-pending-messages-with-priority.response.DTO'; + +export const GetPendingMessagesWithPriorityHandler: TRouteControllerActionHandler< + GetPendingMessagesWithPriorityRequestDTO, + GetPendingMessagesWithPriorityResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.getPendingMessagesWithPriority(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts new file mode 100644 index 00000000..e0531159 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { PurgePendingMessagesWithPriorityRequestDTO } from './purge-pending-messages-with-priority.request.DTO'; +import { PurgePendingMessagesWithPriorityResponseDTO } from './purge-pending-messages-with-priority.response.DTO'; + +export const PurgePendingMessagesWithPriorityHandler: TRouteControllerActionHandler< + PurgePendingMessagesWithPriorityRequestDTO, + PurgePendingMessagesWithPriorityResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.purgePendingMessagesWithPriority(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.response.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts new file mode 100644 index 00000000..19c98c15 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { DeletePendingMessageRequestDTO } from './delete-pending-message.request.DTO'; +import { DeletePendingMessageResponseDTO } from './delete-pending-message.response.DTO'; + +export const DeletePendingMessageHandler: TRouteControllerActionHandler< + DeletePendingMessageRequestDTO, + DeletePendingMessageResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.deletePendingMessage(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts new file mode 100644 index 00000000..59b719a9 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetPendingMessagesRequestDTO } from './get-pending-messages.request.DTO'; +import { GetPendingMessagesResponseDTO } from './get-pending-messages.response.DTO'; + +export const GetPendingMessagesHandler: TRouteControllerActionHandler< + GetPendingMessagesRequestDTO, + GetPendingMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.getPendingMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts new file mode 100644 index 00000000..797f5cc2 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { PurgePendingMessagesRequestDTO } from './purge-pending-messages.request.DTO'; +import { PurgePendingMessagesResponseDTO } from './purge-pending-messages.response.DTO'; + +export const PurgePendingMessagesHandler: TRouteControllerActionHandler< + PurgePendingMessagesRequestDTO, + PurgePendingMessagesResponseDTO +> = (app) => { + return async (ctx) => { + const { messagesService } = app.context.services; + return messagesService.purgePendingMessages(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/queue.controller.ts b/src/monitor-server/controllers/api/namespaces/queue/queue.controller.ts new file mode 100644 index 00000000..960c2a37 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/queue.controller.ts @@ -0,0 +1,34 @@ +import { + ERouteControllerActionMethod, + ERouteControllerActionPayload, + IRouteController, +} from '../../../../lib/routing'; +import { DeleteQueueHandler } from './delete-queue/delete-queue.handler'; +import { DeleteQueueRequestDTO } from './delete-queue/delete-queue.request.DTO'; +import { DeleteQueueResponseDTO } from './delete-queue/delete-queue.response.DTO'; +import { controller as queueDeadLetteredMessagesController } from './dead-lettered-messages/controller'; +import { controller as queueAcknowledgedMessagesController } from './acknowledged-messages/controller'; +import { controller as queuePendingMessagesWithPriorityController } from './pending-messages-with-priority/controller'; +import { controller as queuePendingMessagesController } from './pending-messages/controller'; +import { controller as queueTimeSeriesController } from './time-series/controller'; +import { controller as queueConsumerTimeSeriesController } from './consumer/time-series/controller'; + +export const queueController: IRouteController = { + path: '/:queueName', + actions: [ + { + path: '/', + method: ERouteControllerActionMethod.DELETE, + payload: [ERouteControllerActionPayload.PATH], + Handler: DeleteQueueHandler, + RequestDTO: DeleteQueueRequestDTO, + ResponseDTO: DeleteQueueResponseDTO, + }, + queueDeadLetteredMessagesController, + queueAcknowledgedMessagesController, + queuePendingMessagesWithPriorityController, + queuePendingMessagesController, + queueTimeSeriesController, + queueConsumerTimeSeriesController, + ], +}; diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/controller.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/controller.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/controller.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/controller.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts new file mode 100644 index 00000000..3efd3f54 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetQueueAcknowledgedRequestDTO } from './get-queue-acknowledged.request.DTO'; +import { GetQueueAcknowledgedResponseDTO } from './get-queue-acknowledged.response.DTO'; + +export const GetQueueAcknowledgedHandler: TRouteControllerActionHandler< + GetQueueAcknowledgedRequestDTO, + GetQueueAcknowledgedResponseDTO +> = (app) => { + return async (ctx) => { + const { queueTimeSeriesService } = app.context.services; + return queueTimeSeriesService.acknowledged(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts new file mode 100644 index 00000000..b4e4ff58 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetQueueDeadLetteredRequestDTO } from './get-queue-dead-lettered.request.DTO'; +import { GetQueueDeadLetteredResponseDTO } from './get-queue-dead-lettered.response.DTO'; + +export const GetQueueDeadLetteredHandler: TRouteControllerActionHandler< + GetQueueDeadLetteredRequestDTO, + GetQueueDeadLetteredResponseDTO +> = (app) => { + return async (ctx) => { + const { queueTimeSeriesService } = app.context.services; + return queueTimeSeriesService.deadLettered(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.response.DTO.ts diff --git a/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.handler.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.handler.ts new file mode 100644 index 00000000..544b73b8 --- /dev/null +++ b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.handler.ts @@ -0,0 +1,13 @@ +import { TRouteControllerActionHandler } from '../../../../../../lib/routing'; +import { GetQueuePublishedRequestDTO } from './get-queue-published.request.DTO'; +import { GetQueuePublishedResponseDTO } from './get-queue-published.response.DTO'; + +export const GetQueuePublishedHandler: TRouteControllerActionHandler< + GetQueuePublishedRequestDTO, + GetQueuePublishedResponseDTO +> = (app) => { + return async (ctx) => { + const { queueTimeSeriesService } = app.context.services; + return queueTimeSeriesService.published(ctx.state.dto); + }; +}; diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.request.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.request.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.request.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.request.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.response.DTO.ts b/src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.response.DTO.ts similarity index 100% rename from src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.response.DTO.ts rename to src/monitor-server/controllers/api/namespaces/queue/time-series/get-queue-published/get-queue-published.response.DTO.ts diff --git a/src/monitor-server/controllers/api/queues/get-queues/get-queues.handler.ts b/src/monitor-server/controllers/api/queues/get-queues/get-queues.handler.ts index 06f6d83f..5da46f80 100644 --- a/src/monitor-server/controllers/api/queues/get-queues/get-queues.handler.ts +++ b/src/monitor-server/controllers/api/queues/get-queues/get-queues.handler.ts @@ -1,8 +1,12 @@ import { TApplication } from '../../../../types/common'; +import { GetQueuesRequestDTO } from './get-queues.request.DTO'; +import { TRouteControllerActionHandler } from '../../../../lib/routing'; +import { GetQueuesResponseDTO } from './get-queues.response.DTO'; -export function GetQueuesHandler(app: TApplication) { - return async () => { - const { queuesService } = app.context.services; - return queuesService.getQueues(); - }; -} +export const GetQueuesHandler: TRouteControllerActionHandler< + GetQueuesRequestDTO, + GetQueuesResponseDTO +> = (app: TApplication) => async () => { + const { queuesService } = app.context.services; + return queuesService.getQueues(); +}; diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts b/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts deleted file mode 100644 index ad5c3204..00000000 --- a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TDeleteMessageContext } from '../../context'; - -export function DeleteAcknowledgedMessageHandler(app: TApplication) { - return async (ctx: TDeleteMessageContext) => { - const { messagesService } = app.context.services; - return messagesService.deleteAcknowledgedMessage(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts deleted file mode 100644 index d76aee9a..00000000 --- a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TGetMessagesContext } from '../../context'; - -export function GetAcknowledgedMessagesHandler(app: TApplication) { - return async (ctx: TGetMessagesContext) => { - const { messagesService } = app.context.services; - return messagesService.getAcknowledgedMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts deleted file mode 100644 index 1f64603a..00000000 --- a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TPurgeQueueContext } from '../../context'; - -export function PurgeAcknowledgedMessagesHandler(app: TApplication) { - return async (ctx: TPurgeQueueContext) => { - const { messagesService } = app.context.services; - return messagesService.purgeAcknowledgedMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts b/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts deleted file mode 100644 index 31c0e673..00000000 --- a/src/monitor-server/controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TRequeueMessageContext } from '../../context'; - -export function RequeueAcknowledgedMessageHandler(app: TApplication) { - return async (ctx: TRequeueMessageContext) => { - const { messagesService } = app.context.services; - await messagesService.requeueAcknowledgedMessage(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts b/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts deleted file mode 100644 index 6a30f28c..00000000 --- a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../../types/common'; -import { TConsumerTimeSeriesRequestContext } from '../../../time-series/context'; - -export function GetConsumerAcknowledgedHandler(app: TApplication) { - return async (ctx: TConsumerTimeSeriesRequestContext) => { - const { consumerTimeSeriesService } = app.context.services; - return consumerTimeSeriesService.acknowledged(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts b/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts deleted file mode 100644 index ebff8ad7..00000000 --- a/src/monitor-server/controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../../types/common'; -import { TConsumerTimeSeriesRequestContext } from '../../../time-series/context'; - -export function GetConsumerDeadLetteredHandler(app: TApplication) { - return async (ctx: TConsumerTimeSeriesRequestContext) => { - const { consumerTimeSeriesService } = app.context.services; - return consumerTimeSeriesService.deadLettered(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/context.ts b/src/monitor-server/controllers/api/queues/queue/context.ts deleted file mode 100644 index 29a9e088..00000000 --- a/src/monitor-server/controllers/api/queues/queue/context.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { TRequestContext } from '../../../../types/common'; -import { GetMessagesRequestDTO } from '../../../common/dto/queues/get-messages-request.DTO'; -import { GetMessagesResponseBodyDataDTO } from '../../../common/dto/queues/get-messages-response-body.DTO'; -import { DeleteMessageRequestDTO } from '../../../common/dto/queues/delete-message-request.DTO'; -import { RequeueMessageRequestDTO } from '../../../common/dto/queues/requeue-message-request.DTO'; -import { PurgeMessagesRequestDTO } from '../../../common/dto/queues/purge-messages-request.DTO'; - -export type TGetMessagesContext = TRequestContext< - GetMessagesRequestDTO, - GetMessagesResponseBodyDataDTO ->; -export type TDeleteMessageContext = TRequestContext; -export type TRequeueMessageContext = TRequestContext; -export type TPurgeQueueContext = TRequestContext; diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts b/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts deleted file mode 100644 index e675a935..00000000 --- a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TDeleteMessageContext } from '../../context'; - -export function DeleteDeadLetteredMessageHandler(app: TApplication) { - return async (ctx: TDeleteMessageContext) => { - const { messagesService } = app.context.services; - return messagesService.deleteDeadLetteredMessage(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts deleted file mode 100644 index 1c612ab5..00000000 --- a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TGetMessagesContext } from '../../context'; - -export function GetDeadLetteredMessagesHandler(app: TApplication) { - return async (ctx: TGetMessagesContext) => { - const { messagesService } = app.context.services; - return messagesService.getDeadLetteredMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts deleted file mode 100644 index 70157303..00000000 --- a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TPurgeQueueContext } from '../../context'; - -export function PurgeDeadLetteredMessagesHandler(app: TApplication) { - return async (ctx: TPurgeQueueContext) => { - const { messagesService } = app.context.services; - return messagesService.purgeDeadLetteredMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts b/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts deleted file mode 100644 index 1d05d72f..00000000 --- a/src/monitor-server/controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TRequeueMessageContext } from '../../context'; - -export function RequeueDeadLetteredMessageHandler(app: TApplication) { - return async (ctx: TRequeueMessageContext) => { - const { messagesService } = app.context.services; - await messagesService.requeueDeadLetteredMessage(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.handler.ts b/src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.handler.ts deleted file mode 100644 index d09dcb6e..00000000 --- a/src/monitor-server/controllers/api/queues/queue/delete-queue/delete-queue.handler.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { TApplication, TRequestContext } from '../../../../../types/common'; -import { DeleteMessageRequestDTO } from '../../../../common/dto/queues/delete-message-request.DTO'; - -export type TDeleteQueueContext = TRequestContext; - -export function DeleteQueueHandler(app: TApplication) { - return async (ctx: TDeleteQueueContext) => { - const { queuesService } = app.context.services; - return queuesService.deleteQueue(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts deleted file mode 100644 index 303b527a..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TDeleteMessageContext } from '../../context'; - -export function DeletePendingMessageWithPriorityHandler(app: TApplication) { - return async (ctx: TDeleteMessageContext) => { - const { messagesService } = app.context.services; - return messagesService.deletePendingMessageWithPriority(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts deleted file mode 100644 index e3040dee..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TGetMessagesContext } from '../../context'; - -export function GetPendingMessagesWithPriorityHandler(app: TApplication) { - return async (ctx: TGetMessagesContext) => { - const { messagesService } = app.context.services; - return messagesService.getPendingMessagesWithPriority(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts deleted file mode 100644 index 64bd5551..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TPurgeQueueContext } from '../../context'; - -export function PurgePendingMessagesWithPriorityHandler(app: TApplication) { - return async (ctx: TPurgeQueueContext) => { - const { messagesService } = app.context.services; - return messagesService.purgePendingMessagesWithPriority(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts deleted file mode 100644 index 4f7aa038..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TDeleteMessageContext } from '../../context'; - -export function DeletePendingMessageHandler(app: TApplication) { - return async (ctx: TDeleteMessageContext) => { - const { messagesService } = app.context.services; - return messagesService.deletePendingMessage(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts deleted file mode 100644 index ca60c191..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TGetMessagesContext } from '../../context'; - -export function GetPendingMessagesHandler(app: TApplication) { - return async (ctx: TGetMessagesContext) => { - const { messagesService } = app.context.services; - return messagesService.getPendingMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts b/src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts deleted file mode 100644 index cd07c8bc..00000000 --- a/src/monitor-server/controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TPurgeQueueContext } from '../../context'; - -export function PurgePendingMessagesHandler(app: TApplication) { - return async (ctx: TPurgeQueueContext) => { - const { messagesService } = app.context.services; - return messagesService.purgePendingMessages(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/context.ts b/src/monitor-server/controllers/api/queues/queue/time-series/context.ts deleted file mode 100644 index 5c566c90..00000000 --- a/src/monitor-server/controllers/api/queues/queue/time-series/context.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { TRequestContext } from '../../../../../types/common'; -import { QueueTimeSeriesRequestDTO } from '../../../../common/dto/queues/queue-time-series-request.DTO'; -import { ConsumerTimeSeriesRequestDTO } from '../../../../common/dto/queues/consumer-time-series-request.DTO'; -import { TimeSeriesRequestDTO } from '../../../../common/dto/time-series/time-series-request.DTO'; - -export type TTimeSeriesRequestContext = TRequestContext; - -export type TQueueTimeSeriesRequestContext = - TRequestContext; - -export type TConsumerTimeSeriesRequestContext = - TRequestContext; diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts b/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts deleted file mode 100644 index e32cdbff..00000000 --- a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-acknowledged/get-queue-acknowledged.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TQueueTimeSeriesRequestContext } from '../context'; - -export function GetQueueAcknowledgedHandler(app: TApplication) { - return async (ctx: TQueueTimeSeriesRequestContext) => { - const { queueTimeSeriesService } = app.context.services; - return queueTimeSeriesService.acknowledged(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts b/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts deleted file mode 100644 index f9f7e2f5..00000000 --- a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-dead-lettered/get-queue-dead-lettered.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TQueueTimeSeriesRequestContext } from '../context'; - -export function GetQueueDeadLetteredHandler(app: TApplication) { - return async (ctx: TQueueTimeSeriesRequestContext) => { - const { queueTimeSeriesService } = app.context.services; - return queueTimeSeriesService.deadLettered(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.handler.ts b/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.handler.ts deleted file mode 100644 index 0d87acc0..00000000 --- a/src/monitor-server/controllers/api/queues/queue/time-series/get-queue-published/get-queue-published.handler.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { TApplication } from '../../../../../../types/common'; -import { TQueueTimeSeriesRequestContext } from '../context'; - -export function GetQueuePublishedHandler(app: TApplication) { - return async (ctx: TQueueTimeSeriesRequestContext) => { - const { queueTimeSeriesService } = app.context.services; - return queueTimeSeriesService.published(ctx.state.dto); - }; -} diff --git a/src/monitor-server/controllers/api/queues/queues.controller.ts b/src/monitor-server/controllers/api/queues/queues.controller.ts index 9c2ac2ab..a367e0da 100644 --- a/src/monitor-server/controllers/api/queues/queues.controller.ts +++ b/src/monitor-server/controllers/api/queues/queues.controller.ts @@ -1,22 +1,11 @@ import { ERouteControllerActionMethod, - ERouteControllerActionPayload, IRouteController, } from '../../../lib/routing'; import { GetQueuesHandler } from './get-queues/get-queues.handler'; import { GetQueuesRequestDTO } from './get-queues/get-queues.request.DTO'; import { GetQueuesResponseDTO } from './get-queues/get-queues.response.DTO'; -import { controller as queueDeadLetteredMessagesController } from './queue/dead-lettered-messages/controller'; -import { controller as queueAcknowledgedMessagesController } from './queue/acknowledged-messages/controller'; -import { controller as queuePendingMessagesWithPriorityController } from './queue/pending-messages-with-priority/controller'; -import { controller as queuePendingMessagesController } from './queue/pending-messages/controller'; -import { controller as queueTimeSeriesController } from './queue/time-series/controller'; -import { controller as queueConsumerTimeSeriesController } from './queue/consumer/time-series/controller'; -import { DeleteQueueHandler } from './queue/delete-queue/delete-queue.handler'; -import { DeleteQueueRequestDTO } from './queue/delete-queue/delete-queue.request.DTO'; -import { DeleteQueueResponseDTO } from './queue/delete-queue/delete-queue.response.DTO'; - export const queuesController: IRouteController = { path: '/queues', actions: [ @@ -28,24 +17,5 @@ export const queuesController: IRouteController = { RequestDTO: GetQueuesRequestDTO, ResponseDTO: GetQueuesResponseDTO, }, - { - path: '/:queueName/ns/:ns', - actions: [ - { - path: '/', - method: ERouteControllerActionMethod.DELETE, - payload: [ERouteControllerActionPayload.PATH], - Handler: DeleteQueueHandler, - RequestDTO: DeleteQueueRequestDTO, - ResponseDTO: DeleteQueueResponseDTO, - }, - queueDeadLetteredMessagesController, - queueAcknowledgedMessagesController, - queuePendingMessagesWithPriorityController, - queuePendingMessagesController, - queueTimeSeriesController, - queueConsumerTimeSeriesController, - ], - }, ], }; diff --git a/src/monitor-server/controllers/common/dto/namespaces/namespace-request.DTO.ts b/src/monitor-server/controllers/common/dto/namespaces/namespace-request.DTO.ts new file mode 100644 index 00000000..258806e8 --- /dev/null +++ b/src/monitor-server/controllers/common/dto/namespaces/namespace-request.DTO.ts @@ -0,0 +1,7 @@ +import { IsNotEmpty, IsString } from 'class-validator'; + +export class NamespaceRequestDTO { + @IsString() + @IsNotEmpty() + ns!: string; +} diff --git a/src/monitor-server/controllers/common/dto/no-content-http-response.DTO.ts b/src/monitor-server/controllers/common/dto/no-content-http-response.DTO.ts index 1598b605..fefafe30 100644 --- a/src/monitor-server/controllers/common/dto/no-content-http-response.DTO.ts +++ b/src/monitor-server/controllers/common/dto/no-content-http-response.DTO.ts @@ -1,9 +1,10 @@ import { Equals, IsInt } from 'class-validator'; +import { TResponseDTO } from '../../../lib/routing'; -export class NoContentHttpResponseDTO { +export class NoContentHttpResponseDTO implements TResponseDTO { @IsInt() status!: number; @Equals(undefined) - body: undefined; + body: void = undefined; } diff --git a/src/monitor-server/controllers/common/dto/queues/message.DTO.ts b/src/monitor-server/controllers/common/dto/queues/message.DTO.ts index 64974e12..8418db08 100644 --- a/src/monitor-server/controllers/common/dto/queues/message.DTO.ts +++ b/src/monitor-server/controllers/common/dto/queues/message.DTO.ts @@ -56,20 +56,16 @@ export class MessageDTO { createdAt!: number; @IsInt() - @IsOptional() - ttl: number | null = null; + ttl!: number; @IsInt() - @IsOptional() - retryThreshold: number | null = null; + retryThreshold!: number; @IsInt() - @IsOptional() - retryDelay: number | null = null; + retryDelay!: number; @IsInt() - @IsOptional() - consumeTimeout: number | null = null; + consumeTimeout!: number; @Allow() body: unknown = null; @@ -95,9 +91,9 @@ export class MessageDTO { @ValidateNested() @Type(() => MessageQueueDTO) - queue!: MessageQueueDTO; + queue: MessageQueueDTO | undefined | null; @ValidateNested() @Type(() => MessageMetadataDTO) - metadata!: MessageMetadataDTO; + metadata: MessageMetadataDTO | undefined | null; } diff --git a/src/monitor-server/controllers/common/dto/queues/queue-request.DTO.ts b/src/monitor-server/controllers/common/dto/queues/queue-request.DTO.ts index 5d2354b3..68d2d146 100644 --- a/src/monitor-server/controllers/common/dto/queues/queue-request.DTO.ts +++ b/src/monitor-server/controllers/common/dto/queues/queue-request.DTO.ts @@ -1,10 +1,7 @@ import { IsNotEmpty, IsString } from 'class-validator'; +import { NamespaceRequestDTO } from '../namespaces/namespace-request.DTO'; -export class QueueRequestDTO { - @IsString() - @IsNotEmpty() - ns!: string; - +export class QueueRequestDTO extends NamespaceRequestDTO { @IsString() @IsNotEmpty() queueName!: string; diff --git a/src/monitor-server/lib/routing.ts b/src/monitor-server/lib/routing.ts index 57b0357a..fa7a0a0f 100644 --- a/src/monitor-server/lib/routing.ts +++ b/src/monitor-server/lib/routing.ts @@ -2,8 +2,14 @@ import * as Router from '@koa/router'; import { ClassConstructor } from 'class-transformer'; import { RequestValidator } from '../middlewares/request-validator'; import { ResponseValidator } from '../middlewares/response-validator'; -import { TApplication, TRequestContext } from '../types/common'; +import { + IContext, + IContextState, + IResponseBody, + TApplication, +} from '../types/common'; import { posix } from 'path'; +import { Next, ParameterizedContext } from 'koa'; export enum ERouteControllerActionPayload { QUERY = 'query', @@ -17,47 +23,73 @@ export enum ERouteControllerActionMethod { DELETE = 'delete', } -export type TRouteControllerActionHandler = ( +export type TRequestContext< + RequestDTO, + ResponseDTO extends TResponseDTO, +> = ParameterizedContext< + IContextState, + IContext, + ResponseDTO['body'] +>; + +export type TResponseDTO = { + status: number; + body: IResponseBody | void; +}; + +export class CRequestDTO {} + +export type TRouteControllerActionHandler< + RequestDTO extends CRequestDTO, + ResponseDTO extends TResponseDTO, +> = ( app: TApplication, -) => (ctx: TRequestContext) => Promise | void>; +) => ( + ctx: TRequestContext, +) => Promise< + ResponseDTO['body'] extends Record + ? ResponseDTO['body']['data'] + : void +>; -export type TRouteControllerAction = { +export type TRouteControllerAction< + RequestDTO extends CRequestDTO, + ResponseDTO extends TResponseDTO, +> = { path: string; method: ERouteControllerActionMethod; payload: ERouteControllerActionPayload[]; - Handler: TRouteControllerActionHandler; + Handler: TRouteControllerActionHandler; RequestDTO: ClassConstructor; ResponseDTO: ClassConstructor; }; export interface IRouteController { path: string; - actions: (IRouteController | TRouteControllerAction)[]; + actions: (IRouteController | TRouteControllerAction)[]; } function isRouteController( - object: IRouteController | TRouteControllerAction, + object: IRouteController | TRouteControllerAction, ): object is IRouteController { return object.hasOwnProperty('actions'); } -export function getControllerActionRouter( +export function getControllerActionRouter< + RequestDTO extends CRequestDTO, + ResponseDTO extends TResponseDTO, +>( app: TApplication, - action: TRouteControllerAction, + action: TRouteControllerAction, ): Router { const router = new Router(); router[action.method]( action.path, RequestValidator(action.RequestDTO, action.payload), - async (ctx: TRequestContext, next) => { + async (ctx: TRequestContext, next: Next) => { const data = await action.Handler(app)(ctx); - if (data) { - ctx.status = 200; - ctx.body = { data }; - } else { - ctx.status = 204; - ctx.body = undefined; - } + ctx.status = data ? 200 : 204; + ctx.body = data ? { data } : data; await next(); }, ResponseValidator(action.ResponseDTO), @@ -77,7 +109,7 @@ export function registerControllerRoutes( app, item, mainRouter, - posix.join(path, item.path), + item.path === '/' ? path : posix.join(path, item.path), ); } else { const router = getControllerActionRouter(app, item); diff --git a/src/monitor-server/services/consumer-time-series.service.ts b/src/monitor-server/services/consumer-time-series.service.ts index e43289fb..1372f68f 100644 --- a/src/monitor-server/services/consumer-time-series.service.ts +++ b/src/monitor-server/services/consumer-time-series.service.ts @@ -2,8 +2,8 @@ import { RedisClient } from '../../system/common/redis-client/redis-client'; import { ConsumerDeadLetteredTimeSeries } from '../../system/app/consumer/consumer-time-series/consumer-dead-lettered-time-series'; import { ConsumerAcknowledgedTimeSeries } from '../../system/app/consumer/consumer-time-series/consumer-acknowledged-time-series'; import { promisifyAll } from 'bluebird'; -import { GetConsumerAcknowledgedRequestDTO } from '../controllers/api/queues/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO'; -import { GetConsumerDeadLetteredRequestDTO } from '../controllers/api/queues/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO'; +import { GetConsumerAcknowledgedRequestDTO } from '../controllers/api/namespaces/queue/consumer/time-series/get-consumer-acknowledged/get-consumer-acknowledged.request.DTO'; +import { GetConsumerDeadLetteredRequestDTO } from '../controllers/api/namespaces/queue/consumer/time-series/get-consumer-dead-lettered/get-consumer-dead-lettered.request.DTO'; export class ConsumerTimeSeriesService { protected redisClient: RedisClient; diff --git a/src/monitor-server/services/messages.service.ts b/src/monitor-server/services/messages.service.ts index 61e38b9f..8987f0b0 100644 --- a/src/monitor-server/services/messages.service.ts +++ b/src/monitor-server/services/messages.service.ts @@ -1,25 +1,20 @@ import { promisifyAll } from 'bluebird'; -import { - TGetMessagesReply, - TGetPendingMessagesWithPriorityReply, - TGetScheduledMessagesReply, -} from '../../../types'; import { MessageManager } from '../../system/app/message-manager/message-manager'; import { GetScheduledMessagesRequestDTO } from '../controllers/api/main/scheduled-messages/get-scheduled-messages/get-scheduled-messages.request.DTO'; -import { GetPendingMessagesRequestDTO } from '../controllers/api/queues/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO'; -import { GetAcknowledgedMessagesRequestDTO } from '../controllers/api/queues/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO'; -import { GetDeadLetteredMessagesRequestDTO } from '../controllers/api/queues/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO'; -import { DeletePendingMessageRequestDTO } from '../controllers/api/queues/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO'; -import { DeletePendingMessageWithPriorityRequestDTO } from '../controllers/api/queues/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO'; -import { DeleteAcknowledgedMessageRequestDTO } from '../controllers/api/queues/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO'; -import { DeleteDeadLetteredMessageRequestDTO } from '../controllers/api/queues/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO'; +import { GetPendingMessagesRequestDTO } from '../controllers/api/namespaces/queue/pending-messages/get-pending-messages/get-pending-messages.request.DTO'; +import { GetAcknowledgedMessagesRequestDTO } from '../controllers/api/namespaces/queue/acknowledged-messages/get-acknowledged-messages/get-acknowledged-messages.request.DTO'; +import { GetDeadLetteredMessagesRequestDTO } from '../controllers/api/namespaces/queue/dead-lettered-messages/get-dead-lettered-messages/get-dead-lettered-messages.request.DTO'; +import { DeletePendingMessageRequestDTO } from '../controllers/api/namespaces/queue/pending-messages/delete-pending-message/delete-pending-message.request.DTO'; +import { DeletePendingMessageWithPriorityRequestDTO } from '../controllers/api/namespaces/queue/pending-messages-with-priority/delete-pending-message-with-priority/delete-pending-message-with-priority.request.DTO'; +import { DeleteAcknowledgedMessageRequestDTO } from '../controllers/api/namespaces/queue/acknowledged-messages/delete-acknowledged-message/delete-acknowledged-message.request.DTO'; +import { DeleteDeadLetteredMessageRequestDTO } from '../controllers/api/namespaces/queue/dead-lettered-messages/delete-dead-lettered-message/delete-dead-lettered-message.request.DTO'; import { DeleteScheduledMessageRequestDTO } from '../controllers/api/main/scheduled-messages/delete-scheduled-message/delete-scheduled-message-request.DTO'; -import { RequeueDeadLetteredMessageRequestDTO } from '../controllers/api/queues/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO'; -import { RequeueAcknowledgedMessageRequestDTO } from '../controllers/api/queues/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO'; -import { PurgeDeadLetteredMessagesRequestDTO } from '../controllers/api/queues/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO'; -import { PurgeAcknowledgedMessagesRequestDTO } from '../controllers/api/queues/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO'; -import { PurgePendingMessagesRequestDTO } from '../controllers/api/queues/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO'; -import { PurgePendingMessagesWithPriorityRequestDTO } from '../controllers/api/queues/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO'; +import { RequeueDeadLetteredMessageRequestDTO } from '../controllers/api/namespaces/queue/dead-lettered-messages/requeue-dead-lettered-message/requeue-dead-lettered-message.request.DTO'; +import { RequeueAcknowledgedMessageRequestDTO } from '../controllers/api/namespaces/queue/acknowledged-messages/requeue-acknowledged-message/requeue-acknowledged-message.request.DTO'; +import { PurgeDeadLetteredMessagesRequestDTO } from '../controllers/api/namespaces/queue/dead-lettered-messages/purge-dead-lettered-messages/purge-dead-lettered-messages.request.DTO'; +import { PurgeAcknowledgedMessagesRequestDTO } from '../controllers/api/namespaces/queue/acknowledged-messages/purge-acknowledged-messages/purge-acknowledged-messages.request.DTO'; +import { PurgePendingMessagesRequestDTO } from '../controllers/api/namespaces/queue/pending-messages/purge-pending-messages/purge-pending-messages.request.DTO'; +import { PurgePendingMessagesWithPriorityRequestDTO } from '../controllers/api/namespaces/queue/pending-messages-with-priority/purge-pending-messages-with-priority/purge-pending-messages-with-priority.request.DTO'; const messageManagerAsync = promisifyAll(MessageManager.prototype); @@ -30,18 +25,18 @@ export class MessagesService { this.messageManager = promisifyAll(messageManager); } - async getScheduledMessages( - args: GetScheduledMessagesRequestDTO, - ): Promise { + async getScheduledMessages(args: GetScheduledMessagesRequestDTO) { const { skip = 0, take = 1 } = args; - return this.messageManager.getScheduledMessagesAsync(skip, take); + const r = await this.messageManager.getScheduledMessagesAsync(skip, take); + return { + ...r, + items: r.items.map((i) => i.toJSON()), + }; } - async getPendingMessages( - args: GetPendingMessagesRequestDTO, - ): Promise { + async getPendingMessages(args: GetPendingMessagesRequestDTO) { const { ns, queueName, skip = 0, take = 1 } = args; - return this.messageManager.getPendingMessagesAsync( + const r = await this.messageManager.getPendingMessagesAsync( { name: queueName, ns, @@ -49,13 +44,15 @@ export class MessagesService { skip, take, ); + return { + ...r, + items: r.items.map((i) => ({ ...i, message: i.message.toJSON() })), + }; } - async getAcknowledgedMessages( - args: GetAcknowledgedMessagesRequestDTO, - ): Promise { + async getAcknowledgedMessages(args: GetAcknowledgedMessagesRequestDTO) { const { ns, queueName, skip = 0, take = 1 } = args; - return this.messageManager.getAcknowledgedMessagesAsync( + const r = await this.messageManager.getAcknowledgedMessagesAsync( { name: queueName, ns, @@ -63,13 +60,15 @@ export class MessagesService { skip, take, ); + return { + ...r, + items: r.items.map((i) => ({ ...i, message: i.message.toJSON() })), + }; } - async getPendingMessagesWithPriority( - args: GetPendingMessagesRequestDTO, - ): Promise { + async getPendingMessagesWithPriority(args: GetPendingMessagesRequestDTO) { const { ns, queueName, skip = 0, take = 1 } = args; - return this.messageManager.getPendingMessagesWithPriorityAsync( + const r = await this.messageManager.getPendingMessagesWithPriorityAsync( { name: queueName, ns, @@ -77,13 +76,15 @@ export class MessagesService { skip, take, ); + return { + ...r, + items: r.items.map((i) => i.toJSON()), + }; } - async getDeadLetteredMessages( - args: GetDeadLetteredMessagesRequestDTO, - ): Promise { + async getDeadLetteredMessages(args: GetDeadLetteredMessagesRequestDTO) { const { ns, queueName, skip = 0, take = 1 } = args; - return this.messageManager.getDeadLetteredMessagesAsync( + const r = await this.messageManager.getDeadLetteredMessagesAsync( { name: queueName, ns, @@ -91,6 +92,10 @@ export class MessagesService { skip, take, ); + return { + ...r, + items: r.items.map((i) => ({ ...i, message: i.message.toJSON() })), + }; } async deletePendingMessage( diff --git a/src/monitor-server/services/queues.service.ts b/src/monitor-server/services/queues.service.ts index b106362e..e6a020be 100644 --- a/src/monitor-server/services/queues.service.ts +++ b/src/monitor-server/services/queues.service.ts @@ -1,7 +1,9 @@ import { promisifyAll } from 'bluebird'; import { TQueueParams } from '../../../types'; -import { DeleteQueueRequestDTO } from '../controllers/api/queues/queue/delete-queue/delete-queue.request.DTO'; +import { DeleteQueueRequestDTO } from '../controllers/api/namespaces/queue/delete-queue/delete-queue.request.DTO'; import { QueueManager } from '../../queue-manager'; +import { GetNamespaceQueuesRequestDTO } from '../controllers/api/namespaces/get-namespace-queues/get-namespace-queues.request.DTO'; +import { DeleteNamespaceRequestDTO } from '../controllers/api/namespaces/delete-namespace/delete-namespace.request.DTO'; const queueManagerAsync = promisifyAll(QueueManager.prototype); @@ -12,13 +14,29 @@ export class QueuesService { this.queueManager = promisifyAll(queueManager); } + async getNamespaces(): Promise { + return this.queueManager.getNamespacesAsync(); + } + + async getNamespaceQueues( + args: GetNamespaceQueuesRequestDTO, + ): Promise { + const { ns } = args; + return this.queueManager.getNamespaceQueuesAsync(ns); + } + + async deleteNamespace(args: DeleteNamespaceRequestDTO): Promise { + const { ns } = args; + return this.queueManager.deleteNamespaceAsync(ns); + } + async getQueues(): Promise { - return this.queueManager.getMessageQueuesAsync(); + return this.queueManager.getQueuesAsync(); } async deleteQueue(args: DeleteQueueRequestDTO): Promise { const { ns, queueName } = args; - return this.queueManager.deleteMessageQueueAsync({ + return this.queueManager.deleteQueueAsync({ name: queueName, ns, }); diff --git a/src/monitor-server/types/common.ts b/src/monitor-server/types/common.ts index 9301a2c3..5850fd9a 100644 --- a/src/monitor-server/types/common.ts +++ b/src/monitor-server/types/common.ts @@ -2,12 +2,11 @@ import * as Koa from 'koa'; import { ICompatibleLogger, IConfig } from '../../../types'; import { RedisClient } from '../../system/common/redis-client/redis-client'; import { Services } from '../services'; -import { ParameterizedContext } from 'koa'; export interface IResponseBodyError { code: number; message: string; - details?: Record; + details?: Record; } export interface IResponseBody> { @@ -33,15 +32,6 @@ export interface IContext extends Koa.DefaultContext { export type TApplication = Koa; -export type TRequestContext< - DTO, - ResponseBody = Record, -> = ParameterizedContext< - IContextState, - IContext, - IResponseBody | undefined ->; - export type TMiddleware> = Koa.Middleware< IContextState, IContext & { params: Record }, diff --git a/src/monitor-server/utils/validate-dto.ts b/src/monitor-server/utils/validate-dto.ts index 3516494d..d15fe228 100644 --- a/src/monitor-server/utils/validate-dto.ts +++ b/src/monitor-server/utils/validate-dto.ts @@ -6,12 +6,10 @@ export async function validateDTO>( plain: Record, ): Promise { const object = plainToClass(dto, plain); - if (!Object.keys(object).length) { - return object; - } const errors = await validate(object, { stopAtFirstError: true, - forbidUnknownValues: true, + // See https://github.com/typestack/class-validator/issues/305#issuecomment-504778830 + // forbidUnknownValues: true, whitelist: true, forbidNonWhitelisted: true, }); diff --git a/src/monitor-server/workers/websocket-main-stream.worker.ts b/src/monitor-server/workers/websocket-main-stream.worker.ts index a1aed579..806c5996 100644 --- a/src/monitor-server/workers/websocket-main-stream.worker.ts +++ b/src/monitor-server/workers/websocket-main-stream.worker.ts @@ -131,7 +131,7 @@ export class WebsocketMainStreamWorker extends Worker { }; protected getQueues = (cb: ICallback): void => { - queueManager.getMessageQueues(this.redisClient, cb); + queueManager.getQueues(this.redisClient, cb); }; protected countScheduledMessages = (cb: ICallback): void => { diff --git a/src/monitor-server/workers/websocket-online-stream.worker.ts b/src/monitor-server/workers/websocket-online-stream.worker.ts index cce95627..9208a929 100644 --- a/src/monitor-server/workers/websocket-online-stream.worker.ts +++ b/src/monitor-server/workers/websocket-online-stream.worker.ts @@ -12,7 +12,7 @@ export class WebsocketOnlineStreamWorker extends Worker { waterfall( [ (cb: ICallback) => { - queueManager.getMessageQueues(this.redisClient, cb); + queueManager.getQueues(this.redisClient, cb); }, (queues: TQueueParams[], done: ICallback) => { each( diff --git a/src/system/app/message/message-metadata.ts b/src/system/app/message/message-metadata.ts index 43617190..68cf87d3 100644 --- a/src/system/app/message/message-metadata.ts +++ b/src/system/app/message/message-metadata.ts @@ -1,4 +1,5 @@ import { v4 as uuid } from 'uuid'; +import { TMessageMetadataJSON } from '../../../../types'; export class MessageMetadata { protected readonly uuid: string; @@ -159,4 +160,18 @@ export class MessageMetadata { } return 0; } + + toJSON(): TMessageMetadataJSON { + return { + uuid: this.uuid, + publishedAt: this.publishedAt, + scheduledAt: this.scheduledAt, + scheduledCronFired: this.scheduledCronFired, + attempts: this.attempts, + scheduledRepeatCount: this.scheduledRepeatCount, + expired: this.expired, + nextScheduledDelay: this.nextScheduledDelay, + nextRetryDelay: this.nextRetryDelay, + }; + } } diff --git a/src/system/app/message/message.ts b/src/system/app/message/message.ts index 28c6937d..02260498 100644 --- a/src/system/app/message/message.ts +++ b/src/system/app/message/message.ts @@ -1,5 +1,5 @@ import { parseExpression } from 'cron-parser'; -import { TQueueParams } from '../../../../types'; +import { TMessageJSON, TQueueParams } from '../../../../types'; import { ArgumentError } from '../../common/errors/argument.error'; import { queueManager } from '../queue-manager/queue-manager'; import { getConfiguration } from '../../common/configuration'; @@ -379,6 +379,24 @@ export class Message { return JSON.stringify(this); } + toJSON(): TMessageJSON { + return { + createdAt: this.createdAt, + queue: this.queue, + ttl: this.ttl, + retryThreshold: this.retryThreshold, + retryDelay: this.retryDelay, + consumeTimeout: this.consumeTimeout, + body: this.body, + priority: this.priority, + scheduledCron: this.scheduledCron, + scheduledDelay: this.scheduledDelay, + scheduledRepeatPeriod: this.scheduledRepeatPeriod, + scheduledRepeat: this.scheduledRepeat, + metadata: this.metadata ? this.metadata.toJSON() : null, + }; + } + hasRetryThresholdExceeded(): boolean { const metadata = this.getMetadata(); if (!metadata) { diff --git a/src/system/app/producer/producer.ts b/src/system/app/producer/producer.ts index 27590f4b..70a6d164 100644 --- a/src/system/app/producer/producer.ts +++ b/src/system/app/producer/producer.ts @@ -64,16 +64,21 @@ export class Producer extends Base { keyQueuePendingPriorityMessages, keyQueuePendingPriorityMessageIds, keyQueuePending, + keyNamespaces, + keyNsQueues, } = redisKeys.getQueueKeys(queue); redisClient.runScript( ELuaScriptName.PUBLISH_MESSAGE, [ + keyNamespaces, + keyNsQueues, keyQueues, keyQueuePendingPriorityMessages, keyQueuePendingPriorityMessageIds, keyQueuePending, ], [ + queue.ns, JSON.stringify(queue), message.getRequiredId(), JSON.stringify(message), diff --git a/src/system/app/queue-manager/common.ts b/src/system/app/queue-manager/common.ts index 29eb96db..30fc4f3f 100644 --- a/src/system/app/queue-manager/common.ts +++ b/src/system/app/queue-manager/common.ts @@ -23,7 +23,7 @@ export function validateMessageQueueDeletion( if (onlineArr.length) { cb( new GenericError( - `The queue is currently in use. Before deleting a queue, shutdown all its consumers. After shutting down all instances, wait a few seconds and try again.`, + `Before deleting a queue/namespace, make sure it is not used by a message handler. After shutting down all message handlers, wait a few seconds and try again.`, ), ); } else cb(); diff --git a/src/system/app/queue-manager/queue-manager-frontend.ts b/src/system/app/queue-manager/queue-manager-frontend.ts index f7f7f656..b82cd516 100644 --- a/src/system/app/queue-manager/queue-manager-frontend.ts +++ b/src/system/app/queue-manager/queue-manager-frontend.ts @@ -20,9 +20,9 @@ export class QueueManagerFrontend { this.logger = getNamespacedLogger('QueueManager'); } - deleteMessageQueue(queue: string | TQueueParams, cb: ICallback): void { + deleteQueue(queue: string | TQueueParams, cb: ICallback): void { const queueParams = queueManager.getQueueParams(queue); - queueManager.deleteMessageQueue(this.redisClient, queueParams, (err) => { + queueManager.deleteQueue(this.redisClient, queueParams, (err) => { if (err) cb(err); else { this.logger.info( @@ -35,6 +35,26 @@ export class QueueManagerFrontend { }); } + getNamespaceQueues(ns: string, cb: ICallback): void { + queueManager.getNamespaceQueues(this.redisClient, ns, cb); + } + + deleteNamespace(ns: string, cb: ICallback): void { + queueManager.deleteNamespace(this.redisClient, ns, (err) => { + if (err) cb(err); + else { + this.logger.info( + `The namespace (${ns}) alongside with its message queues has been successfully deleted.`, + ); + cb(); + } + }); + } + + getNamespaces(cb: ICallback): void { + queueManager.getNamespaces(this.redisClient, cb); + } + getQueueMetrics( queue: string | TQueueParams, cb: ICallback, @@ -43,8 +63,8 @@ export class QueueManagerFrontend { queueManager.getQueueMetrics(this.redisClient, queueParams, cb); } - getMessageQueues(cb: ICallback): void { - queueManager.getMessageQueues(this.redisClient, cb); + getQueues(cb: ICallback): void { + queueManager.getQueues(this.redisClient, cb); } quit(cb: ICallback): void { diff --git a/src/system/app/queue-manager/queue-manager.ts b/src/system/app/queue-manager/queue-manager.ts index f7576b10..b4ab5f32 100644 --- a/src/system/app/queue-manager/queue-manager.ts +++ b/src/system/app/queue-manager/queue-manager.ts @@ -10,7 +10,7 @@ import { EmptyCallbackReplyError } from '../../common/errors/empty-callback-repl import { GenericError } from '../../common/errors/generic.error'; import { ConsumerMessageHandler } from '../consumer/consumer-message-handler'; import { validateMessageQueueDeletion } from './common'; -import { waterfall } from '../../lib/async'; +import { eachOf, waterfall } from '../../lib/async'; export const queueManager = { queueExists( @@ -26,16 +26,11 @@ export const queueManager = { }); }, - /** - * When deleting a message queue, all queue's related queues and data will be deleted from the system. If the given - * queue has an online consumer, an error will be returned. To make sure that a consumer is online, - * an additional heartbeat check is performed, so that crushed consumers would not block queue deletion for a certain - * time. - */ - deleteMessageQueue( + deleteQueueTransaction( redisClient: RedisClient, queue: TQueueParams, - cb: ICallback, + multi: TRedisClientMulti | undefined, + cb: ICallback, ): void { const { keyQueuePending, @@ -56,6 +51,7 @@ export const queueManager = { keyQueueConsumers, keyProcessingQueues, keyQueues, + keyNsQueues, } = redisKeys.getQueueKeys(queue); const keys: string[] = [ keyQueuePending, @@ -101,15 +97,17 @@ export const queueManager = { (err?: Error | null, processingQueues?: string[] | null) => { if (err) redisClient.unwatch(() => cb(err)); else { - const multi = redisClient.multi(); - multi.srem(keyQueues, JSON.stringify(queue)); + const tx = multi || redisClient.multi(); + const str = JSON.stringify(queue); + tx.srem(keyQueues, str); + tx.srem(keyNsQueues, str); const pQueues = processingQueues ?? []; if (pQueues.length) { keys.push(...pQueues); - multi.srem(keyProcessingQueues, ...pQueues); + tx.srem(keyProcessingQueues, ...pQueues); } - multi.del(...keys); - redisClient.execMulti(multi, (err) => cb(err)); + tx.del(...keys); + cb(null, tx); } }, ); @@ -117,6 +115,56 @@ export const queueManager = { }); }, + deleteNamespace( + redisClient: RedisClient, + ns: string, + cb: ICallback, + ): void { + this.getNamespaceQueues(redisClient, ns, (err, reply) => { + if (err) cb(err); + else { + const queues = reply ?? []; + if (queues.length) { + const multi = redisClient.multi(); + eachOf( + queues, + (queue, _, done) => { + this.deleteQueueTransaction(redisClient, queue, multi, (err) => + done(err), + ); + }, + (err) => { + if (err) cb(err); + else { + const { keyNamespaces } = redisKeys.getMainKeys(); + multi.srem(keyNamespaces, ns); + redisClient.execMulti(multi, (err) => cb(err)); + } + }, + ); + } else cb(); + } + }); + }, + + /** + * When deleting a message queue, all queue's related queues and data will be deleted from the system. If the given + * queue has an online consumer, an error will be returned. To make sure that a consumer is online, + * an additional heartbeat check is performed, so that crushed consumers would not block queue deletion for a certain + * time. + */ + deleteQueue( + redisClient: RedisClient, + queue: TQueueParams, + cb: ICallback, + ): void { + this.deleteQueueTransaction(redisClient, queue, undefined, (err, multi) => { + if (err) cb(err); + else if (!multi) cb(new EmptyCallbackReplyError()); + else redisClient.execMulti(multi, (err) => cb(err)); + }); + }, + deleteProcessingQueue( redisClient: RedisClient, queue: TQueueParams, @@ -206,10 +254,32 @@ export const queueManager = { ); }, - getMessageQueues( + getNamespaces(redisClient: RedisClient, cb: ICallback): void { + const { keyNamespaces } = redisKeys.getMainKeys(); + redisClient.smembers(keyNamespaces, (err, reply) => { + if (err) cb(err); + else if (!reply) cb(new EmptyCallbackReplyError()); + else cb(null, reply ?? []); + }); + }, + + getNamespaceQueues( redisClient: RedisClient, + namespace: string, cb: ICallback, ): void { + const { keyNsQueues } = redisKeys.getNsKeys(namespace); + redisClient.smembers(keyNsQueues, (err, reply) => { + if (err) cb(err); + else if (!reply) cb(new EmptyCallbackReplyError()); + else { + const messageQueues: TQueueParams[] = reply.map((i) => JSON.parse(i)); + cb(null, messageQueues); + } + }); + }, + + getQueues(redisClient: RedisClient, cb: ICallback): void { const { keyQueues } = redisKeys.getMainKeys(); redisClient.smembers(keyQueues, (err, reply) => { if (err) cb(err); @@ -244,9 +314,12 @@ export const queueManager = { }, setUpMessageQueue(multi: TRedisClientMulti, queue: TQueueParams): void { - const { keyQueues } = redisKeys.getQueueKeys(queue); + const { keyQueues, keyNsQueues, keyNamespaces } = + redisKeys.getQueueKeys(queue); const str = JSON.stringify(queue); multi.sadd(keyQueues, str); + multi.sadd(keyNsQueues, str); + multi.sadd(keyNamespaces, queue.ns); }, getQueueParams(queue: string | TQueueParams): TQueueParams { diff --git a/src/system/common/redis-client/lua/publish-message.lua b/src/system/common/redis-client/lua/publish-message.lua index fccda239..07af982f 100644 --- a/src/system/common/redis-client/lua/publish-message.lua +++ b/src/system/common/redis-client/lua/publish-message.lua @@ -1,18 +1,27 @@ ---- KEYS[1] keyQueues (set) ---- KEYS[2] keyQueuePendingWithPriority (hash) ---- KEYS[3] keyQueuePriority (sorted set) ---- KEYS[4] keyQueuePending (list) ---- ARGV[1] queue ---- ARGV[2] message id ---- ARGV[3] message ---- ARGV[4] messagePriority +--- KEYS[1] keyNamespaces +--- KEYS[2] keyNsQueues +--- KEYS[3] keyQueues (set) +--- KEYS[4] keyQueuePendingWithPriority (hash) +--- KEYS[5] keyQueuePriority (sorted set) +--- KEYS[6] keyQueuePending (list) +--- ARGV[1] namespace +--- ARGV[2] queue +--- ARGV[3] message id +--- ARGV[4] message +--- ARGV[5] messagePriority if redis.call("SISMEMBER", KEYS[1], ARGV[1]) == 0 then redis.call("SADD", KEYS[1], ARGV[1]) end -if ARGV[4] == nil or ARGV[4] == '' then - redis.call("RPUSH", KEYS[4], ARGV[3]) +if redis.call("SISMEMBER", KEYS[2], ARGV[2]) == 0 then + redis.call("SADD", KEYS[2], ARGV[2]) +end +if redis.call("SISMEMBER", KEYS[3], ARGV[2]) == 0 then + redis.call("SADD", KEYS[3], ARGV[2]) +end +if ARGV[5] == nil or ARGV[5] == '' then + redis.call("RPUSH", KEYS[6], ARGV[4]) else - redis.call("HSET", KEYS[2], ARGV[2], ARGV[3]) - redis.call("ZADD", KEYS[3], ARGV[4], ARGV[2]) + redis.call("HSET", KEYS[4], ARGV[3], ARGV[4]) + redis.call("ZADD", KEYS[5], ARGV[5], ARGV[3]) end return 1 \ No newline at end of file diff --git a/src/system/common/redis-keys/redis-keys.ts b/src/system/common/redis-keys/redis-keys.ts index e51610fa..a6b06a58 100644 --- a/src/system/common/redis-keys/redis-keys.ts +++ b/src/system/common/redis-keys/redis-keys.ts @@ -5,7 +5,7 @@ import { TQueueParams } from '../../../../types'; const keySegmentSeparator = '.'; // Key prefix -const nsPrefix = 'redis-smq-v600rc10'; +const nsPrefix = 'redis-smq-v600rc12'; // Namespaces const globalNamespace = 'global'; @@ -56,6 +56,8 @@ enum ERedisKey { KEY_QUEUES, KEY_PROCESSING_QUEUES, KEY_CONSUMER_QUEUES, + KEY_NS_QUEUES, + KEY_NAMESPACES, } export const redisKeys = { @@ -65,8 +67,20 @@ export const redisKeys = { }; }, - getQueueKeys(queueParams: TQueueParams) { + getNsKeys(ns: string) { const mainKeys = this.getMainKeys(); + const keys = { + keyNsQueues: ERedisKey.KEY_NS_QUEUES, + }; + return { + ...mainKeys, + ...keys, + ...this.makeNamespacedKeys(keys, ns), + }; + }, + + getQueueKeys(queueParams: TQueueParams) { + const nsKeys = this.getNsKeys(queueParams.ns); const queueKeys = { keyQueuePending: ERedisKey.KEY_QUEUE_PENDING, keyQueueDL: ERedisKey.KEY_QUEUE_DL, @@ -90,7 +104,7 @@ export const redisKeys = { keyQueueConsumers: ERedisKey.KEY_QUEUE_CONSUMERS, }; return { - ...mainKeys, + ...nsKeys, ...queueKeys, ...this.makeNamespacedKeys(queueKeys, queueParams.ns, queueParams.name), }; @@ -154,6 +168,7 @@ export const redisKeys = { ERedisKey.KEY_LOCK_RATE_GLOBAL_ACKNOWLEDGED, keyLockRateGlobalDeadLettered: ERedisKey.KEY_LOCK_RATE_GLOBAL_DEAD_LETTERED, + keyNamespaces: ERedisKey.KEY_NAMESPACES, }; return this.makeNamespacedKeys(mainKeys, globalNamespace); }, diff --git a/tests/http-api/test00001.test.ts b/tests/http-api/test00001.test.ts index 1a12e16b..96ebe31e 100644 --- a/tests/http-api/test00001.test.ts +++ b/tests/http-api/test00001.test.ts @@ -28,7 +28,7 @@ test('Fetching and deleting scheduled messages using the HTTP API: Case 1', asyn expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); - expect(response1.body.data?.items[0].metadata.uuid).toBe( + expect(response1.body.data?.items[0].metadata?.uuid).toBe( msg1.getRequiredId(), ); diff --git a/tests/http-api/test00002.test.ts b/tests/http-api/test00002.test.ts index 72638660..379220d7 100644 --- a/tests/http-api/test00002.test.ts +++ b/tests/http-api/test00002.test.ts @@ -30,10 +30,10 @@ test('Fetching and deleting scheduled messages using the HTTP API: Case 2', asyn expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(4); expect(response1.body.data?.items.length).toBe(2); - expect(response1.body.data?.items[0].metadata.uuid).toBe( + expect(response1.body.data?.items[0].metadata?.uuid).toBe( messages[0].getRequiredId(), ); - expect(response1.body.data?.items[1].metadata.uuid).toBe( + expect(response1.body.data?.items[1].metadata?.uuid).toBe( messages[1].getRequiredId(), ); @@ -43,10 +43,10 @@ test('Fetching and deleting scheduled messages using the HTTP API: Case 2', asyn expect(response2.body.data).toBeDefined(); expect(response2.body.data?.total).toBe(4); expect(response2.body.data?.items.length).toBe(2); - expect(response2.body.data?.items[0].metadata.uuid).toBe( + expect(response2.body.data?.items[0].metadata?.uuid).toBe( messages[2].getRequiredId(), ); - expect(response2.body.data?.items[1].metadata.uuid).toBe( + expect(response2.body.data?.items[1].metadata?.uuid).toBe( messages[3].getRequiredId(), ); diff --git a/tests/http-api/test00006.test.ts b/tests/http-api/test00006.test.ts index e37b6aca..c45fa85a 100644 --- a/tests/http-api/test00006.test.ts +++ b/tests/http-api/test00006.test.ts @@ -4,16 +4,54 @@ import { startMonitorServer, } from '../common'; import * as supertest from 'supertest'; +import { TQueueParams } from '../../types'; -test('Fetching queues', async () => { +test('Fetching queues, namespaces, queue namespaces, deleting namespace', async () => { await startMonitorServer(); const { message } = await produceMessage(); const request = supertest('http://127.0.0.1:3000'); - const response1: ISuperTestResponse = await request.get( + + const r1: ISuperTestResponse = await request.get( + '/api/queues', + ); + expect(r1.statusCode).toBe(200); + expect(r1.body.data).toBeDefined(); + expect(r1.body.data?.length).toBe(1); + expect((r1.body.data ?? [])[0]).toEqual(message.getRequiredQueue()); + + const r2: ISuperTestResponse = await request.get('/api/ns'); + expect(r2.statusCode).toBe(200); + expect(r2.body.data).toBeDefined(); + expect(r2.body.data?.length).toBe(1); + expect((r2.body.data ?? [])[0]).toEqual(message.getRequiredQueue().ns); + + const r3: ISuperTestResponse = await request.get( + `/api/ns/${message.getRequiredQueue().ns}/queues`, + ); + expect(r3.statusCode).toBe(200); + expect(r3.body.data).toBeDefined(); + expect(r3.body.data?.length).toBe(1); + expect((r3.body.data ?? [])[0]).toEqual(message.getRequiredQueue()); + + const r4: ISuperTestResponse = await request.delete( + `/api/ns/${message.getRequiredQueue().ns}`, + ); + expect(r4.status).toEqual(204); + expect(r4.body.data).toBeUndefined(); + + const r5: ISuperTestResponse = await request.get( '/api/queues', ); - expect(response1.statusCode).toBe(200); - expect(response1.body.data).toBeDefined(); - expect(response1.body.data?.length).toBe(1); - expect((response1.body.data ?? [])[0]).toEqual(message.getQueue()); + expect(r5.statusCode).toBe(200); + expect(r5.body.data?.length).toBe(0); + + const r6: ISuperTestResponse = await request.get('/api/ns'); + expect(r6.statusCode).toBe(200); + expect(r6.body.data?.length).toBe(0); + + const r7: ISuperTestResponse = await request.get( + `/api/ns/${message.getRequiredQueue().ns}/queues`, + ); + expect(r7.statusCode).toBe(200); + expect(r7.body.data?.length).toBe(0); }); diff --git a/tests/http-api/test00007.test.ts b/tests/http-api/test00007.test.ts index 11625093..788e7532 100644 --- a/tests/http-api/test00007.test.ts +++ b/tests/http-api/test00007.test.ts @@ -12,14 +12,14 @@ test('Fetching pending messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); }); diff --git a/tests/http-api/test00008.test.ts b/tests/http-api/test00008.test.ts index 1b61a7c3..9a5266a7 100644 --- a/tests/http-api/test00008.test.ts +++ b/tests/http-api/test00008.test.ts @@ -13,7 +13,7 @@ test('Fetching acknowledged messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/acknowledged-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/acknowledged-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); @@ -21,7 +21,7 @@ test('Fetching acknowledged messages', async () => { expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); }); diff --git a/tests/http-api/test00009.test.ts b/tests/http-api/test00009.test.ts index e15bf263..e309afb1 100644 --- a/tests/http-api/test00009.test.ts +++ b/tests/http-api/test00009.test.ts @@ -12,14 +12,14 @@ test('Fetching dead-lettered messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/dead-lettered-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/dead-lettered-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); }); diff --git a/tests/http-api/test00010.test.ts b/tests/http-api/test00010.test.ts index 740ab707..40d9eb4a 100644 --- a/tests/http-api/test00010.test.ts +++ b/tests/http-api/test00010.test.ts @@ -4,7 +4,7 @@ import { startMonitorServer, } from '../common'; import * as supertest from 'supertest'; -import { GetPendingMessagesWithPriorityResponseBodyDataDTO } from '../../src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO'; +import { GetPendingMessagesWithPriorityResponseBodyDataDTO } from '../../src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO'; test('Fetching pending messages with priority', async () => { await startMonitorServer(); @@ -13,14 +13,14 @@ test('Fetching pending messages with priority', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages-with-priority?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages-with-priority?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); - expect(response1.body.data?.items[0].metadata.uuid).toBe( + expect(response1.body.data?.items[0].metadata?.uuid).toBe( message.getRequiredId(), ); }); diff --git a/tests/http-api/test00011.test.ts b/tests/http-api/test00011.test.ts index c7c5f39c..b382e070 100644 --- a/tests/http-api/test00011.test.ts +++ b/tests/http-api/test00011.test.ts @@ -12,8 +12,8 @@ test('Delete a pending message', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/pending-messages/${message.getRequiredId()}?sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00012.test.ts b/tests/http-api/test00012.test.ts index ddd767bf..71741da3 100644 --- a/tests/http-api/test00012.test.ts +++ b/tests/http-api/test00012.test.ts @@ -12,8 +12,8 @@ test('Delete an acknowledged message', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/acknowledged-messages/${message.getRequiredId()}?sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00013.test.ts b/tests/http-api/test00013.test.ts index 0090f86c..e4d37c82 100644 --- a/tests/http-api/test00013.test.ts +++ b/tests/http-api/test00013.test.ts @@ -12,8 +12,8 @@ test('Delete a dead-lettered messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/dead-lettered-messages/${message.getRequiredId()}?sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00014.test.ts b/tests/http-api/test00014.test.ts index 03489eed..ef6c0367 100644 --- a/tests/http-api/test00014.test.ts +++ b/tests/http-api/test00014.test.ts @@ -12,8 +12,8 @@ test('Deleting a pending messages with priority', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/pending-messages-with-priority/${message.getRequiredId()}`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00015.test.ts b/tests/http-api/test00015.test.ts index 4a6e40b4..7d8aaef5 100644 --- a/tests/http-api/test00015.test.ts +++ b/tests/http-api/test00015.test.ts @@ -12,8 +12,8 @@ test('Re-queuing an acknowledged message', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.post( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/acknowledged-messages/${message.getRequiredId()}/requeue?sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00016.test.ts b/tests/http-api/test00016.test.ts index 5b481fe8..df6b4b54 100644 --- a/tests/http-api/test00016.test.ts +++ b/tests/http-api/test00016.test.ts @@ -12,8 +12,8 @@ test('Requeuing a dead-lettered messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.post( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/dead-lettered-messages/${message.getRequiredId()}/requeue?sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00017.test.ts b/tests/http-api/test00017.test.ts index 5fad545b..9f18cf6b 100644 --- a/tests/http-api/test00017.test.ts +++ b/tests/http-api/test00017.test.ts @@ -12,8 +12,8 @@ test('Requeuing with priority an acknowledged message', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.post( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/acknowledged-messages/${message.getRequiredId()}/requeue?priority=4&sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00018.test.ts b/tests/http-api/test00018.test.ts index dd68c9a1..aeb36b98 100644 --- a/tests/http-api/test00018.test.ts +++ b/tests/http-api/test00018.test.ts @@ -12,8 +12,8 @@ test('Requeuing with priority a dead-lettered messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.post( - `/api/queues/${queue.name}/ns/${ - queue.ns + `/api/ns/${queue.ns}/queues/${ + queue.name }/dead-lettered-messages/${message.getRequiredId()}/requeue?priority=3&sequenceId=0`, ); expect(response1.statusCode).toBe(204); diff --git a/tests/http-api/test00019.test.ts b/tests/http-api/test00019.test.ts index 36b9e4b4..a36c3ad6 100644 --- a/tests/http-api/test00019.test.ts +++ b/tests/http-api/test00019.test.ts @@ -12,25 +12,25 @@ test('Purge dead-lettered messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/dead-lettered-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/dead-lettered-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); const response2: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${queue.ns}/dead-lettered-messages`, + `/api/ns/${queue.ns}/queues/${queue.name}/dead-lettered-messages`, ); expect(response2.statusCode).toBe(204); expect(response2.body).toEqual({}); const response3: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/dead-lettered-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/dead-lettered-messages?skip=0&take=99`, ); expect(response3.statusCode).toBe(200); expect(response3.body.data).toBeDefined(); diff --git a/tests/http-api/test00020.test.ts b/tests/http-api/test00020.test.ts index 91214502..2649e2f0 100644 --- a/tests/http-api/test00020.test.ts +++ b/tests/http-api/test00020.test.ts @@ -12,25 +12,25 @@ test('Purge acknowledged messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/acknowledged-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/acknowledged-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); const response2: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${queue.ns}/acknowledged-messages`, + `/api/ns/${queue.ns}/queues/${queue.name}/acknowledged-messages`, ); expect(response2.statusCode).toBe(204); expect(response2.body).toEqual({}); const response3: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/acknowledged-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/acknowledged-messages?skip=0&take=99`, ); expect(response3.statusCode).toBe(200); expect(response3.body.data).toBeDefined(); diff --git a/tests/http-api/test00021.test.ts b/tests/http-api/test00021.test.ts index dc4b2441..ac54fcf3 100644 --- a/tests/http-api/test00021.test.ts +++ b/tests/http-api/test00021.test.ts @@ -12,25 +12,25 @@ test('Purge pending messages', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); expect(response1.body.data?.items[0].sequenceId).toBe(0); - expect(response1.body.data?.items[0].message.metadata.uuid).toBe( + expect(response1.body.data?.items[0].message.metadata?.uuid).toBe( message.getRequiredId(), ); const response2: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages`, ); expect(response2.statusCode).toBe(204); expect(response2.body).toEqual({}); const response3: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages?skip=0&take=99`, ); expect(response3.statusCode).toBe(200); expect(response3.body.data).toBeDefined(); diff --git a/tests/http-api/test00022.test.ts b/tests/http-api/test00022.test.ts index e1d54d7a..962d820c 100644 --- a/tests/http-api/test00022.test.ts +++ b/tests/http-api/test00022.test.ts @@ -4,7 +4,7 @@ import { startMonitorServer, } from '../common'; import * as supertest from 'supertest'; -import { GetPendingMessagesWithPriorityResponseBodyDataDTO } from '../../src/monitor-server/controllers/api/queues/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO'; +import { GetPendingMessagesWithPriorityResponseBodyDataDTO } from '../../src/monitor-server/controllers/api/namespaces/queue/pending-messages-with-priority/get-pending-messages-with-priority/get-pending-messages-with-priority.response.DTO'; test('Purge pending messages with priority', async () => { await startMonitorServer(); @@ -12,23 +12,23 @@ test('Purge pending messages with priority', async () => { const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages-with-priority?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages-with-priority?skip=0&take=99`, ); expect(response1.statusCode).toBe(200); expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); - expect(response1.body.data?.items[0].metadata.uuid).toBe( + expect(response1.body.data?.items[0].metadata?.uuid).toBe( message.getRequiredId(), ); const response2: ISuperTestResponse = await request.delete( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages-with-priority`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages-with-priority`, ); expect(response2.statusCode).toBe(204); expect(response2.body).toEqual({}); const response3: ISuperTestResponse = await request.get( - `/api/queues/${queue.name}/ns/${queue.ns}/pending-messages-with-priority?skip=0&take=99`, + `/api/ns/${queue.ns}/queues/${queue.name}/pending-messages-with-priority?skip=0&take=99`, ); expect(response3.statusCode).toBe(200); expect(response3.body.data).toBeDefined(); diff --git a/tests/http-api/test00023.test.ts b/tests/http-api/test00023.test.ts index fa9bad35..fa4e9ecb 100644 --- a/tests/http-api/test00023.test.ts +++ b/tests/http-api/test00023.test.ts @@ -16,7 +16,7 @@ test('Purge scheduled messages', async () => { expect(response1.body.data).toBeDefined(); expect(response1.body.data?.total).toBe(1); expect(response1.body.data?.items.length).toBe(1); - expect(response1.body.data?.items[0].metadata.uuid).toBe( + expect(response1.body.data?.items[0].metadata?.uuid).toBe( message.getRequiredId(), ); const response2: ISuperTestResponse = await request.delete( diff --git a/tests/http-api/test00024.test.ts b/tests/http-api/test00024.test.ts index 1c106fa5..997bb33d 100644 --- a/tests/http-api/test00024.test.ts +++ b/tests/http-api/test00024.test.ts @@ -2,6 +2,6 @@ import { validateTimeSeriesFrom } from '../common'; test('Queue acknowledged time series', async () => { await validateTimeSeriesFrom( - `/api/queues/test_queue/ns/testing/time-series/acknowledged`, + `/api/ns/testing/queues/test_queue/time-series/acknowledged`, ); }); diff --git a/tests/http-api/test00025.test.ts b/tests/http-api/test00025.test.ts index 6f2c05c2..907c8a4c 100644 --- a/tests/http-api/test00025.test.ts +++ b/tests/http-api/test00025.test.ts @@ -2,6 +2,6 @@ import { validateTimeSeriesFrom } from '../common'; test('Queue dead-lettered time series', async () => { await validateTimeSeriesFrom( - `/api/queues/test_queue/ns/testing/time-series/dead-lettered`, + `/api/ns/testing/queues/test_queue/time-series/dead-lettered`, ); }); diff --git a/tests/http-api/test00026.test.ts b/tests/http-api/test00026.test.ts index 7696f87d..ecd7f2e1 100644 --- a/tests/http-api/test00026.test.ts +++ b/tests/http-api/test00026.test.ts @@ -2,6 +2,6 @@ import { validateTimeSeriesFrom } from '../common'; test('Queue published time series', async () => { await validateTimeSeriesFrom( - `/api/queues/test_queue/ns/testing/time-series/published`, + `/api/ns/testing/queues/test_queue/time-series/published`, ); }); diff --git a/tests/http-api/test00027.test.ts b/tests/http-api/test00027.test.ts index f7b74a31..4732d45c 100644 --- a/tests/http-api/test00027.test.ts +++ b/tests/http-api/test00027.test.ts @@ -11,8 +11,8 @@ test('Consumer acknowledged time series', async () => { await consumer.runAsync(); await untilConsumerIdle(consumer); await validateTimeSeriesFrom( - `/api/queues/${defaultQueue.name}/ns/${ - defaultQueue.ns + `/api/ns/${defaultQueue.ns}/queues/${ + defaultQueue.name }/consumers/${consumer.getId()}/time-series/acknowledged`, ); }); diff --git a/tests/http-api/test00028.test.ts b/tests/http-api/test00028.test.ts index 2a8a5d59..1c33e63c 100644 --- a/tests/http-api/test00028.test.ts +++ b/tests/http-api/test00028.test.ts @@ -11,8 +11,8 @@ test('Consumer dead-lettered time series', async () => { await consumer.runAsync(); await untilConsumerIdle(consumer); await validateTimeSeriesFrom( - `/api/queues/${defaultQueue.name}/ns/${ - defaultQueue.ns + `/api/ns/${defaultQueue.ns}/queues/${ + defaultQueue.name }/consumers/${consumer.getId()}/time-series/dead-lettered`, ); }); diff --git a/tests/http-api/test00034.test.ts b/tests/http-api/test00034.test.ts index 712670be..c2dd6ce8 100644 --- a/tests/http-api/test00034.test.ts +++ b/tests/http-api/test00034.test.ts @@ -11,7 +11,7 @@ test('Delete a message queue', async () => { const { queue } = await produceMessage(); const request = supertest('http://127.0.0.1:3000'); const response1: ISuperTestResponse = - await request.delete(`/api/queues/${queue.name}/ns/${queue.ns}`); + await request.delete(`/api/ns/${queue.ns}/queues/${queue.name}`); expect(response1.statusCode).toBe(204); expect(response1.body).toEqual({}); }); diff --git a/tests/purging-queues/test00006.test.ts b/tests/purging-queues/test00006.test.ts index 3d151204..e77aaea8 100644 --- a/tests/purging-queues/test00006.test.ts +++ b/tests/purging-queues/test00006.test.ts @@ -13,18 +13,18 @@ test('Deleting a message queue with all of its data', async () => { expect(m1.acknowledged).toBe(1); await expect(async () => { - await queueManager.deleteMessageQueueAsync(queue); + await queueManager.deleteQueueAsync(queue); }).rejects.toThrow( - 'The queue is currently in use. Before deleting a queue, shutdown all its consumers.', + 'Before deleting a queue/namespace, make sure it is not used by a message handler', ); await consumer.shutdownAsync(); - await queueManager.deleteMessageQueueAsync(queue); + await queueManager.deleteQueueAsync(queue); const m2 = await queueManager.getQueueMetricsAsync(queue); expect(m2.acknowledged).toBe(0); await expect(async () => { - await queueManager.deleteMessageQueueAsync(queue); + await queueManager.deleteQueueAsync(queue); }).rejects.toThrow('Queue does not exist'); }); diff --git a/tests/purging-queues/test00007.test.ts b/tests/purging-queues/test00007.test.ts index e68bfd52..8b8aa2a2 100644 --- a/tests/purging-queues/test00007.test.ts +++ b/tests/purging-queues/test00007.test.ts @@ -21,9 +21,9 @@ test('Concurrently deleting a message queue and starting a consumer', async () = pending: 1, }); - // queueManagerInstance.deleteMessageQueue() calls queueManager.getQueueProcessingQueues() after validation is passed. + // queueManagerInstance.deleteQueue() calls queueManager.getQueueProcessingQueues() after validation is passed. // Within getQueueProcessingQueues() method, we can take more time than usual to return a response, to allow the - // consumer to start up. queueManagerInstance.deleteMessageQueue() should detect that a consumer has been started and + // consumer to start up. queueManagerInstance.deleteQueue() should detect that a consumer has been started and // the operation should be cancelled. const originalMethod = queueManager.getQueueProcessingQueues; queueManager.getQueueProcessingQueues = ( @@ -40,7 +40,7 @@ test('Concurrently deleting a message queue and starting a consumer', async () = await expect(async () => { await Promise.all([ - queueManagerInstance.deleteMessageQueueAsync(queue), + queueManagerInstance.deleteQueueAsync(queue), consumer.runAsync(), ]); }).rejects.toThrow('Redis transaction has been abandoned. Try again.'); diff --git a/tests/purging-queues/test00008.test.ts b/tests/purging-queues/test00008.test.ts new file mode 100644 index 00000000..8c64f246 --- /dev/null +++ b/tests/purging-queues/test00008.test.ts @@ -0,0 +1,54 @@ +import { + getQueueManagerFrontend, + produceAndAcknowledgeMessage, +} from '../common'; +import { promisifyAll } from 'bluebird'; + +test('Combined: Fetching namespaces, deleting a namespace with its message queues', async () => { + const ns = 'ns1'; + const { consumer: c1, queue: q1 } = await produceAndAcknowledgeMessage({ + ns, + name: 'queue_a', + }); + + const { consumer: c2, queue: q2 } = await produceAndAcknowledgeMessage({ + ns, + name: 'queue_b', + }); + + const queueManager = promisifyAll(await getQueueManagerFrontend()); + + const m0 = await queueManager.getNamespacesAsync(); + expect(m0).toEqual([ns]); + + const m1 = await queueManager.getQueueMetricsAsync(q1); + expect(m1.acknowledged).toBe(1); + + const m2 = await queueManager.getQueueMetricsAsync(q2); + expect(m2.acknowledged).toBe(1); + + await expect(async () => { + await queueManager.deleteNamespaceAsync(ns); + }).rejects.toThrow( + 'Before deleting a queue/namespace, make sure it is not used by a message handler', + ); + + await c1.shutdownAsync(); + await expect(async () => { + await queueManager.deleteNamespaceAsync(ns); + }).rejects.toThrow( + 'Before deleting a queue/namespace, make sure it is not used by a message handler', + ); + + await c2.shutdownAsync(); + await queueManager.deleteNamespaceAsync(ns); + + const m3 = await queueManager.getQueueMetricsAsync(q1); + expect(m3.acknowledged).toBe(0); + + const m4 = await queueManager.getQueueMetricsAsync(q2); + expect(m4.acknowledged).toBe(0); + + const m5 = await queueManager.getNamespacesAsync(); + expect(m5).toEqual([]); +}); diff --git a/tests/scheduling-messages/test00008.test.ts b/tests/scheduling-messages/test00008.test.ts index b73e14bd..be959d6b 100644 --- a/tests/scheduling-messages/test00008.test.ts +++ b/tests/scheduling-messages/test00008.test.ts @@ -23,7 +23,7 @@ test("Make sure scheduled messages aren't published if destination queue is dele expect(s1.total).toBe(1); const queueManager = promisifyAll(await getQueueManagerFrontend()); - await queueManager.deleteMessageQueueAsync('some_queue'); + await queueManager.deleteQueueAsync('some_queue'); await startScheduleWorker(); await delay(20000); diff --git a/types/index.ts b/types/index.ts index 25f590d5..80c73327 100644 --- a/types/index.ts +++ b/types/index.ts @@ -314,3 +314,31 @@ export interface ICompatibleLogger { error(message: unknown, ...params: unknown[]): void; debug(message: unknown, ...params: unknown[]): void; } + +export type TMessageJSON = { + createdAt: number; + queue: TQueueParams | null; + ttl: number; + retryThreshold: number; + retryDelay: number; + consumeTimeout: number; + body: unknown; + priority: number | null; + scheduledCron: string | null; + scheduledDelay: number | null; + scheduledRepeatPeriod: number | null; + scheduledRepeat: number; + metadata: TMessageMetadataJSON | null; +}; + +export type TMessageMetadataJSON = { + uuid: string; + publishedAt: number | null; + scheduledAt: number | null; + scheduledCronFired: boolean; + attempts: number; + scheduledRepeatCount: number; + expired: boolean; + nextScheduledDelay: number; + nextRetryDelay: number; +};