@edd-kernel/provider-aws-sqs
v0.2.0-alpha.1
Published
AWS SQS EDD Kernel provider.
Maintainers
Readme
@edd-kernel/provider-aws-sqs
AWS SQS provider for EDD Kernel.
This package belongs to the EDD Kernel provider layer. It owns only the AWS SQS
transport mapping for the shared @edd-kernel/contracts client contract.
Repository: brunnofoggia/edd-kernel-js
Install
npm install @edd-kernel/contracts @edd-kernel/provider-aws-sqsFor provider-name based client creation, install @edd-kernel/factory in place of the
contract. It brings the contract and re-exports it:
npm install @edd-kernel/factory @edd-kernel/provider-aws-sqsUsage
import { createSqsClient } from '@edd-kernel/provider-aws-sqs';
const client = createSqsClient({ createIfNotExists: true }, { region: 'us-east-1' });
await client.send({ queueName: 'email-jobs' }, { type: 'EmailRequested', payload: {} });
await client.consume({ queueName: 'email-jobs' }, async (event, context) => {
console.log(event);
await context.ack();
});You can also create this provider through @edd-kernel/factory:
import { EddProviderName, createEddClient } from '@edd-kernel/factory';
const client = await createEddClient({
providerName: EddProviderName.AwsSqs,
createIfNotExists: true,
options: {
region: 'us-east-1',
},
});The package also exports SqsEddClient for direct construction and inheritance.
Its static provider identity is aws-sqs.
Addressing
SqsEventTarget and SqsEventQueue are what this client accepts, for sending and
consuming alike:
| Address | Meaning |
| --------------- | ---------------------------------------------------------- |
| { queueName } | A logical name, joined with env, project and prefix. |
| { queueUrl } | A queue URL written in full, used as it is. |
Any other address is refused by the compiler, and at runtime with
EddKernelConfigurationError.
A queueName is looked up once and its URL kept for the life of the client.
queueUrlByName preloads those URLs, keyed by the resolved name, so a queue listed there
is never looked up. accountId is the owner account passed to the lookup, for a queue in
another account. Creation attributes and tags for one queue are the second parameter of
createQueue.
Provider Options
client: custom SQS-compatible client for tests or adapters.region: AWS region.endpointUrl: endpoint override, reaching the SDK asendpoint.credentials: explicit credentials, taking precedence over the SDK chain.clientOptions: the rest of the AWSSQSClientconfiguration, merged over the provider defaults.queueUrlByName: pre-resolved queue URLs by queue name.createQueueAttributes: attributes passed when creating queues.createQueueTags: tags passed when creating queues.waitTimeSeconds: SQS receive wait time.pollIntervalMs: delay after an empty poll or runtime polling failure. Defaults to10.visibilityTimeout: visibility timeout for received messages.nackVisibilityTimeout: visibility timeout used whennackis called.
region, endpointUrl and credentials are named options of their own so that
the same read has the same name in both languages; every other SQSClient setting
goes through clientOptions.
Acknowledgement
ack()deletes the SQS message.nack()changes message visibility usingnackVisibilityTimeout.autoAck: truestill performs a manual delete operation; it does not enable provider-native automatic acknowledgement.
For tests, pass a custom client implementing the minimal SQS API used by this
provider.
Lifecycle
Runtime polling failures are logged and retried after pollIntervalMs. Stopping
a consumer waits for active handlers, and closing the client stops and drains
all consumers. The internally created AWS client is destroyed on close; an
injected client is never destroyed. Both lifecycle operations are idempotent.
