{"id":47804,"library":"graphql-amqp-subscriptions","title":"graphql-amqp-subscriptions","description":"Implements the PubSubEngine interface from graphql-subscriptions using AMQP (RabbitMQ) as the pub/sub mechanism. Current stable version is 3.0.1, targeting graphql@16.x and graphql-subscriptions@3.x. Maintained since 2017 with periodic updates. Key differentiator vs alternatives like graphql-redis-subscriptions: it reuses existing amqplib connections and channels, offers flexible exchange/queue configuration, and supports topic exchanges for pattern-based routing.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Surnet/graphql-amqp-subscriptions","tags":["javascript","graphql","subscription","api","push","pull","amqp","rabbitmq","rabbit","typescript"],"install":[{"cmd":"npm install graphql-amqp-subscriptions","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-amqp-subscriptions","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-amqp-subscriptions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"AMQP connection and channel management","package":"amqplib","optional":false},{"reason":"GraphQL type system and subscription logic","package":"graphql","optional":false},{"reason":"PubSubEngine interface to implement","package":"graphql-subscriptions","optional":false}],"imports":[{"note":"Package exports ES modules; CommonJS require will not work correctly.","wrong":"const AMQPPubSub = require('graphql-amqp-subscriptions')","symbol":"AMQPPubSub","correct":"import { AMQPPubSub } from 'graphql-amqp-subscriptions'"},{"note":"Default export also available, but named export is preferred.","wrong":"import { AMQPPubSub } from 'graphql-amqp-subscriptions'","symbol":"default","correct":"import AMQPPubSub from 'graphql-amqp-subscriptions'"},{"note":"TypeScript type for the constructor options object.","wrong":"import { Options } from 'graphql-amqp-subscriptions'","symbol":"AMQPPubSubOptions","correct":"import { AMQPPubSubOptions } from 'graphql-amqp-subscriptions'"}],"quickstart":{"code":"import amqp from 'amqplib';\nimport { AMQPPubSub } from 'graphql-amqp-subscriptions';\n\nconst connection = await amqp.connect(process.env.AMQP_URL ?? 'amqp://guest:guest@localhost:5672?heartbeat=30');\n\nconst pubsub = new AMQPPubSub({\n  connection,\n  exchange: {\n    name: 'my-exchange',\n    type: 'topic',\n    options: { durable: false, autoDelete: true }\n  },\n  queue: {\n    name: 'my-queue',\n    options: { exclusive: true, durable: true, autoDelete: true },\n    unbindOnDispose: false,\n    deleteOnDispose: false\n  }\n});\n\n// Publish and subscribe\npubsub.publish('POST_CREATED', { post: { id: '1' } });\nconst subscription = pubsub.subscribe('POST_CREATED', (message) => {\n  console.log('Received:', message);\n});\n\n// Cleanup\nawait pubsub.dispose();\nawait connection.close();","lang":"typescript","description":"Shows how to connect to RabbitMQ, create an AMQPPubSub instance, publish and subscribe using a topic exchange."},"warnings":[{"fix":"Upgrade to graphql@16 and graphql-subscriptions@3, or use graphql-amqp-subscriptions@2 for older dependencies.","message":"graphql-amqp-subscriptions@3 requires graphql@16.x and graphql-subscriptions@3.x. Version 2 required older versions.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Connect explicitly using amqplib.connect() and pass the resulting connection object.","message":"The 'connection' option expects an amqplib connection object; passing a URL string was supported in previous versions but is deprecated in v3.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Set unbindOnDispose: true and deleteOnDispose: true to automatically clean up queues and bindings on dispose.","message":"The queue options 'unbindOnDispose' and 'deleteOnDispose' are boolean and default to false. Misconfiguring these can cause queue leaks.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Always call pubsub.dispose() and close the amqplib connection when done.","message":"Channel reuse: one channel is used for all subscriptions, another for publishing. Not closing them properly can lead to resource exhaustion.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap in a connection error listener and reinitialize pubsub on 'close' or 'error' events.","message":"Error handling: if the connection drops, the pubsub instance will not automatically reconnect. You must implement reconnection logic externally.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'16':27 '2017':37 '3':33 '3.0.1':24 'altern':44 'amqp':3,14,76 'amqplib':53 'api':73 'base':68 'channel':56 'configur':60 'connect':54 'current':20 'differenti':42 'exchang':64 'exchange/queue':59 'exist':52 'flexibl':58 'graphql':2,11,26,31,47,71 'graphql-amqp-subscript':1 'graphql-redis-subscript':46 'graphql-subscript':10,30 'implement':5 'interfac':8 'javascript':70 'key':41 'like':45 'maintain':35 'mechan':19 'offer':57 'pattern':67 'pattern-bas':66 'period':39 'pub/sub':18 'pubsubengin':7 'pull':75 'push':74 'rabbit':78 'rabbitmq':15,77 'redi':48 'reus':51 'rout':69 'sinc':36 'stabl':21 'subscript':4,12,32,49,72 'support':62 'target':25 'topic':63 'typescript':79 'updat':40 'use':13 'version':22 'vs':43 'x':28,34","created_at":"2026-06-07T16:53:23.461067+00:00","updated_at":"2026-06-07T16:53:23.461067+00:00","problems":[{"fix":"Use `import { AMQPPubSub } from 'graphql-amqp-subscriptions'` or enable esModuleInterop in tsconfig.","cause":"Using CommonJS require instead of ES import","error":"AMQPPubSub is not a constructor"},{"fix":"Run `npm install graphql-amqp-subscriptions amqplib graphql graphql-subscriptions`.","cause":"Package not installed or missing peer dependencies","error":"Cannot find module 'graphql-amqp-subscriptions'"},{"fix":"Make sure the amqplib connection promise resolves before creating AMQPPubSub.","cause":"Using pubsub before connection is ready","error":"TypeError: Cannot read properties of undefined (reading 'publish')"},{"fix":"Ensure exchange options are correctly configured and the exchange exists, or set passive to false.","cause":"Exchange declared with passive mode or not created","error":"ExchangeNotFound: no exchange '...' in vhost '/'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Surnet/graphql-amqp-subscriptions","github":"https://github.com/Surnet/graphql-amqp-subscriptions","docs":null,"changelog":null,"pypi":null,"npm":"graphql-amqp-subscriptions","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}