在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):cdmbase/graphql-rabbitmq-subscriptions开源软件地址(OpenSource Url):https://github.com/cdmbase/graphql-rabbitmq-subscriptions开源编程语言(OpenSource Language):TypeScript 100.0%开源软件介绍(OpenSource Introduction):graphql-rabbitmq-subscriptionsThis 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 Usageimport { AmqpPubSub } from 'graphql-rabbitmq-subscriptions';
const logger = <log function>;
const pubsub = new AmqpPubSub({logger});
const subscriptionManager = new SubscriptionManager({
schema,
pubsub,
setupFunctions: {},
}); Logging exampleThe 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
More details about @cdm-logger/server Using Trigger TransformRecently, 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 const pubsub = new AmqpPubSub({
triggerTransform,
}); Lastly, I provide a setupFunction for const subscriptionManager = new SubscriptionManager({
schema,
setupFunctions: {
commentsAdded: (options, {repoName}) => ({
'comments.added': {
channelOptions: {path: [repoName]},
},
}),
},
pubsub,
}); When I call 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 Passing rabbitmq options objectThe 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,
}); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论