moleculerjs / moleculer-channels

Reliable messages for Moleculer services via external queue/channel/topic.
MIT License
72 stars 15 forks source link

sendToChannel middleware hook is not firing #65

Closed ujwal-setlur closed 1 year ago

ujwal-setlur commented 1 year ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Current Behavior

I have a middleware where I have both localChannel and sesndToChannel hooks. The localChannel hook is firing, but the sendToChannel hook is not.

Expected Behavior

sendToChannelHook should fire.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

Create middleware with localChannel and sendToChannel hooks. The middleware is dynamically loaded after broker starts with broker.middlewares.add()

Reproduce code snippet

    localChannel(next, chan) {
        return async (msg, raw) => {
            this.logger.info(kleur.magenta(`  Before localChannel for '${chan.name}'`), msg);
            await next(msg, raw);
            this.logger.info(kleur.magenta(`  After localChannel for '${chan.name}'`), msg);
        };
    },

    // Wrap the `broker.sendToChannel` method
    sendToChannel(next) {
        return async (channelName, payload, opts) => {
            this.logger.info(kleur.yellow(`Before sendToChannel for '${channelName}'`), payload);
            await next(channelName, payload, opts);
            this.logger.info(kleur.yellow(`After sendToChannel for '${channelName}'`), payload);
        };
    }

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

none

AndreMaz commented 1 year ago

Hi @ujwal-setlur This is also related to the previous issue that you've opened re dynamic middleware. Please check this comment: https://github.com/moleculerjs/moleculer-channels/issues/60#issuecomment-1412498489

ujwal-setlur commented 1 year ago

Ok thanks @AndreMaz