Closed ujwal-setlur closed 1 year ago
Can you please provide a full repro example?
This example is working fine https://github.com/moleculerjs/moleculer-channels/blob/master/examples/multi-adapter/index.js
This one also seems to be ok.
"use strict";
const { ServiceBroker } = require("moleculer");
const ChannelsMiddleware = require("../../").Middleware;
let c = 1;
// Create broker
const broker = new ServiceBroker({
namespace: "uat",
logLevel: {
CHANNELS: "debug",
"**": "info"
},
middlewares: [
ChannelsMiddleware({
adapter: process.env.ADAPTER || "Fake",
sendMethodName: "sendToAnotherChanel"
})
],
replCommands: [
{
command: "publish",
alias: ["p"],
async action(broker, args) {
const { options } = args;
//console.log(options);
await broker.sendToAnotherChanel(
"my.first.topic",
{
id: 2,
name: "Jane Doe",
status: false,
count: ++c,
pid: process.pid
},
{ key: "" + c, headers: { a: "something" } }
);
}
}
]
});
broker.createService({
name: "posts",
version: 1,
channels: {
async "my.first.topic"(msg, raw) {
this.logger.info("[POSTS] Channel One msg received", msg, raw.key, raw.headers);
}
}
});
broker
.start()
.then(async () => {
broker.repl();
//await Promise.delay(1000);
console.log("Publish 'my.first.topic' message...");
await broker.sendToAnotherChanel("my.first.topic", {
id: 1,
name: "John Doe",
status: true,
count: c,
pid: process.pid
});
})
.catch(err => {
broker.logger.error(err);
broker.stop();
});
Duh, my bad! I had the config wrong. I had it as:
const mw = ChannelMiddleware({
adapter: {
type: 'Fake',
sendMethodName: 'sendChannelMessage' // WRONG PLACE!!
}
});
It should be
const mw = ChannelMiddleware({
adapter: {
type: 'Fake',
},
sendMethodName: 'sendChannelMessage'
});
Sorry!
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Current Behavior
Specifying
sendMethodName
in the options is not working. There is no method with the specified name found. Instead, the method is still called the defaultsendToChannel
.Expected Behavior
The broker should have a method with the name specified in the
sendMethodName
option.Failure Information
Error is:
Steps to Reproduce
Set up middleware:
Send a message:
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Failure Logs