-
Notifications
You must be signed in to change notification settings - Fork 0
feat(queue-storage): implement @cellix/service-queue-storage and @ocom/service-queue-storage (#263) #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nnoce14
wants to merge
3
commits into
issue251/blob-storage-service
Choose a base branch
from
issue263/queue-storage-service
base: issue251/blob-storage-service
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(queue-storage): implement @cellix/service-queue-storage and @ocom/service-queue-storage (#263) #264
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { BlobQueueMessageLogger, ServiceQueueStorage } from '@cellix/service-queue-storage'; | ||
| import type { ServiceBlobStorage } from '@ocom/service-blob-storage'; | ||
| import { allQueueNames } from '@ocom/service-queue-storage'; | ||
|
|
||
| const { AZURE_QUEUE_ACCOUNT_NAME: accountName, AZURE_QUEUE_CONNECTION_STRING: connectionString, QUEUE_LOG_CONTAINER: logContainer } = process.env; | ||
|
|
||
| if (!accountName) { | ||
| throw new Error('Missing AZURE_QUEUE_ACCOUNT_NAME environment variable. Required for queue operations with managed identity authentication.'); | ||
| } | ||
|
|
||
| if (!connectionString) { | ||
| // Some applications may not require connection string; however for client operations we expect it | ||
| throw new Error('Missing AZURE_QUEUE_CONNECTION_STRING environment variable. Required for connection-string-based queue operations.'); | ||
| } | ||
|
|
||
| export function createQueueServices(clientOperationsService: ServiceBlobStorage, isProd: boolean) { | ||
| const queueLoggingEnabled = !!logContainer; | ||
| let queueLogger: BlobQueueMessageLogger | undefined; | ||
| if (queueLoggingEnabled) { | ||
| // BlobQueueMessageLogger expects an object with uploadText({ containerName, blobName, text }) | ||
| const blobLike = clientOperationsService as unknown as { uploadText(request: { containerName: string; blobName: string; text: string }): Promise<unknown> }; | ||
| queueLogger = new BlobQueueMessageLogger(blobLike, logContainer as string); | ||
| } | ||
|
|
||
| // Build the list of queues to auto-provision from the application's queue registry when available | ||
| // This keeps configuration centralized in the OCOM queue registry | ||
| const provisionQueues = Array.isArray(allQueueNames) && allQueueNames.length > 0 ? allQueueNames : ['email-notifications', 'audit-events', 'import-requests']; | ||
| const qAccount = accountName as string | undefined; | ||
| const qConnection = connectionString as string | undefined; | ||
|
|
||
| const queueService = isProd | ||
| ? new ServiceQueueStorage({ accountName: qAccount as string, logging: { enabled: queueLoggingEnabled, container: logContainer as string }, logger: queueLogger, provisionQueues }) | ||
| : new ServiceQueueStorage({ connectionString: qConnection as string, localDev: !isProd, logging: { enabled: queueLoggingEnabled, container: logContainer as string }, logger: queueLogger, provisionQueues }); | ||
|
|
||
| return { queueService, queueLogger, provisionQueues }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /dist | ||
| /node_modules | ||
|
|
||
| tsconfig.tsbuidinfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # @cellix/service-queue-storage | ||
|
|
||
| Type-safe Azure Queue Storage framework service for Cellix. | ||
|
|
||
| Provides: ServiceQueueStorage, message contracts, blob-backed logging, and poison-queue helpers. | ||
|
|
||
| See manifest.md for public surface. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Public surface | ||
|
|
||
| - ServiceQueueStorage | ||
| - registerQueues | ||
| - createQueueProducer | ||
| - createQueueConsumer | ||
| - defineQueueMessage | ||
| - BlobQueueMessageLogger | ||
| - moveMessageToPoison / handleMessageWithRetries / PoisonQueueOptions | ||
| - types: QueueMessage, QueueStorageConfig, QueueMessageContract, OutboundQueueSchema, InboundQueueSchema, QueueProducerContext, QueueConsumerContext |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "name": "@cellix/service-queue-storage", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "format": "biome format --write", | ||
| "format:check": "biome format .", | ||
| "prebuild": "pnpm run lint", | ||
| "build": "tsgo --build", | ||
| "watch": "tsgo --watch", | ||
| "test": "vitest -c vitest.config.ts run --exclude src/**/*.integration.test.ts --silent --reporter=dot", | ||
| "test:coverage": "vitest run --coverage --exclude src/**/*.integration.test.ts --reporter=dot", | ||
| "test:integration": "vitest run src/service-queue-storage.integration.test.ts --reporter=dot", | ||
| "test:watch": "vitest", | ||
| "lint": "biome lint", | ||
| "clean": "rimraf dist" | ||
| }, | ||
| "dependencies": { | ||
| "@azure/storage-queue": "^12.10.0", | ||
| "@azure/identity": "^4.13.1", | ||
| "zod": "^3.22.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@cellix/config-typescript": "workspace:*", | ||
| "@cellix/config-vitest": "workspace:*", | ||
| "@vitest/coverage-istanbul": "catalog:", | ||
| "rimraf": "catalog:", | ||
| "typescript": "catalog:", | ||
| "vitest": "catalog:" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| export type { | ||
| InboundQueueMap, | ||
| InboundQueueSchema, | ||
| IQueueConsumerOperations, | ||
| IQueueStorageOperations, | ||
| OutboundQueueMap, | ||
| OutboundQueueSchema, | ||
| PeekMessagesOptions, | ||
| QueueMessage, | ||
| QueueMessageContract, | ||
| QueueStorageConfig, | ||
| ReceiveMessagesOptions, | ||
| SendMessageOptions, | ||
| } from './interfaces.js'; | ||
| export type { LogAddress } from './logging.js'; | ||
| export { BlobQueueMessageLogger } from './logging.js'; | ||
|
|
||
| export { defineQueueMessage } from './message-contracts.js'; | ||
| export { moveMessageToPoison } from './poison.js'; | ||
| export type { QueueConsumerContext } from './queue-consumer.js'; | ||
| export { createQueueConsumer } from './queue-consumer.js'; | ||
| export type { QueueDefinition, QueueDefinitions, QueueProducerContext } from './queue-producer.js'; | ||
| export { createQueueProducer } from './queue-producer.js'; | ||
|
|
||
| export { registerQueues } from './register-queues.js'; | ||
| export { ServiceQueueStorage } from './service-queue-storage.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { ZodTypeAny } from 'zod'; | ||
| import type { IQueueMessageLogger } from './logging.js'; | ||
|
|
||
| export type QueueStorageConfig = { | ||
| accountName?: string; | ||
| connectionString?: string; | ||
| localDev?: boolean; | ||
| /** Optional list of queues that should be auto-provisioned in local/dev environments */ | ||
| provisionQueues?: string[]; | ||
| logging?: { | ||
| enabled: boolean; | ||
| container: string; | ||
| await?: boolean; | ||
| }; | ||
| /** Optional logger implementation for persisting message envelopes */ | ||
| logger?: IQueueMessageLogger; | ||
| }; | ||
|
|
||
| export type QueueMessage<T = unknown> = { | ||
| id: string; | ||
| popReceipt?: string; | ||
| payload: T; | ||
| dequeueCount?: number; | ||
| }; | ||
|
|
||
| export type SendMessageOptions = { visibilityTimeoutSeconds?: number; loggingTags?: Record<string, string> }; | ||
| export type ReceiveMessagesOptions = { maxMessages?: number; visibilityTimeout?: number }; | ||
| export type PeekMessagesOptions = { maxMessages?: number }; | ||
|
|
||
| export interface IQueueStorageOperations { | ||
| sendMessage<_T = unknown>(queue: string, message: string | object, opts?: SendMessageOptions): Promise<void>; | ||
| sendValidatedMessage<T>(queue: string, contract: QueueMessageContract<T>, payload: T, opts?: SendMessageOptions): Promise<void>; | ||
| receiveMessages<_T = unknown>(queue: string, opts?: ReceiveMessagesOptions): Promise<QueueMessage<_T>[]>; | ||
| deleteMessage(queue: string, messageId: string, popReceipt: string): Promise<void>; | ||
| peekMessages<_T = unknown>(queue: string, opts?: PeekMessagesOptions): Promise<QueueMessage<_T>[]>; | ||
| } | ||
|
|
||
| export interface IQueueConsumerOperations { | ||
| receiveMessages<T = unknown>(queue: string, opts?: ReceiveMessagesOptions): Promise<QueueMessage<T>[]>; | ||
| deleteMessage(queue: string, messageId: string, popReceipt: string): Promise<void>; | ||
| } | ||
|
|
||
| export type QueueMessageContract<T> = { | ||
| encode(payload: T): string; | ||
| decode(raw: string): T; | ||
| }; | ||
|
|
||
| // New: explicit schema shapes for application-level queue definitions | ||
| export type OutboundQueueSchema<S extends ZodTypeAny = ZodTypeAny> = { | ||
| queueName: string; | ||
| schema: S; | ||
| loggingTags?: Record<string, string>; | ||
| }; | ||
|
|
||
| export type InboundQueueSchema<S extends ZodTypeAny = ZodTypeAny> = { | ||
| queueName: string; | ||
| schema: S; | ||
| loggingTags?: Record<string, string>; | ||
| }; | ||
|
|
||
| export type OutboundQueueMap = Record<string, OutboundQueueSchema>; | ||
| export type InboundQueueMap = Record<string, InboundQueueSchema>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| export type MessageLogEnvelope = { | ||
| queue: string; | ||
| messageId?: string; | ||
| payload: unknown; | ||
| metadata?: Record<string, unknown>; | ||
| createdAt?: string; | ||
| }; | ||
|
|
||
| export type LogAddress = { container: string; blobName: string; url?: string }; | ||
|
|
||
| export interface IQueueMessageLogger { | ||
| logMessage(envelope: MessageLogEnvelope): Promise<LogAddress>; | ||
| } | ||
|
|
||
| type BlobStorageLike = { | ||
| uploadText(request: { containerName: string; blobName: string; text: string }): Promise<unknown>; | ||
| }; | ||
|
|
||
| export class BlobQueueMessageLogger implements IQueueMessageLogger { | ||
| private readonly blobStorage: BlobStorageLike; | ||
| private readonly containerName: string; | ||
| constructor(blobStorage: BlobStorageLike, containerName: string) { | ||
| this.blobStorage = blobStorage; | ||
| this.containerName = containerName; | ||
| } | ||
|
|
||
| public async logMessage(envelope: MessageLogEnvelope): Promise<LogAddress> { | ||
| const name = `${envelope.queue}/${envelope.messageId ?? Date.now().toString()}.json`; | ||
| const text = JSON.stringify({ envelope }, null, 2); | ||
| await this.blobStorage.uploadText({ containerName: this.containerName, blobName: name, text }); | ||
| return { container: this.containerName, blobName: name, url: `${this.containerName}/${name}` }; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
packages/cellix/service-queue-storage/src/message-contracts.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { ZodType } from 'zod'; | ||
|
|
||
| export function defineQueueMessage<T>(schema: ZodType<T>) { | ||
| return { | ||
| encode(payload: T): string { | ||
| schema.parse(payload); | ||
| return JSON.stringify(payload); | ||
| }, | ||
| decode(raw: string): T { | ||
| const parsed = JSON.parse(raw); | ||
| return schema.parse(parsed); | ||
| }, | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk):
visibilityTimeoutSecondsin SendMessageOptions is not used when sending messages.SendMessageOptionsexposesvisibilityTimeoutSeconds, butServiceQueueStorage.sendMessageignores it and always callsqueueClient.sendMessage(encoded)with no options. This will silently drop any caller-specified visibility timeout. Please either pass it through to the Azure SDK (e.g.{ visibilityTimeout: opts.visibilityTimeoutSeconds }) or remove the field from the public type to avoid a misleading API.