graphql-rabbitmq-subscriptions icon indicating copy to clipboard operation
graphql-rabbitmq-subscriptions copied to clipboard

How to pass in a named queue to rabbitmq-pub-sub

Open developerworks opened this issue 8 years ago • 12 comments

Default behavior of rabbitmq-pub-sub is generate a random named queue like amq.gen--8B_yHhahOGcnAo7zNWK_A every time make subscription. This will cause huge number of queues generated, how to avoid this ?

developerworks avatar Sep 14 '17 06:09 developerworks

Isn't it ok to have a separate queue for distinct subscription?

groundmuffin avatar Sep 14 '17 06:09 groundmuffin

I think it's better have a way i can specify all subscriptions or a group of subscriptions use one queue. i have not find a way to bind subscription to fixed queue in rabbitmq-pub-sub

@groundmuffin

developerworks avatar Sep 17 '17 03:09 developerworks

@developerworks This package use <cdmbase/rabbitmq-pubsub>-RabbitMqSubscriber instance to create a new subscription. It's method accepts a queue config as IQueueNameConfig object. You can pass it to subscribe method to set queue and exchange names. Take a look at subscriber.ts and common.ts

groundmuffin avatar Sep 17 '17 10:09 groundmuffin

@groundmuffin I kown this, i means it's good if the configuration options can be pass to rabbitmq-pub-sub throuth AmqpPubSub configurations or something else, because i have not use rabbitmq-pub-sub directly.

developerworks avatar Sep 17 '17 11:09 developerworks

@developerworks I think triggerTransform method signature can be changed to return . And it can be used to get channel config objects instead.

groundmuffin avatar Sep 17 '17 11:09 groundmuffin

give me scenario how you want to add the configuration, so I can make the current package compatible. Feel free to open a PR.

veeramarni avatar Sep 19 '17 16:09 veeramarni

May be the config key of AmqpPubSub configuration object is the place to rabbitmq configurations, such as: host, port, username,password, exchange, queue, durability, auto_delete and so on.

const pubsub = new AmqpPubSub({
  config: {
    host: RABBITMQ_DOMAIN_NAME, // Could connect rabbitmq server from remote client with `username:password@hostname`, but could specify independently is better in config
    port: PORT_NUMBER,
    username: String, // optional
    password: String, // optional
    // 
    exchange: {
        name: String, 
        type: headers | fanout | topic | direct 
        durability: Boolean,
        autodelete: Boolean,
        internal: Boolean,
        arguments: {
            "alternate-exchange": String
        }
    },
    // Object, Queue creation params
    queue: {
        name: '',
        durability: Boolean,
        autodelete: Boolean,   
        // If exists, shoud be pass to rabbitmq server
        arguments: {
            "x-message-ttl": Number,
            "x-expires": Number,
            "x-max-length": Number,
            "x-max-length-bytes": Number,
            "x-dead-letter-exchange": String,
            "x-dead-letter-routing-key": String,
            "x-max-priority": Number
         }
    },
  },
  logger,
});

developerworks avatar Sep 19 '17 16:09 developerworks

This is exported definitions of rabbitmq, i think most of these is configuable.

{
  "rabbit_version": "3.5.7",
  "users": [
    {
      "name": "notification",
      "password_hash": "bjI3Bv7PnxcbBRhB3znGmT++uWw=",
      "tags": "administrator"
    },
    {
      "name": "register_notice",
      "password_hash": "kmCJDlEoiK716RcEXY9YWIVKi6c=",
      "tags": "administrator"
    },
    {
      "name": "guest",
      "password_hash": "Cz+gtiAstAx3gYqulClXE64bgGM=",
      "tags": "administrator"
    }
  ],
  "vhosts": [
    {
      "name": "/"
    }
  ],
  "permissions": [
    {
      "user": "register_notice",
      "vhost": "/",
      "configure": ".*",
      "write": ".*",
      "read": ".*"
    },
    {
      "user": "notification",
      "vhost": "/",
      "configure": ".*",
      "write": ".*",
      "read": ".*"
    },
    {
      "user": "guest",
      "vhost": "/",
      "configure": ".*",
      "write": ".*",
      "read": ".*"
    }
  ],
  "parameters": [],
  "policies": [],
  "queues": [
    {
      "name": "graphql",
      "vhost": "/",
      "durable": true,
      "auto_delete": false,
      "arguments": {}
    },
    {
      "name": "graphql-operations",
      "vhost": "/",
      "durable": true,
      "auto_delete": false,
      "arguments": {}
    },
    {
      "name": "user-register-notification",
      "vhost": "/",
      "durable": true,
      "auto_delete": false,
      "arguments": {}
    }
  ],
  "exchanges": [
    {
      "name": "ON_WECHAT_USER_LOGIN.DLQ.Exchange",
      "vhost": "/",
      "type": "fanout",
      "durable": false,
      "auto_delete": false,
      "internal": false,
      "arguments": {}
    },
    {
      "name": "ON_WECHAT_USER_AUTHORIZED.DLQ.Exchange",
      "vhost": "/",
      "type": "fanout",
      "durable": false,
      "auto_delete": false,
      "internal": false,
      "arguments": {}
    },
    {
      "name": "orderCreated.DLQ.Exchange",
      "vhost": "/",
      "type": "fanout",
      "durable": false,
      "auto_delete": false,
      "internal": false,
      "arguments": {}
    }
  ],
  "bindings": [
    {
      "source": "amq.topic",
      "vhost": "/",
      "destination": "user-register-notification",
      "destination_type": "queue",
      "routing_key": "#an125",
      "arguments": {}
    },
    {
      "source": "amq.topic",
      "vhost": "/",
      "destination": "graphql-operations",
      "destination_type": "queue",
      "routing_key": "#graphql_operations",
      "arguments": {}
    }
  ]
}

developerworks avatar Sep 19 '17 16:09 developerworks

I'm having the same issue here, is there a recommended way to connect to an existing exchange and queue? I can't find it in the README. Any help is appreciated.

whilelucky avatar Jul 13 '18 14:07 whilelucky

is there any way to consume an existing queue?

LyhengTep avatar Apr 29 '20 11:04 LyhengTep

same issue (also have queues that match patterns), I also have the issue that I'm using multiple exchanges, so would this mean multiple pubsub objects? and what's being published to them right now isn't exactly what I want published to graphql, I need to transform the inbound to the outbound.

xenoterracide avatar Jun 18 '20 18:06 xenoterracide

I'm having the same issue here, is there a recommended way to connect to an existing exchange and queue? I can't find it in the README. Any help is appreciated.

Have you gotten this to work? The default behavior of the lib creates a new channel per event and most end up being idle and I want to pass in one specific channel to use. Is seems this project is not being maintained as this issue's been around for years without answer :(

zestsystem avatar May 16 '22 04:05 zestsystem