Skip to content

Commit

Permalink
Improving the Readme minimally to release.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopinto committed Aug 27, 2020
1 parent 9bfd097 commit fe40796
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
MIT License

Copyright (c) 2016 David Yahalomi
Copyright (c) 2020 Felix Mannhardt
Copyright (c) 2017 Horia Miron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
74 changes: 43 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# graphql-kafka-subscriptions

**Apollo graphql subscriptions over Kafka protocol**

One producer and one consumer for each node instance. Communication happens over a single kafka topic.
It implements the PubSubEngine Interface from the graphql-subscriptions package and also the new AsyncIterator interface. It allows you to connect your subscriptions manager to a single Kafka topic used as Pub/Sub communication channel.

## Installation

`npm install graphql-kafka-subscriptions`

### Mac OS High Sierra / Mojave
Expand All @@ -19,45 +18,58 @@ export LDFLAGS=-L/usr/local/opt/openssl/lib
Then you can run `npm install` on your application to get it to build correctly.

## Usage
```javascript


### Initializing the kafka pubsub client

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

export const pubsub = new KafkaPubSub({
topic: 'anything',
topic: 'name-of-the-topic',
host: 'INSERT_KAFKA_IP',
port: 'INSERT_KAFKA_PORT',
globalConfig: {} // options passed directly to the consumer and producer
})
```

With multiple Kafka nodes
```javascript
export const pubsub = new KafkaPubSub({
topic: 'anything',
host: 'kafka-10.development.foobar.com:9092,kafka-21.development.foobar.com:9092,kafka-22.development.foobar.com:9092',
})
### Publishing messages to the subcrition

```js
payload = {
firstName: "John",
lastName: "Doe"
}

pubsub.publish('pubSubChannel', payload);
```

```javascript
// as mentioned in the comments of https://github.com/ancashoria/graphql-kafka-subscriptions/issues/4
// 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
pubsub.publish({
channel: 'messageAdded',
messageAdded: newMessage,
channelId: message.channelId
});
### Subscribing to a channel

```js
const onMessage = (payload) => {
console.log(payload);
}

const subscription = await pubsub.subscribe('pubSubChannel', onMessage)
```

Special thanks to:
- [davidyaha](https://github.com/davidyaha) for [graphql-redis-subscriptions](https://github.com/davidyaha/graphql-redis-subscriptions) which was the main inspiration point for this project
- [Apollo graphql community](http://dev.apollodata.com/community/)
## Contributing

Contributions are welcome. Make sure to check the existing issues (including the closed ones) before requesting a feature, reporting a bug or opening a pull requests.

For sending a PR follow:

1. Fork it (<https://github.com/ancashoria/graphql-kafka-subscriptions/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request


**Horia Miron notes:**

Thanks to [davidyaha][1] for [graphql-redis-subscriptions][2] which was the main inspiration point for this project.

Help greatly appreciated
[1]: https://github.com/davidyaha
[2]: https://github.com/davidyaha/graphql-redis-subscriptions

0 comments on commit fe40796

Please sign in to comment.