How to use the graphql-redis-subscriptions.RedisPubSub function in graphql-redis-subscriptions

To help you get started, we’ve selected a few graphql-redis-subscriptions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CoinCircle / icostats / src / server / lib / pubsub.js View on Github external
/* eslint-disable no-console*/
import { RedisPubSub } from 'graphql-redis-subscriptions';
import settings from 'settings';

const pubsub = new RedisPubSub({
  connection: {
    url: settings.REDIS_URI,
    host: 'redis',
    retry_strategy: options => {
      // reconnect after
      return Math.max(options.attempt * 100, 3000);
    }
  },
  connectionListener: (err) => {
    if (err) {
      console.error(err);
    }
    console.info('Pubsub: Succefuly connected to redis');
  }
});
github Webiks / GeoStrike / packages / server / src / graphql / redisPubSub.ts View on Github external
import {RedisPubSub} from 'graphql-redis-subscriptions';
import {config} from '../settings/config'
export const CHANNEL = config.channel;

const options = {
    host: config.host,
    port: config.port,
    retry_strategy: options => {
        // reconnect after
        return Math.max(options.attempt * 100, 3000);
    }
};

export const redisPubSub = new RedisPubSub({
    connection: options
});



// redisPubSub.subscribe(config.channel, (payload) => {
//
//     try {
//         // console.log("redisPubSub:" + JSON.stringify(payload));
//     } catch (error) {
//         console.error(`Error trying to extract new message from payload`);
//         console.error(error.message);
//     }
// });
github MichalLytek / type-graphql / examples / redis-subscriptions / index.ts View on Github external
async function bootstrap() {
  // configure Redis connection options
  const options: Redis.RedisOptions = {
    host: REDIS_HOST,
    port: REDIS_PORT,
    retryStrategy: times => Math.max(times * 100, 3000),
  };

  // create Redis-based pub-sub
  const pubSub = new RedisPubSub({
    publisher: new Redis(options),
    subscriber: new Redis(options),
  });

  // Build the TypeGraphQL schema
  const schema = await buildSchema({
    resolvers: [RecipeResolver],
    validate: false,
    pubSub, // provide redis-based instance of PubSub
  });

  // Create GraphQL server
  const server = new ApolloServer({ schema });

  // Start the server
  const { url } = await server.listen(4000);
github withspectrum / spectrum / iris / subscriptions / listeners / pubsub.js View on Github external
// @flow
/**
 * Our PubSub instance
 */
import { RedisPubSub } from 'graphql-redis-subscriptions';

const connection =
  process.env.NODE_ENV === 'production'
    ? {
        port: process.env.COMPOSE_REDIS_PORT,
        host: process.env.COMPOSE_REDIS_URL,
        password: process.env.COMPOSE_REDIS_PASSWORD,
      }
    : undefined; // Use the local instance of Redis in development by not passing any connection string

module.exports = new RedisPubSub({
  connection,
});
github coralproject / talk / services / pubsub.js View on Github external
const getClient = () => {
  if (pubsub !== null) {
    return pubsub;
  }

  // Create the new PubSub client, we only need one per instance of Talk.
  pubsub = new RedisPubSub({
    publisher: createClient(),
    subscriber: createClient(),
  });

  return pubsub;
};
github erxes / erxes-api / src / pubsub.ts View on Github external
publish: () => null,
    };

    return pubsub;
  }

  if (PUBSUB_TYPE === 'GOOGLE') {
    const googleOptions = configGooglePubsub();

    const GooglePubSub = require('@axelspringer/graphql-google-pubsub').GooglePubSub;

    const googlePubsub = new GooglePubSub(googleOptions, undefined, commonMessageHandler);

    pubsub = googlePubsub;
  } else {
    const redisPubSub = new RedisPubSub({
      connectionListener: error => {
        if (error) {
          console.error(error);
        }
      },
      publisher: new Redis(redisOptions),
      subscriber: new Redis(redisOptions),
    });

    pubsub = redisPubSub;
  }

  return pubsub;
};
github benawad / fullstack-graphql-airbnb-clone / packages / server / src / startServer.ts View on Github external
export const startServer = async () => {
  if (process.env.NODE_ENV === "test") {
    await redis.flushall();
  }

  const schema = genSchema() as any;
  applyMiddleware(schema, middleware);

  const pubsub = new RedisPubSub(
    process.env.NODE_ENV === "production"
      ? {
          connection: process.env.REDIS_URL as any
        }
      : {}
  );

  const server = new GraphQLServer({
    schema,
    context: ({ request, response }) => ({
      redis,
      url: request ? request.protocol + "://" + request.get("host") : "",
      session: request ? request.session : undefined,
      req: request,
      res: response,
      userLoader: userLoader(),
github origen-chat / api / projects / api / src / core / pubsub / pubsub.ts View on Github external
export async function startPubsub(): Promise {
  await startSubscriberAndPublisherRedisClients();

  pubsub = new RedisPubSub({
    subscriber,
    publisher,
  });
}
github OpenCTI-Platform / opencti / opencti-platform / opencti-graphql / src / database / redis.js View on Github external
import Redis from 'ioredis';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import { assoc, isEmpty, map } from 'ramda';
import conf, { isAppRealTime, logger } from '../config/conf';

const redisOptions = {
  port: conf.get('redis:port'),
  host: conf.get('redis:hostname'),
  password: conf.get('redis:password'),
  retryStrategy: times => Math.min(times * 50, 2000),
  maxRetriesPerRequest: 2
};

export const pubsub = isAppRealTime
  ? new RedisPubSub({
      publisher: new Redis(redisOptions),
      subscriber: new Redis(redisOptions)
    })
  : null;

const client = isAppRealTime && new Redis(redisOptions);
if (client) {
  client.on('error', error => {
    logger.error('[REDIS] An error occurred on redis > ', error);
  });
}
const isActive = () => client && client.status === 'ready';

export const getRedisVersion = () => {
  if (isActive()) return client.serverInfo.redis_version;
  return 'Disconnected';
github origen-chat / api / src / core / pubsub / pubsub.ts View on Github external
export async function startPubsub(): Promise {
  await startSubscriberAndPublisherRedisClients();

  pubsub = new RedisPubSub({
    subscriber,
    publisher,
  });

  logger.info('📡 pubsub ready');
}

graphql-redis-subscriptions

A graphql-subscriptions PubSub Engine using redis

MIT
Latest version published 9 days ago

Package Health Score

86 / 100
Full package analysis

Popular graphql-redis-subscriptions functions