Subscription Event


#1

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


(Sean Farmar) #2

Do the events get sent to the correct queues?

Take a look here also:
https://docs.particular.net/transports/msmq/routing?version=msmqtransport_1

Cheers


#3

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


(Sean Farmar) #4

I’m not sure I get your question… Are you looking for the logging output?


#5

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.


(Sean Farmar) #6

Ok, Now I get what you are looking for, I’ll get back to you on this.


(Sean Farmar) #7

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: https://docs.particular.net/nservicebus/pipeline/manipulate-with-behaviors

Does that help?


#8

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);
	}
}

(Andreas Öhlund) #9

Yea that should work although the code should be:

public class LogSubscriptionEvent : Behavior<IIncomingPhysicalMessageContext >

but you probably already figured that out.


#10

Thanks Andreas, Correct. I just updated my previous post.