Skip to content

Commit

Permalink
Use rabbitmq for API pubsub engine
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketeerbkw committed Dec 10, 2018
1 parent 52ef93b commit 8ab8b83
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions services/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"graphql": "^0.13.2",
"graphql-iso-date": "^3.5.0",
"graphql-list-fields": "^2.0.2",
"graphql-rabbitmq-subscriptions": "^1.1.0",
"graphql-subscriptions": "^1.0.0",
"graphql-tools": "^2.5.0",
"jsonwebtoken": "^8.0.1",
Expand Down
35 changes: 34 additions & 1 deletion services/api/src/clients/pubSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,45 @@

const R = require('ramda');
const { PubSub, withFilter } = require('graphql-subscriptions');
const { AmqpPubSub } = require('graphql-rabbitmq-subscriptions');
const { ForbiddenError } = require('apollo-server-express');
const logger = require('../logger');
const sqlClient = require('./sqlClient');
const { query } = require('../util/db');
const environmentSql = require('../resources/environment/sql');

const pubSub = new PubSub();
const rabbitmqHost = process.env.RABBITMQ_HOST || 'rabbitmq';
const rabbitmqUsername = process.env.RABBITMQ_USERNAME || 'guest';
const rabbitmqPassword = process.env.RABBITMQ_PASSWORD || 'guest';

/* eslint-disable class-methods-use-this */
class LoggerConverter {
child() {
return {
debug: logger.debug,
trace: logger.silly,
error: logger.error,
};
}

error(...args) {
return logger.error.apply(args);
}

debug(...args) {
return logger.debug(args);
}

trace(...args) {
return logger.silly(args);
}
}
/* eslint-enable class-methods-use-this */

const pubSub = new AmqpPubSub({
config: `amqp://${rabbitmqUsername}:${rabbitmqPassword}@${rabbitmqHost}`,
logger: new LoggerConverter(),
});

const createEnvironmentFilteredSubscriber = (events: string[]) => {
return {
Expand Down
67 changes: 66 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1557,11 +1557,24 @@
dependencies:
"@types/node" "*"

"@types/amqplib@^0.5.1":
version "0.5.9"
resolved "https://registry.yarnpkg.com/@types/amqplib/-/amqplib-0.5.9.tgz#94fa80fad2fdbe78f458ccb9c5fb0abfe62f817c"
integrity sha512-V4OFDKeu8rY2DnbHAh7J7DaJ8L8LZ7EyOLBoXsN2rtlCoB2QwaTgx2SsBd22mPUC9kl+vK7D+nfLq34jLhEjlA==
dependencies:
"@types/bluebird" "*"
"@types/node" "*"

"@types/async@2.0.50":
version "2.0.50"
resolved "https://registry.yarnpkg.com/@types/async/-/async-2.0.50.tgz#117540e026d64e1846093abbd5adc7e27fda7bcb"
integrity sha512-VMhZMMQgV1zsR+lX/0IBfAk+8Eb7dPVMWiQGFAt3qjo5x7Ml6b77jUo0e1C3ToD+XRDXqtrfw+6AB0uUsPEr3Q==

"@types/bluebird@*":
version "3.5.24"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.24.tgz#11f76812531c14f793b8ecbf1de96f672905de8a"
integrity sha512-YeQoDpq4Lm8ppSBqAnAeF/xy1cYp/dMTif2JFcvmAbETMRlvKHT2iLcWu+WyYiJO3b3Ivokwo7EQca/xfLVJmg==

"@types/body-parser@*":
version "1.16.8"
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.16.8.tgz#687ec34140624a3bec2b1a8ea9268478ae8f3be3"
Expand All @@ -1578,6 +1591,20 @@
"@types/connect" "*"
"@types/node" "*"

"@types/bunyan@0.0.35":
version "0.0.35"
resolved "https://registry.yarnpkg.com/@types/bunyan/-/bunyan-0.0.35.tgz#7bab9f9e26c580413b8c323d3fa76bd08dd1bcac"
integrity sha1-e6ufnibFgEE7jDI9P6dr0I3RvKw=
dependencies:
"@types/node" "*"

"@types/bunyan@^1.8.0":
version "1.8.5"
resolved "https://registry.yarnpkg.com/@types/bunyan/-/bunyan-1.8.5.tgz#d992adbce8ed20cde634764bd8f269f29f703647"
integrity sha512-7n8ANtxh2c5A/NfCuv8cVtWcgSLdq76MQbtmbInpzXuPw4TSAReUJ+MGHK4m67I4zI3ynCJoABfaeHYJaYSeRg==
dependencies:
"@types/node" "*"

"@types/connect@*":
version "3.4.32"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.32.tgz#aa0e9616b9435ccad02bc52b5b454ffc2c70ba28"
Expand Down Expand Up @@ -1649,6 +1676,11 @@
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.12.6.tgz#3d619198585fcabe5f4e1adfb5cf5f3388c66c13"
integrity sha512-wXAVyLfkG1UMkKOdMijVWFky39+OD/41KftzqfX1Oejd0Gm6dOIKjCihSVECg6X7PHjftxXmfOKA/d1H79ZfvQ==

"@types/graphql@^0.9.1":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.9.4.tgz#cdeb6bcbef9b6c584374b81aa7f48ecf3da404fa"
integrity sha512-ob2dps4itT/Le5DbxjssBXtBnloDIRUbkgtAvaB42mJ8pVIWMRuURD9WjnhaEGZ4Ql/EryXMQWeU8Y0EU73QLw==

"@types/long@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"
Expand Down Expand Up @@ -4369,6 +4401,11 @@ es6-map@^0.1.3:
es6-symbol "~3.1.1"
event-emitter "~0.3.5"

es6-promise@^4.0.5:
version "4.2.5"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.5.tgz#da6d0d5692efb461e082c14817fe2427d8f5d054"
integrity sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg==

es6-promise@^4.1.1:
version "4.2.4"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.4.tgz#dc4221c2b16518760bd8c39a52d8f356fc00ed29"
Expand Down Expand Up @@ -5581,6 +5618,25 @@ graphql-list-fields@^2.0.2:
resolved "https://registry.yarnpkg.com/graphql-list-fields/-/graphql-list-fields-2.0.2.tgz#a4ade3cfa2028a2ac32d3f2870f5f8c5b5d5b466"
integrity sha512-9TSAwcVA3KWw7JWYep5NCk2aw3wl1ayLtbMpmG7l26vh1FZ+gZexNPP+XJfUFyJa71UU0zcKSgtgpsrsA3Xv9Q==

graphql-rabbitmq-subscriptions@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/graphql-rabbitmq-subscriptions/-/graphql-rabbitmq-subscriptions-1.1.0.tgz#43a8de9f8a6ab8e8d48e60d0c8b8bc6e6ec16bc2"
integrity sha512-PK9hkh4O7E+VuK9K7jwLbYaaDpqMmoSLOYEoKWMaqrt3yIGn+kIccKNnzQHyRs5zeCazgPhQ0BCyYj038KailA==
dependencies:
"@types/bunyan" "^1.8.0"
async "^2.5.0"
graphql-subscriptions "^0.4.4"
rabbitmq-pub-sub "^0.2.5"

graphql-subscriptions@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz#39cff32d08dd3c990113864bab77154403727e9b"
integrity sha512-hqfUsZv39qmK4SEoKMnTO05U4EVvIeAD4ai5ztE9gCl4hEdeaF2Q5gvF80ONQQAnkys4odzxWYd2tBLS/cWl8g==
dependencies:
"@types/graphql" "^0.9.1"
es6-promise "^4.0.5"
iterall "^1.1.1"

graphql-subscriptions@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-1.0.0.tgz#475267694b3bd465af6477dbab4263a3f62702b8"
Expand Down Expand Up @@ -6635,7 +6691,7 @@ istanbul-reports@^1.5.1:
dependencies:
handlebars "^4.0.3"

iterall@^1.1.3, iterall@^1.2.1:
iterall@^1.1.1, iterall@^1.1.3, iterall@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
integrity sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==
Expand Down Expand Up @@ -9366,6 +9422,15 @@ quick-lru@^1.0.0:
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8"
integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g=

rabbitmq-pub-sub@^0.2.5:
version "0.2.5"
resolved "https://registry.yarnpkg.com/rabbitmq-pub-sub/-/rabbitmq-pub-sub-0.2.5.tgz#87ebfdf34eed72b763afd969c3ce47c576823129"
integrity sha1-h+v9807tcrdjr9lpw85HxXaCMSk=
dependencies:
"@types/amqplib" "^0.5.1"
"@types/bunyan" "0.0.35"
amqplib "^0.5.1"

raf@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/raf/-/raf-3.4.1.tgz#0742e99a4a6552f445d73e3ee0328af0ff1ede39"
Expand Down

0 comments on commit 8ab8b83

Please sign in to comment.