diff --git a/sqs-producer/sqs-producer-tests.ts b/sqs-producer/sqs-producer-tests.ts new file mode 100644 index 0000000000..f224ab11fb --- /dev/null +++ b/sqs-producer/sqs-producer-tests.ts @@ -0,0 +1,52 @@ +// Taken straight from sqs-producer's README.md + +/// + + +import * as Producer from "sqs-producer"; + +var producer = Producer.create({ + queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name', + region: 'eu-west-1' +}); + +// send messages to the queue +producer.send(['msg1', 'msg2'], function(err) { + if (err) console.log(err); +}); + +// get the current size of the queue +producer.queueSize(function (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' +}], function(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 + } +], function(err) { + if (err) console.log(err); +}); diff --git a/sqs-producer/sqs-producer.d.ts b/sqs-producer/sqs-producer.d.ts new file mode 100644 index 0000000000..10638f90c5 --- /dev/null +++ b/sqs-producer/sqs-producer.d.ts @@ -0,0 +1,51 @@ +// Type definitions for sqs-producer +// Project: https://github.com/BBC/sqs-producer +// Definitions by: Daniel Chao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "sqs-producer" { + + import { SQS } from "aws-sdk"; + + module SQSProducer { + + interface ProducerOpts { + queueUrl: string; + region?: string; + batchSize?: number; + sqs?: SQS; + } + + interface ProducerCallback { + (err?: Error, data?: T): any; + } + + interface ProducerMessageAttribute { + DataType: "String"|"Binary"; + StringValue?: string; + BinaryValue?: Buffer; + } + + interface ProducerMessage { + id: string; + body: string; + messageAttributes?: { [key: string]: ProducerMessageAttribute } + delaySeconds?: number; + } + + interface ProducerFactory { + create(opts: ProducerOpts): Producer; + } + + interface Producer { + send(messages: string[], cb: ProducerCallback): void; + send(messages: ProducerMessage[], cb: ProducerCallback): void; + queueSize(cb: ProducerCallback): void; + } + } + + const Producer: SQSProducer.ProducerFactory; + export = Producer; +}