@rxdi/graphql-rabbitmq-subscriptions
A graphql-subscriptions PubSub Engine using RabbitMQ
Last updated 5 hours ago by rxdi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rxdi/graphql-rabbitmq-subscriptions 
SYNC missed versions from official npm registry.

@rxdi/graphql-rabbitmq-subscriptions

Forked from graphql-rabbitmq-subscriptions

This package implements the PusSubEngine Interface from the graphql-subscriptions package. It allows you to connect your subscriptions manger to a rabbitmq Pub Sub mechanism to support multiple subscription manager instances.

This package is copied from graphql-redis-subscriptions originally and modified to work with RabbitMQ.

Basic Usage

import { AmqpPubSub } from 'graphql-rabbitmq-subscriptions';
const logger = <log function>;
const pubsub = new AmqpPubSub({logger});
const subscriptionManager = new SubscriptionManager({
  schema,
  pubsub,
  setupFunctions: {},
});

Logging example

The logger need to be implementation of bunyan. You can use following example logger.

import {ConsoleLogger,IConsoleLoggerSettings} from "@cdm-logger/server";
import * as Logger from "bunyan";

const settings: IConsoleLoggerSettings = {
  level: "info", // Optional: default 'info' ('trace'|'info'|'debug'|'warn'|'error'|'fatal')
  mode: "short" // Optional: default 'short' ('short'|'long'|'dev'|'raw')
}

const logger: Logger = ConsoleLogger.create("<app name>", settings);

Sample Logging trace file

[15:01:16.046Z] TRACE integration-test: trying to subscribe to queue 'testSubscription' (child=amqp-pubsub, class=AmqpPubSub)
[15:01:16.050Z] DEBUG integration-test: connecting to amqp://127.0.0.1:5672 (child=rabbitmq-pub-sub, class=RabbitMqConnectionFactory)
[15:01:16.109Z] TRACE integration-test: got channel for queue 'testSubscription' (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.110Z] TRACE integration-test: setup '{"name":"testSubscription","dlq":"","dlx":"testSubscription.DLQ.Exchange"}' (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.117Z] DEBUG integration-test: queue name generated for subscription queue '(testSubscription)' is '(amq.gen-0Nan220vcDjNVmnnXZOZxg)' (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.117Z] TRACE integration-test: subscribing to queue 'testSubscription' (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.119Z] TRACE integration-test: subscribed to queue 'testSubscription' (amq.ctag-nZJSNBvCUl2V_RGYF5ie5w) (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.119Z] TRACE integration-test: publishing for queue 'testSubscription' ("good") (child=amqp-pubsub, class=AmqpPubSub)
[15:01:16.120Z] DEBUG integration-test: connecting to amqp://127.0.0.1:5672 (child=rabbitmq-pub-sub, class=RabbitMqConnectionFactory)
[15:01:16.126Z] TRACE integration-test: got channel for exchange 'testSubscription.DLQ.Exchange' (child=rabbitmq-pub-sub, class=RabbitMqPublisher)
[15:01:16.127Z] TRACE integration-test: setup '{"name":"testSubscription","dlq":"","dlx":"testSubscription.DLQ.Exchange"}' (child=rabbitmq-pub-sub, class=RabbitMqPublisher)
[15:01:16.130Z] TRACE integration-test: message sent to exchange 'testSubscription.DLQ.Exchange' ("good") (child=rabbitmq-pub-sub, class=RabbitMqPublisher)
[15:01:16.132Z] TRACE integration-test: message arrived from queue 'testSubscription' ("good") (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.133Z] TRACE integration-test: sending message to subscriber callback function '("good")' (child=amqp-pubsub, class=AmqpPubSub)
[15:01:16.137Z] TRACE integration-test: disposing subscriber to queue 'testSubscription' (amq.ctag-nZJSNBvCUl2V_RGYF5ie5w) (child=rabbitmq-pub-sub, class=RabbitMqConsumer)
[15:01:16.137Z] TRACE integration-test: list of subscriptions still available '({})' (child=amqp-pubsub, class=AmqpPubSub)
[15:01:16.138Z] TRACE integration-test: message processed from queue 'testSubscription' ("good") (child=rabbitmq-pub-sub, class=RabbitMqConsumer)

More details about @cdm-logger/server

Using Trigger Transform

Recently, graphql-subscriptions package added a way to pass in options to each call of subscribe. Those options are constructed via the setupFunctions object you provide the Subscription Manager constructor. The reason for graphql-subscriptions to add that feature is to allow pub sub engines a way to reduce their subscription set using the best method of said engine. For example, meteor's live query could use mongo selector with arguments passed from the subscription like the subscribed entity id.

This is only the standard but I would like to present an example of creating a specific subscription using the channel options feature.

First I create a simple and generic trigger transform

const triggerTransform = (trigger, {path}) => [trigger, ...path].join('.');

Then I pass it to the AmqpPubSub constructor.

const pubsub = new AmqpPubSub({
  triggerTransform,
});

Lastly, I provide a setupFunction for commentsAdded subscription field. It specifies one trigger called comments.added and it is called with the channelOptions object that holds repoName path fragment.

const subscriptionManager = new SubscriptionManager({
  schema,
  setupFunctions: {
    commentsAdded: (options, {repoName}) => ({
      'comments.added': {
        channelOptions: {path: [repoName]},
      },
    }),
  },
  pubsub,
});

When I call subscribe like this:

const query = `
  subscription X($repoName: String!) {
    comments.added(repoName: $repoName)
  }
`;
const variables = {repoName: 'graphql-rabbitmq-subscriptions'};
subscriptionManager.subscribe({query, operationName: 'X', variables, callback});

The subscription string that RabbitMQ will receive will be comments.added.graphql-rabbitmq-subscriptions. This subscription string is much more specific and means the the filtering required for this type of subscription is not needed anymore. This is one step towards lifting the load off of the graphql api server regarding subscriptions.

Passing rabbitmq options object

The basic usage is great for development and you will be able to connect to a rabbitmq server running on your system seamlessly. But for any production usage you should probably pass in a rabbitmq options object

import { AmqpPubSub } from 'graphql-rabbitmq-subscriptions';

const pubsub = new AmqpPubSub({
  config: {
    host: RABBITMQ_DOMAIN_NAME,
    port: PORT_NUMBER,
  },
  logger,
});

Current Tags

  • 0.7.67                                ...           latest (5 hours ago)

179 Versions

  • 0.7.67                                ...           5 hours ago
  • 0.7.66                                ...           16 days ago
  • 0.7.63                                ...           16 days ago
  • 0.7.62                                ...           21 days ago
  • 0.7.61                                ...           21 days ago
  • 0.7.60                                ...           21 days ago
  • 0.7.59                                ...           21 days ago
  • 0.7.58                                ...           22 days ago
  • 0.7.57                                ...           22 days ago
  • 0.7.56                                ...           22 days ago
  • 0.7.55                                ...           23 days ago
  • 0.7.54                                ...           23 days ago
  • 0.7.53                                ...           23 days ago
  • 0.7.52                                ...           23 days ago
  • 0.7.51                                ...           a month ago
  • 0.7.50                                ...           a month ago
  • 0.7.49                                ...           a month ago
  • 0.7.47                                ...           a month ago
  • 0.7.46                                ...           a month ago
  • 0.7.45                                ...           a month ago
  • 0.7.42                                ...           a month ago
  • 0.7.41                                ...           a month ago
  • 0.7.40                                ...           6 months ago
  • 0.7.39                                ...           6 months ago
  • 0.7.38                                ...           7 months ago
  • 0.7.37                                ...           7 months ago
  • 0.7.36                                ...           7 months ago
  • 0.7.35                                ...           7 months ago
  • 0.7.34                                ...           7 months ago
  • 0.7.33                                ...           7 months ago
  • 0.7.32                                ...           7 months ago
  • 0.7.31                                ...           7 months ago
  • 0.7.30                                ...           7 months ago
  • 0.7.29                                ...           7 months ago
  • 0.7.28                                ...           7 months ago
  • 0.7.27                                ...           7 months ago
  • 0.7.26                                ...           7 months ago
  • 0.7.25                                ...           7 months ago
  • 0.7.24                                ...           8 months ago
  • 0.7.23                                ...           8 months ago
  • 0.7.22                                ...           8 months ago
  • 0.7.21                                ...           8 months ago
  • 0.7.20                                ...           8 months ago
  • 0.7.19                                ...           8 months ago
  • 0.7.18                                ...           8 months ago
  • 0.7.17                                ...           8 months ago
  • 0.7.16                                ...           10 months ago
  • 0.7.15                                ...           10 months ago
  • 0.7.14                                ...           10 months ago
  • 0.7.13                                ...           10 months ago
  • 0.7.12                                ...           10 months ago
  • 0.7.11                                ...           10 months ago
  • 0.7.10                                ...           10 months ago
  • 0.7.9                                ...           10 months ago
  • 0.7.8                                ...           10 months ago
  • 0.7.7                                ...           10 months ago
  • 0.7.6                                ...           10 months ago
  • 0.7.5                                ...           10 months ago
  • 0.7.4                                ...           10 months ago
  • 0.7.3                                ...           a year ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.6.13                                ...           a year ago
  • 0.6.12                                ...           a year ago
  • 0.6.11                                ...           a year ago
  • 0.6.10                                ...           a year ago
  • 0.6.9                                ...           a year ago
  • 0.6.8                                ...           a year ago
  • 0.6.7                                ...           a year ago
  • 0.6.6                                ...           a year ago
  • 0.6.5                                ...           a year ago
  • 0.6.4                                ...           a year ago
  • 0.6.3                                ...           a year ago
  • 0.6.2                                ...           a year ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           a year ago
  • 0.5.21                                ...           a year ago
  • 0.5.20                                ...           a year ago
  • 0.5.19                                ...           a year ago
  • 0.5.18                                ...           a year ago
  • 0.5.17                                ...           a year ago
  • 0.5.16                                ...           a year ago
  • 0.5.15                                ...           a year ago
  • 0.5.14                                ...           a year ago
  • 0.5.13                                ...           a year ago
  • 0.5.12                                ...           a year ago
  • 0.5.11                                ...           a year ago
  • 0.5.10                                ...           a year ago
  • 0.5.9                                ...           a year ago
  • 0.5.8                                ...           a year ago
  • 0.5.7                                ...           a year ago
  • 0.5.6                                ...           a year ago
  • 0.5.5                                ...           a year ago
  • 0.5.4                                ...           a year ago
  • 0.5.3                                ...           a year ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0                                ...           a year ago
  • 0.4.35                                ...           a year ago
  • 0.4.34                                ...           a year ago
  • 0.4.33                                ...           a year ago
  • 0.4.32                                ...           a year ago
  • 0.4.31                                ...           a year ago
  • 0.4.30                                ...           a year ago
  • 0.4.29                                ...           a year ago
  • 0.4.28                                ...           a year ago
  • 0.4.27                                ...           a year ago
  • 0.4.26                                ...           a year ago
  • 0.4.25                                ...           a year ago
  • 0.4.24                                ...           a year ago
  • 0.4.23                                ...           a year ago
  • 0.4.22                                ...           a year ago
  • 0.4.21                                ...           a year ago
  • 0.4.20                                ...           a year ago
  • 0.4.19                                ...           a year ago
  • 0.4.18                                ...           a year ago
  • 0.4.17                                ...           a year ago
  • 0.4.16                                ...           a year ago
  • 0.4.15                                ...           a year ago
  • 0.4.14                                ...           a year ago
  • 0.4.13                                ...           a year ago
  • 0.4.12                                ...           a year ago
  • 0.4.11                                ...           a year ago
  • 0.4.10                                ...           a year ago
  • 0.4.9                                ...           a year ago
  • 0.4.8                                ...           a year ago
  • 0.4.7                                ...           a year ago
  • 0.4.6                                ...           a year ago
  • 0.4.5                                ...           a year ago
  • 0.4.4                                ...           a year ago
  • 0.4.3                                ...           a year ago
  • 0.4.2                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.19                                ...           a year ago
  • 0.3.18                                ...           a year ago
  • 0.3.17                                ...           a year ago
  • 0.3.16                                ...           a year ago
  • 0.3.15                                ...           a year ago
  • 0.3.14                                ...           a year ago
  • 0.3.13                                ...           a year ago
  • 0.3.12                                ...           a year ago
  • 0.3.11                                ...           a year ago
  • 0.3.10                                ...           a year ago
  • 0.3.9                                ...           a year ago
  • 0.3.8                                ...           a year ago
  • 0.3.7                                ...           a year ago
  • 0.3.6                                ...           a year ago
  • 0.3.5                                ...           a year ago
  • 0.3.4                                ...           a year ago
  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.36                                ...           a year ago
  • 0.2.35                                ...           a year ago
  • 0.2.34                                ...           a year ago
  • 0.2.33                                ...           a year ago
  • 0.2.32                                ...           a year ago
  • 0.2.31                                ...           a year ago
  • 0.2.30                                ...           a year ago
  • 0.2.29                                ...           a year ago
  • 0.2.28                                ...           a year ago
  • 0.2.27                                ...           a year ago
  • 0.2.26                                ...           a year ago
  • 0.2.25                                ...           a year ago
  • 0.2.24                                ...           a year ago
  • 0.2.23                                ...           a year ago
  • 0.2.22                                ...           a year ago
  • 0.2.21                                ...           a year ago
  • 0.2.20                                ...           a year ago
  • 0.2.18                                ...           a year ago
  • 0.2.17                                ...           a year ago
  • 0.2.16                                ...           a year ago
  • 0.2.15                                ...           a year ago
  • 0.2.14                                ...           a year ago
  • 0.2.13                                ...           a year ago
  • 0.2.11                                ...           a year ago
Maintainers (2)
Downloads
Today 11
This Week 11
This Month 204
Last Day 0
Last Week 0
Last Month 116
Dependencies (4)
Dev Dependencies (8)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |