Comments (4)
please show the errors as well.
from moleculer-channels.
@icebob here is the code that generates the error:
const { ServiceBroker } = require('moleculer');
const ChannelMiddleware = require('@moleculer/channels').Middleware;
const main = async () => {
// service schema
const serviceSchema = {
name: 'helper',
channels: {
async 'helper.sum'(payload) {
// Calls the sum method
return this.sum(payload.a, payload.b);
},
},
methods: {
sum(a, b) {
return a + b;
},
},
};
// our channel middleware
const mw = ChannelMiddleware({
adapter: {
type: 'Fake',
},
});
// create broker
let broker = new ServiceBroker({
logger: {
type: 'Console',
},
// middlewares: [mw], // If I add middleware here, it works!
});
broker.middlewares.add(mw); // If I add middleware here, it does not work!
broker.createService(serviceSchema);
await broker.start();
await broker.stop();
};
main();
Here is the error:
node index.js
[2023-01-31T19:04:19.622Z] INFO triloka-81500/BROKER: Moleculer v0.14.28 is starting...
[2023-01-31T19:04:19.623Z] INFO triloka-81500/BROKER: Namespace: <not defined>
[2023-01-31T19:04:19.623Z] INFO triloka-81500/BROKER: Node ID: triloka-81500
[2023-01-31T19:04:19.623Z] INFO triloka-81500/REGISTRY: Strategy: RoundRobinStrategy
[2023-01-31T19:04:19.623Z] INFO triloka-81500/REGISTRY: Discoverer: LocalDiscoverer
[2023-01-31T19:04:19.624Z] INFO triloka-81500/BROKER: Serializer: JSONSerializer
[2023-01-31T19:04:19.626Z] INFO triloka-81500/BROKER: Validator: FastestValidator
[2023-01-31T19:04:19.627Z] INFO triloka-81500/BROKER: Registered 13 middleware(s).
[2023-01-31T19:04:19.633Z] INFO triloka-81500/REGISTRY: '$node' service is registered.
[2023-01-31T19:04:19.634Z] INFO triloka-81500/REGISTRY: 'helper' service is registered.
[2023-01-31T19:04:19.634Z] INFO triloka-81500/$NODE: Service '$node' started.
[2023-01-31T19:04:19.634Z] INFO triloka-81500/HELPER: Service 'helper' started.
/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/@moleculer/channels/src/index.js:210
await broker.Promise.mapSeries(
^
TypeError: Cannot read properties of undefined (reading 'Promise')
at ServiceBroker.serviceCreated (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/@moleculer/channels/src/index.js:210:18)
at /Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/middleware.js:111:29
at Array.map (<anonymous>)
at MiddlewareHandler.callSyncHandlers (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/middleware.js:111:16)
at ServiceBroker.callMiddlewareHookSync (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/service-broker.js:679:27)
at Service._init (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/service.js:271:15)
at Service.parseServiceSchema (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/service.js:239:8)
at new Service (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/service.js:64:20)
at ServiceBroker.createService (/Users/ujwal/Projects/moleculer-channels-issue-60/node_modules/moleculer/src/service-broker.js:834:14)
at main (/Users/ujwal/Projects/moleculer-channels-issue-60/index.js:50:10)
Node.js v18.13.0
from moleculer-channels.
Yeah this form won't work. The middleware uses the created
hook to get the broker instance and initialize the middleware, but you add the middleware after the broker created
so this hook is not called.
It's a little hacky, but you can try to call mw.created(broker);
before adding.
from moleculer-channels.
Ok, no worries. I put it in the configuration
from moleculer-channels.
Related Issues (20)
- incorporate `moleculer_channels_` metrics to the dashboard HOT 2
- sendToChannel with Context HOT 29
- Redis Cluster Configuration Issue HOT 1
- Feature Request: Batching by Time Window or Event Count HOT 2
- Does moculer-channels support use of wildcards like the builtin events do? HOT 1
- Feature Request: Add Ability to Pause/Resume Stream Processing HOT 3
- amqp failed to reconnect
- durable_name NATS option being overwritten. HOT 2
- Error using typescript HOT 3
- The NATS Channel adapter breaks when using wildcard topics HOT 5
- emitlLocalChannelHandler error when channel is defined with options
- Custom sendMethodName is not working, still defaulting to sendToChannel HOT 2
- sendToChannel middleware hook is not firing HOT 2
- benchmark sendToChannel vs emit HOT 3
- AMQP: DEAD_LETTER exchange needs to be asserted
- Redis Adapter Capped Stream Support - "MAXLEN ~" HOT 4
- Context should have channelName
- Loosing subscriber connection to Kafka HOT 1
- Redis adapter HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moleculer-channels.