loopback-pubsub-component
A PubSub component for LoopBack 4, trying to follow GraphQL specs and inspired by graphql-subscriptions
This is a generic component that can wraps "any" PubSub client/broker in your own repository and strategy provider.
Installation
Run the following command to install loopback-pubsub-component
:
npm i -s loopback-pubsub-component
Usage
Import component
When the loopback-pubsub-component
package is installed, bind it to your application with app.component()
;; ; app.bindPubSubBindings.CONFIG.to;app.componentPubSubComponent;app.bindPubSubBindings.PUBSUB_STRATEGY.toProviderPubSubStrategyProvider;
Create a repository
Create a repository that implements your client/broker logic, here an example for a simple EventEmitter. You could create several repositories, with MQTT client or other kinds of PubSub clients.
;;;
Strategy provider
Create a strategy provider that implements your custom logic. If you have several repositories, inject them and create a function to switch between repositories with trigerName filtering.
;;;;
Use in a controller
Inject the bindings, to make available PubSubStrategy provider functions.
;;;;;;; ;
TODO
- Adding decorator to use it like a router in a Controller ( @publish, @subscribe ... ) and control access ( when using broker )