Skip to content

API reference / @backpack/amazon-sqs / SqsPublisher

Class: SqsPublisher

Utility for publishing messages to Amazon SQS.

Example

ts
import { SQSClient } from "@aws-sdk/client-sqs";
import { SqsPublisher } from "@backpack/amazon-sqs";

const client = new SQSClient();
const publisher = new SqsPublisher(client, "my-queue-url");

// sends the message as raw payload
await publisher.sendRaw("raw payload");

// sends the message as JSON payload
await publisher.sendJson({ foo: 'Foo' });

Constructors

Constructor

ts
new SqsPublisher(
   sqsClient, 
   queueUrl, 
   logger?): SqsPublisher;

Parameters

ParameterTypeDescription
sqsClientSQSClientThe SQS client from AWS SDK.
queueUrlstringThe URL of the SQS queue to publish to.
logger?LoggerA PowerTools logger instance, to enable additional logging.

Returns

SqsPublisher

Methods

publish()

ts
publish(message, queueUrl): Promise<void>;

Sends a single message to an SQS queue.

Parameters

ParameterTypeDescription
messagestringThe raw message payload.
queueUrlstringThe URL of the SQS queue to publish to.

Returns

Promise<void>

Deprecated

Please use SqsPublisher#sendRaw or SqsPublisher#sendJson instead.


sendJson()

ts
sendJson(message): Promise<void>;

Publishes a message as JSON to an SQS queue.

Parameters

ParameterTypeDescription
messageunknownThe message object which will be published as JSON.

Returns

Promise<void>


sendRaw()

ts
sendRaw(message): Promise<void>;

Sends a raw message to an SQS queue.

Parameters

ParameterTypeDescription
messagestringThe raw message payload.

Returns

Promise<void>