DefinitelyTyped/types/sqs-producer/sqs-producer-tests.ts
John Hamelink 7594a53576 sqs-producer: Added missing attributes in Options interface (#35444)
* sqs-producer: Added missing attributes in Options interface

Added accessKeyId and secretAccessKey (taken from the README on the
project) to the Options interface. Added an (unused) producer to the
test with the extra Options set.

* Added my name to the "definitionsBy" as per the PR checklist
2019-05-14 14:53:58 -07:00

57 lines
1.4 KiB
TypeScript

// Taken straight from sqs-producer's README.md
import * as Producer from "sqs-producer";
const producer = Producer.create({
queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
region: 'eu-west-1'
});
const producer2 = Producer.create({
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
region: 'eu-west-1',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
});
// send messages to the queue
producer.send(['msg1', 'msg2'], err => {
if (err) console.log(err);
});
// get the current size of the queue
producer.queueSize((err, size) => {
if (err) console.log(err);
console.log('There are', size, 'messages on the queue.');
});
// send a message to the queue with a specific ID (by default the body is used as the ID)
producer.send([{
id: 'id1',
body: 'Hello world'
}], err => {
if (err) console.log(err);
});
// send a message to the queue with
// - delaySeconds (must be an number contained within 0 and 900)
// - messageAttributes
producer.send([
{
id: 'id1',
body: 'Hello world with two string attributes: attr1 and attr2',
messageAttributes: {
attr1: { DataType: 'String', StringValue: 'stringValue' },
attr2: { DataType: 'Binary', BinaryValue: new Buffer('binaryValue') }
}
},
{
id: 'id2',
body: 'Hello world delayed by 5 seconds',
delaySeconds: 5
}
], err => {
if (err) console.log(err);
});