cdmbase / graphql-rabbitmq-subscriptions

A graphql subscriptions implementation using rabbimq and apollo's graphql-subscriptions
MIT License
116 stars 27 forks source link

Every publish event creates a brand new channel #20

Closed zestsystem closed 8 months ago

zestsystem commented 2 years ago

Subscribers respond to the events being fired but the problem is that it creates a new channel per event and only two channels process these events anyway and rest remain idle (demonstrated by the pic below). After a while, the rabbitmq hits "No channels left to allocate error".

Why are we creating a new channel per event? Why can't it use one channel to process all notification events? Let me know if there is something I'm doing wrong with implementation...

Thank you for your time and help

Screen Shot 2022-05-15 at 8 25 14 PM (2)

pubsub instantiation


export const pubsub = new AmqpPubSub({ logger });

//new follow event happens every second
setInterval(function () {
  pubsub.publish('new_follow', { id: 'hello' , username: 'help'});
}, 1000);

And implementation of subscriber (I use graphql nexus)

import { pubsub } from './../infra/rabbitmq/rabbitmq';
import { subscriptionField, objectType, extendType } from 'nexus';

export const NewFollowSubscription = subscriptionField('newFollow', {
  type: 'NewFollowSubscriptionPayload',

  subscribe: (_, args, ctx) => {
    return pubsub.asyncIterator('new_follow');
  },
  resolve(payload) {
    console.log('payload: ', payload);
    return {
      follower: {
        id: payload.id,
        username: payload.username,
      },
    };
  },
});

export const NewFollowSubscriptionPayload = objectType({
  name: 'NewFollowSubscriptionPayload',
  definition(t) {
    t.nonNull.field('follower', { type: 'User' });
  },
});
MallamTY commented 1 year ago

Hello,

Have you been able to resolve this or find an alternative to it? I am working on a project currently and I have implemented this before notificing the issue

zestsystem commented 1 year ago

@MallamTY I found an alternative. I think it would help to post an answer here if you would like to provide one :) I will close this issue after.

MallamTY commented 1 year ago

I haven't been unable to get a solution either @zestsystem.

MallamTY commented 1 year ago

Is there a way we can connect outside this conversation?

I will be glad if you can help with the alternative