Skip to content
Apollo graphql subscriptions over Kafka protocol
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Allow for a global config to be passed to the createWriteStream/creat… Mar 13, 2019
LICENSE Updated node-rdkafka and added globalConfig param Mar 15, 2019
yarn.lock ADD multiple kafka cluster endpoints Jul 6, 2018


Apollo graphql subscriptions over Kafka protocol

One producer and one consumer for each node instance. Communication happens over a single kafka topic.


npm install graphql-kafka-subscriptions

Mac OS High Sierra / Mojave

OpenSSL has been upgraded in High Sierra and homebrew does not overwrite default system libraries. That means when building node-rdkafka, because you are using openssl, you need to tell the linker where to find it:

export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

Then you can run npm install on your application to get it to build correctly.


import { KafkaPubSub } from 'graphql-kafka-subscriptions'

export const pubsub = new KafkaPubSub({
  topic: 'anything',
  host: 'INSERT_KAFKA_IP',
  globalConfig: {} // options passed directly to the consumer and producer

With multiple Kafka nodes

export const pubsub = new KafkaPubSub({
  topic: 'anything',
  host: ',,',
// as mentioned in the comments of
// you will need to upate the site calls of `publish` in your application as called out below.

// the stock PubSub::publish expects a string and an object
      pubsub.publish('messageAdded', {
        messageAdded: newMessage,
        channelId: message.channelId

// KafkaPubSub::publish expects the first parameter to be inserted into the object
        channel: 'messageAdded',
        messageAdded: newMessage,
        channelId: message.channelId

Special thanks to:

Help greatly appreciated

You can’t perform that action at this time.