Hi Everyone, I’m using NSB 6.3 and am working with pub/sub functionality using MSMQ. Everything is working just fine but I can’t seem to find the event that get raised on the publisher when a subscriber ‘connects’. Nhibernate logs the INFO SubscriptionReceiverBehavior event but I can’t seem to figure out how I can hook into it as well. Any help would be greatly appreciated.
Thanks
Do the events get sent to the correct queues?
Take a look here also:
Cheers
Hi Sean. Yes everything is working as expected. Thanks for the link. Because I do logging outside of nhibernate, I just wanted to capture when my endpoint had a new subscriber ‘attach’ to it. I just can’t seem to locate where in the nservicebus object model I can do this.
Thanks
I’m not sure I get your question… Are you looking for the logging output?
Sean, I am looking at being able to do something along the lines what we do for endpoint errors…
// Wire up error\failed message handlers
var errors = endpointConfiguration.Notifications.Errors;
errors.MessageHasBeenSentToDelayedRetries += (sender, retry) => LogEvent(retry);
errors.MessageHasFailedAnImmediateRetryAttempt += (sender, retry) => LogEvent(retry);
errors.MessageSentToErrorQueue += (sender, retry) => LogEvent(retry);
but instead for Subscribe/Unsubscribe events. {this is made up code…}
// Wire up subscriber change handlers
var subscriptions= endpointConfiguration.Notifications.Subscriptions;
subscriptions.SubscriberAdded += (sender, subscriberInfo) => SubscriptionUpdate(SubscriberInfo);
subscriptions.SubscriberRemoved += (sender, subscriberInfo) => SubscriptionUpdate(SubscriberInfo);
I hope this helps.
Ok, Now I get what you are looking for, I’ll get back to you on this.
We don’t have that out of the box, you can use a behaviour similar to the SubscriptionReceiverBehavior that checks the message intent and rais the event.
more about behaviours here: Manipulate pipeline with behaviors • NServiceBus • Particular Docs
Does that help?
Sean, I think this will work for me. I will give it a go and let you know how it works out. Just so that I think I am on the right path… the pipeline step I register could look something like this correct?
public class LogSubscriptionEvent : Behavior<IIncomingPhysicalMessageContext>
{
public async Task Invoke(IIncomingPhysicalMessageContext context, Func<IIncomingPhysicalMessageContext, Task> next)
{
var incomingMessage = context.Message;
var intent = incomingMessage.GetMesssageIntent();
if (intent == MessageIntentEnum.Subscribe)
{
// Log Subscribe event
}
if (intent == MessageIntentEnum.Unsubscribe)
{
// Log Unsubscribe event
}
await next(context).ConfigureAwait(false);
}
}
Yea that should work although the code should be:
public class LogSubscriptionEvent : Behavior<IIncomingPhysicalMessageContext >
but you probably already figured that out.
Thanks Andreas, Correct. I just updated my previous post.
1 Like