Skip to content

Commit

Permalink
feat: adding MessageSystemAttributeNames (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgriffintn authored Oct 1, 2024
1 parent e74f41a commit c35eb4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ReceiveMessageCommandInput,
ReceiveMessageCommandOutput,
QueueAttributeName,
MessageSystemAttributeName,
} from "@aws-sdk/client-sqs";

import { ConsumerOptions, StopOptions, UpdatableOptions } from "./types.js";
Expand Down Expand Up @@ -45,6 +46,7 @@ export class Consumer extends TypedEventEmitter {
private handleMessageTimeout: number;
private attributeNames: QueueAttributeName[];
private messageAttributeNames: string[];
private messageSystemAttributeNames: MessageSystemAttributeName[];
private shouldDeleteMessages: boolean;
private alwaysAcknowledge: boolean;
private batchSize: number;
Expand All @@ -71,6 +73,8 @@ export class Consumer extends TypedEventEmitter {
this.handleMessageTimeout = options.handleMessageTimeout;
this.attributeNames = options.attributeNames || [];
this.messageAttributeNames = options.messageAttributeNames || [];
this.messageSystemAttributeNames =
options.messageSystemAttributeNames || [];
this.batchSize = options.batchSize || 1;
this.visibilityTimeout = options.visibilityTimeout;
this.terminateVisibilityTimeout =
Expand Down Expand Up @@ -242,6 +246,7 @@ export class Consumer extends TypedEventEmitter {
QueueUrl: this.queueUrl,
AttributeNames: this.attributeNames,
MessageAttributeNames: this.messageAttributeNames,
MessageSystemAttributeNames: this.messageSystemAttributeNames,
MaxNumberOfMessages: this.batchSize,
WaitTimeSeconds: this.waitTimeSeconds,
VisibilityTimeout: this.visibilityTimeout,
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { SQSClient, Message, QueueAttributeName } from "@aws-sdk/client-sqs";
import {
SQSClient,
Message,
QueueAttributeName,
MessageSystemAttributeName,
} from "@aws-sdk/client-sqs";

/**
* The options for the consumer.
Expand All @@ -18,6 +23,11 @@ export interface ConsumerOptions {
* @defaultvalue `[]`
*/
messageAttributeNames?: string[];
/**
* A list of attributes that need to be returned along with each message.
* @defaultvalue `[]`
*/
messageSystemAttributeNames?: MessageSystemAttributeName[];
/** @hidden */
stopped?: boolean;
/**
Expand Down
3 changes: 3 additions & 0 deletions test/tests/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ describe("Consumer", () => {
consumer = new Consumer({
queueUrl: QUEUE_URL,
messageAttributeNames: ["attribute-1", "attribute-2"],
messageSystemAttributeNames: ["All"],
region: REGION,
handleMessage,
batchSize: 3,
Expand All @@ -944,6 +945,7 @@ describe("Consumer", () => {
QueueUrl: QUEUE_URL,
AttributeNames: [],
MessageAttributeNames: ["attribute-1", "attribute-2"],
MessageSystemAttributeNames: ["All"],
MaxNumberOfMessages: 3,
WaitTimeSeconds: AUTHENTICATION_ERROR_TIMEOUT,
VisibilityTimeout: undefined,
Expand Down Expand Up @@ -988,6 +990,7 @@ describe("Consumer", () => {
QueueUrl: QUEUE_URL,
AttributeNames: ["ApproximateReceiveCount"],
MessageAttributeNames: [],
MessageSystemAttributeNames: [],
MaxNumberOfMessages: 1,
WaitTimeSeconds: AUTHENTICATION_ERROR_TIMEOUT,
VisibilityTimeout: undefined,
Expand Down

0 comments on commit c35eb4c

Please sign in to comment.