Registry / messaging / graphql-amqp-subscriptions

graphql-amqp-subscriptions

JSON →
library3.0.1jsnpmunverified

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.

npm install graphql-amqp-subscriptions
INSTALL
IMPORT
SIG · GRAPHQL-AMQP-SUBSC
G
graphql-amqp-subscriptions
messagingjavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AMQPPubSub
import { AMQPPubSub } from 'graphql-amqp-subscriptions'
const AMQPPubSub = require('graphql-amqp-subscriptions')
Package exports ES modules; CommonJS require will not work correctly.
default
import AMQPPubSub from 'graphql-amqp-subscriptions'
import { AMQPPubSub } from 'graphql-amqp-subscriptions'
Default export also available, but named export is preferred.
AMQPPubSubOptions
import { AMQPPubSubOptions } from 'graphql-amqp-subscriptions'
import { Options } from 'graphql-amqp-subscriptions'
TypeScript type for the constructor options object.

Shows how to connect to RabbitMQ, create an AMQPPubSub instance, publish and subscribe using a topic exchange.

import amqp from 'amqplib'; import { AMQPPubSub } from 'graphql-amqp-subscriptions'; const connection = await amqp.connect(process.env.AMQP_URL ?? 'amqp://guest:guest@localhost:5672?heartbeat=30'); const pubsub = new AMQPPubSub({ connection, exchange: { name: 'my-exchange', type: 'topic', options: { durable: false, autoDelete: true } }, queue: { name: 'my-queue', options: { exclusive: true, durable: true, autoDelete: true }, unbindOnDispose: false, deleteOnDispose: false } }); // Publish and subscribe pubsub.publish('POST_CREATED', { post: { id: '1' } }); const subscription = pubsub.subscribe('POST_CREATED', (message) => { console.log('Received:', message); }); // Cleanup await pubsub.dispose(); await connection.close();
Debug
Known issues
breakinggraphql-amqp-subscriptions@3 requires graphql@16.x and graphql-subscriptions@3.x. Version 2 required older versions.
fix
Upgrade to graphql@16 and graphql-subscriptions@3, or use graphql-amqp-subscriptions@2 for older dependencies.
affects: >=3.0.0
deprecatedThe 'connection' option expects an amqplib connection object; passing a URL string was supported in previous versions but is deprecated in v3.
fix
Connect explicitly using amqplib.connect() and pass the resulting connection object.
affects: >=3.0.0
gotchaThe queue options 'unbindOnDispose' and 'deleteOnDispose' are boolean and default to false. Misconfiguring these can cause queue leaks.
fix
Set unbindOnDispose: true and deleteOnDispose: true to automatically clean up queues and bindings on dispose.
affects: >=2.0.0
gotchaChannel reuse: one channel is used for all subscriptions, another for publishing. Not closing them properly can lead to resource exhaustion.
fix
Always call pubsub.dispose() and close the amqplib connection when done.
affects: >=1.0.0
gotchaError handling: if the connection drops, the pubsub instance will not automatically reconnect. You must implement reconnection logic externally.
fix
Wrap in a connection error listener and reinitialize pubsub on 'close' or 'error' events.
affects: >=1.0.0
Errors
Common errors & fixes
AMQPPubSub is not a constructor
Using CommonJS require instead of ES import
fix
Use `import { AMQPPubSub } from 'graphql-amqp-subscriptions'` or enable esModuleInterop in tsconfig.
Cannot find module 'graphql-amqp-subscriptions'
Package not installed or missing peer dependencies
fix
Run `npm install graphql-amqp-subscriptions amqplib graphql graphql-subscriptions`.
TypeError: Cannot read properties of undefined (reading 'publish')
Using pubsub before connection is ready
fix
Make sure the amqplib connection promise resolves before creating AMQPPubSub.
ExchangeNotFound: no exchange '...' in vhost '/'
Exchange declared with passive mode or not created
fix
Ensure exchange options are correctly configured and the exchange exists, or set passive to false.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
amqplibrequiredAMQP connection and channel management
graphqlrequiredGraphQL type system and subscription logic
graphql-subscriptionsrequiredPubSubEngine interface to implement
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
graphql-amqp-subscriptions — npm install graphql-amqp-subscriptions · libregistry