fastify-moleculer
enables the use of Moleculer in a Fastify application.
Supports Fastify versions 4.x
Supports moleculer version 0.14
npm i fastify-moleculer moleculer
Require fastify-moleculer
and register it as any other plugin, it will add a broker
decorator.
serviceFolder
& serviceMask
options respect the configuration supported by moleculer ServiceBroker
const fastify = require("fastify")();
fastify.register(require("fastify-moleculer"), {
// put your options here
serviceFolder: './', //load all services from the given folder
serviceMask: '*.service.js' //load all services whose file nane respect the given mask
});
fastify.get("/", (req, reply) => {
fastify.broker.emit("hello", { who: 'world' });
});
fastify.listen({ port: 3000 });
For more details see examples
You can use it as is without passing any option, or you can configure it as explained by Moleculer doc.
The plugin support a preClose
hook to clean up loaded services in order to close correctly the fastify server. To configure this behaviour you can use preClose
option:
await fastify.register(require('fastify-moleculer'), {
preClose: (done) => {
// do other things
// fastify.broker. ;
done();
}
})
The plugin also adds an onClose
hook which closes the socket server when the fastify
instance is closed.
The broker
decorator is typed to moleculer ServiceBroker type.
The plugin supports loading Typescript service classes from a given folder optionally overriding the default file mask of .service.(js|ts)
.
-
Clone this repository
git clone git@github.com:github.com/ducktors/fastify-moleculer.git
-
Move inside repository folder
cd fastify-moleculer
-
Install dependencies
pnpm install
The release is performed by the maintainers of the repository. New versions are managed via changesets.
To release a new version, simply choose which package to bump with pnpm release
command:
$ pnpm release
> @ducktors/fastify-moleculer@0.9.0 release /ducktors-workstation/fastify-moleculer
> changeset
Licensed under MIT.
moleculer
license