Sqs producer (#9279)

* add sqs-producer typings

* use site url
This commit is contained in:
Daniel Chao
2016-05-11 21:48:50 -07:00
committed by Horiuchi_H
parent 00694cb526
commit 4efcbba3d4
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
// Taken straight from sqs-producer's README.md
/// <reference path="./sqs-producer.d.ts"/>
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);
});

51
sqs-producer/sqs-producer.d.ts vendored Normal file
View File

@@ -0,0 +1,51 @@
// Type definitions for sqs-producer
// Project: https://github.com/BBC/sqs-producer
// Definitions by: Daniel Chao <http://dchao.co/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path="../aws-sdk/aws-sdk.d.ts"/>
declare module "sqs-producer" {
import { SQS } from "aws-sdk";
module SQSProducer {
interface ProducerOpts {
queueUrl: string;
region?: string;
batchSize?: number;
sqs?: SQS;
}
interface ProducerCallback<T> {
(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>): void;
send(messages: ProducerMessage[], cb: ProducerCallback<void>): void;
queueSize(cb: ProducerCallback<number>): void;
}
}
const Producer: SQSProducer.ProducerFactory;
export = Producer;
}