Messaging
In some cases you may need to handle external events in you GraphQL server. To do this, our template integrates with @totalsoft/nodebb, allowing you to handle events published in a message bus using Nats, Kafka, etc. For more details see its documentation.
This feature will include the src/messaging
folder, which contains all the things you need to develope your first ervent handler.
First, you need to define the event topic you want to listen by exporting it as a string from
src/messaging/topics.js
file.Write the message handler itself, you cand cerate it in your feature folder and add it in the
src/messaging/msgHandlers.js
file.(Optional)
MessagingDataSource
- this allows you to define a custom Apollo data source that helps you explicitly publish or subscribe to events on the message bus.
Being a totally different context, we would have to apply all the middleware functions and strategies that are normally executed on a basic GraphQL request. To to so, in your src/index.js
file you fill see the following code:
This code basically executes the same middleware functions in the same order as they are executed on a GraphQL request.
When using messaging, you need to opt-in between two existing messaging transports:
nats
: uses Nats streamingrusi
: uses a sidecar container, powered by rusi, to offload messaging concerns
You can find more details here
Last updated