mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
52
sqs-producer/sqs-producer-tests.ts
Normal file
52
sqs-producer/sqs-producer-tests.ts
Normal 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
51
sqs-producer/sqs-producer.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user