-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (34 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const azure = require('azure-sb')
module.exports = options => {
if (!options) {
throw Error('Missing required input: options')
}
if (!options.connectionString) {
throw Error('Missing required input: options.connectionString')
}
if (!options.topicName && !options.queueName) {
throw Error('Missing required input: missing options.topicName or options.queueName')
}
const sbService = azure.createServiceBusService(options.connectionString)
return (messageBody) => {
return new Promise((resolve, reject) => {
if (!messageBody) {
throw Error('Missing required input: messageBody')
}
const message = {
...options.settings,
body: JSON.stringify(messageBody),
contentType: 'application/json'
}
if (options.queueName) {
sbService.sendQueueMessage(options.queueName, message, error => {
return error ? reject(error) : resolve(message)
})
} else if (options.topicName) {
sbService.sendTopicMessage(options.topicName, message, error => {
return error ? reject(error) : resolve(message)
})
}
})
}
}