-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bus is always empty object on listen() #9
Comments
I'm guessing that's going to depend on what your Note that |
I am exporting my bus, and all is well if I don't use register-handler with that same bus. The interesting thing about { queueName: undefined,
routingKey: 'user.create',
correlationId: undefined } |
Can you paste your bus.js file contents, as well as your usage of servicebus-register-handers? |
Here's a sample of mine: bus.js:
service.js:
|
yeah mine is identical, except 'use strict';
const bus = require('../bus');
const config = require('../config');
const debug = require('debug')('user-create');
// debug('BUS:', bus); // logs out the RabbitMQ bus object
module.exports = {
ack: true,
routingKey: 'user.create',
queueName: config.SERVICE_NAME,
listen: function(cmd, cb) {
// debug('BUS:', bus); // always {}
// debug('THIS', this); // always { queueName: undefined, routingKey: 'user.create', correlationId: undefined }
cb();
}
}; |
Just as a note, I added a console.log(bus) inside one of my handlers from this same service. Here's what I get:
|
Part of your problem may be magic coming from the way I would think that the fn.call(context, ... method of calling it would have given it our context, but at least we can rule it out. |
Also, be sure that the first and only thing requiring this module is your |
so moving the functions directly to the module object |
just an fyi, this worked: exports = module.exports = {
ack: true,
routingKey: 'user.created',
subscribe: function(event, cb) {
const user = event.data;
debug('msg', user);
cb();
}
}; |
oh, and no matter which method I use. I still get { queueName: undefined, |
The queueName being undefined may be a bug. All of these fields are taken directly off the header properties placed on the message by Rabbitmq (and subsequently amqplib). I remember queueName being one of the properties, but don't see it in their docs now. Perhaps it's moved and now needs to be taken from local state.
or
|
Other than the above, very strange you were seeing Any more findings on that part? See #11 for a fix on |
I really don't know what was happening. I was trying several different approaches to wrapping the register-handlers module but none of them seemed to work until I moved the handlers function call out of my ./lib/bus.js module. Either way it's working atm, but when/if I have more time I will see if I can't debug more since I would like to wrap the handlers func into my bus wrapper as well. |
#11 fixed |
so the correlation id is still undefined but that might be because I'm logging it out to console before one is assigned? I do the id once it reaches the user.created subscriber though THIS { queueName: 'user.create',
routingKey: 'user.create',
correlationId: undefined } // command
exports = module.exports = {
ack: true,
routingKey: 'user.create',
queueName: 'user',
listen: function(cmd, cb) {
const user = cmd.data;
debug('THIS', this); // correlationId: undefined
cb();
}
};
// event
exports = module.exports = {
ack: true,
routingKey: 'user.created',
subscribe: function(evt, cb) {
const user = evt.data;
debug('received event', evt); // cid: '75c07874-fd96-4724-bd39-dd1032898a02'
}; |
You need to provide the correlationId in your send or publish command, as an options property. Are you doing that for the send? cid and correlationId are different. cid is placed on the message via the correlate middleware. correlationId is just a property that rabbitmq and amqplib know to store on the message.header.properties. |
ahh that was a misunderstanding on my part. thank you |
Can you help me understand why
bus
is being set to an empty object in a listen function? It seems that since the bus is passed into the register-handler and being used to attach listen and subscribe, that I should be using that same bus within the handler instead of re-requiring it in the module. I just didn't see the bus being exposed for use in that way.The text was updated successfully, but these errors were encountered: