Skip to content

Commit d314686

Browse files
committed
Now using external AMQP URI
1 parent 13235ad commit d314686

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

component.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
22
"title": "PubSub",
33
"description": "Pub/Sub Component for async communication with queues and topics",
4+
"credentials": {
5+
"fields": {
6+
"amqpURI": {
7+
"label": "AMQP URI",
8+
"required": true,
9+
"viewClass": "TextFieldView",
10+
"placeholder": "amqp://foo:[email protected]"
11+
}
12+
}
13+
},
414
"actions": {
515
"publish": {
616
"title": "Publish",

lib/actions/publish.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ module.exports.process = processAction;
1212
*
1313
* @param msg incoming message object that contains ``body`` with payload
1414
* @param cfg configuration that is account information and configuration field values
15-
* @param snapshot - current values from the snapshot
1615
*/
17-
function processAction(msg, cfg, snapshot) {
16+
function processAction(msg, cfg) {
1817
console.log('Action started');
19-
const amqpURI = process.env.ELASTICIO_AMQP_URI;
18+
const amqpURI = cfg.amqpURI;
2019
const amqpExchange = `pubsub_${process.env.ELASTICIO_TASK_ID}_${process.env.ELASTICIO_USER_ID}`;
2120
co(function*() {
2221
if (!conn) {

verifyCredentials.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
'use strict';
22
const co = require('co');
3-
const rp = require('request-promise');
3+
const amqp = require('amqplib');
44

55
// This function will be called by the platform to verify credentials
66
module.exports = function verifyCredentials(credentials, cb) {
77
console.log('Credentials passed for verification %j', credentials);
8-
8+
const amqpURI = credentials.amqpURI;
9+
const amqpExchange = 'verify_credentials_test';
910
co(function*() {
10-
console.log('Fetching user information');
11-
12-
const test = yield rp({
13-
uri: 'https://cdn.elastic.io/test.json',
14-
json: true
15-
});
16-
17-
console.log('Fetched JSON value=%j', test);
18-
19-
console.log('Verification completed');
20-
11+
console.log('Connecting to amqpURI=%s', amqpURI);
12+
const conn = yield amqp.connect(amqpURI);
13+
console.log('Creating a confirm channel');
14+
const channel = yield conn.createConfirmChannel();
15+
console.log('Asserting topic exchange exchange=%s', amqpExchange);
16+
yield channel.assertExchange(amqpExchange, 'topic', { durable: false });
17+
console.log('Verified successfully');
2118
cb(null, {verified: true});
2219
}).catch(err => {
2320
console.log('Error occurred', err.stack || err);

0 commit comments

Comments
 (0)