@talema/graphql-azure-servicebus-subscriptions
v0.5.2
Published
A GraphQL subscription library using Azure Service Bus topics as PubSub server
Downloads
1,723
Maintainers
Readme
GraphQL Azure Service Bus Subscription Library
This package implements the PubSubEngine Interface from the graphql-subscriptions package. It allows you to connect your subscriptions manger to a Azure ServiceBus mechanism to support multiple subscription manager instances.
Installation
npm install @talema/graphql-azure-servicebus-subscriptions
Usage
Initializing the Azure ServiceBus pubsub client
import { ServiceBusPubSub, IServiceBusOptions } from "@talema/graphql-azure-servicebus-subscriptions";
const options: IServiceBusOptions = {
connectionString: process.env.SERVICEBUS_CONNECTION_STRING!,
topicName: process.env.SERVICEBUS_TOPIC!,
subscriptionName: process.env.SERVICEBUS_SUBSCRIPTION_NAME!,
triggerFilterEnabled: true,
}
export const pubsub = new ServiceBusPubSub(options);
Publishing message to the subscription - Azure Topic
nameChanged = {
firstName: "Abdo",
lastName: "Talema"
}
Or
nameChanged : ServiceBusMessage {
body: {
firstName: "Abdo",
lastName: "Talema"
}
}
pubsub.publish("nameChangedEvent", payload);
Subscribing to the configured topic events - filtered by event name
Payload would be the published plain message object
const onMessage = (payload) => {
console.log(message);
}
const subscription = await pubsub.subscribe('nameChanged', onMessage);
Note
The current version of the ServiceBusPubSub
works with the Competing Consumer pattern. This means if there are (n) of the GraphQL server running theses instances will be competing on consuming notifications updates.
The new version to support publishing notification updates to all the GraphQL instances will be coming soon.
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:
- Fork it (https://github.com/abdomohamed/graphql-azure-servicebus-subscriptions)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request