Skip to content

Commit

Permalink
chore: make createDeduplicationId not required
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinícius Vargas committed Jun 4, 2023
1 parent f18295b commit e002594
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dxqueue",
"version": "0.2.10",
"version": "0.2.11",
"description": "Improve developer experience using the remote command pattern",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 5 additions & 4 deletions src/backends/sqs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ export type SQSBackendConfig<
createMessageAttributes?: (...params: P) => Attributes

/**
* Used for FIFO queues, ignored for standard. The group id is used for ordering messages within a 5-minute period.
* Used for FIFO queues, ignored for standard. The messages with same groupId have ordering guaranteed.
* @param params the same params passed to the function wrapped in pubsub.
* @external import('@aws-sdk/client-sqs').SendMessageCommandInput#MessageGroupId
*/
getGroupId?: (...params: P) => string
createGroupId?: (...params: P) => string

/**
* Used for FIFO queues, ignored for standard. The deduplication id is used for deduplication of messages within a 5-minute period.
* Defaults to hashing the params.
* @param params the same params passed to the function wrapped in pubsub.
* @external import('@aws-sdk/client-sqs').SendMessageCommandInput#MessageDeduplicationId
*/
getDeduplicationId?: (...params: P) => string
createDeduplicationId?: (...params: P) => string

onMessageSent?: (args: {
params: P
Expand Down
13 changes: 4 additions & 9 deletions src/backends/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,18 @@ export class SqsProducer<P extends any[]> implements Publisher<P> {
const isFifo = backendConfig.queueUrl.endsWith('.fifo')

if (isFifo) {
if (
this.backendConfig.getDeduplicationId &&
this.backendConfig.getGroupId
) {
if (this.backendConfig.createGroupId) {
this.createSendMessageCommandInput = (params: P) => ({
MessageBody: this.messageConfig.encode(params),
QueueUrl: this.backendConfig.queueUrl,
MessageAttributes: getTraceAsMessageAttributes(),
MessageDeduplicationId: this.backendConfig.getDeduplicationId!(
MessageDeduplicationId: this.backendConfig.createDeduplicationId?.(
...params,
),
MessageGroupId: this.backendConfig.getGroupId!(...params),
MessageGroupId: this.backendConfig.createGroupId!(...params),
})
} else {
throw new Error(
'FIFO queue requires getDeduplicationId and getGroupId.',
)
throw new Error('FIFO queue requires createGroupId.')
}
} else {
this.createSendMessageCommandInput = (params: P) => ({
Expand Down

0 comments on commit e002594

Please sign in to comment.