moleculer
moleculer copied to clipboard
Miss-leading documentation for Custom Transporter and Serializer
I have reproduced this issue with both a custom transporter and serializer. I'm going to assume this is also an issue with the custom cacher too.
https://moleculer.services/docs/0.14/networking.html#Custom-transporter
The documentation suggests you should be able to just define a custom class.
https://github.com/moleculerjs/moleculer/blob/d84a6916a012664cdcc4e88fab5a780a816584be/src/transporters/index.js#L72
The resolve base index.js of the Transporter module will never find the specified Custom transporter as its not in the Transporters object specified at the top of the file.
Transporters['custom-transporter'] = CustomTransporter;
config.transporter = {
type: 'custom-transporter',
options: {
}
};
This seems to be the best way to get the broker to acknowledge and use the custom transporter.
There's also a register function. However, if using Typescript you'll receive a typeError once compiled.
Could you create a repro example?
Yep. I will get around to it eventually!
// file: moleculer.config.js
const { Middlewares, Transporters, Cachers, Serializers, Loggers, Strategies, Validators, TracerExporters, MetricReporters } = require("moleculer");
// Middleware
Middlewares.register("MyMiddleware", require("./customMiddleware"));
// Transport
Transporters.register("MyTransport", require("./customTransport"));
// Cacher
Cachers.register("MyCacher", require("./customCacher"));
// Serializer
Serializers.register("MySerializer", require("./customSerializer"));
// Logger
Loggers.register("MyLogger", require("./customLogger"));
// Balancer strategy
Strategies.register("MyStrategy", require("./customStrategy"));
// Validator
Validators.register("MyValidator", require("./customValidator"));
// Tracing exporter
TracerExporters.register("MyTracer", require("./customTracer"));
// Metric exporter
MetricReporters.register("MyMetric", require("./customMetric"));