moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Miss-leading documentation for Custom Transporter and Serializer

Open JordanPawlett opened this issue 4 years ago • 2 comments

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.

JordanPawlett avatar Jan 20 '21 12:01 JordanPawlett

Could you create a repro example?

icebob avatar May 23 '21 14:05 icebob

Yep. I will get around to it eventually!

JordanPawlett avatar Jun 11 '21 13:06 JordanPawlett

// 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"));

intech avatar Oct 10 '22 23:10 intech