Skip to content

v3.12.0

Compare
Choose a tag to compare
@ocoanet ocoanet released this 06 Sep 14:27
· 58 commits to master since this release
  • Support custom startup subscriptions on message handlers

SubscriptionModeAttribute can now be configured with the type of a custom IStartupSubscriber. The startup subscriber will be used to create the startup subscriptions for the target message handler.

Complete example:

[SubscriptionMode(typeof(StartupSubscriber))]
public class CustomSubscriptionHandler : IMessageHandler<RoutableEvent>
{
    public void Handle(RoutableEvent message)
    {
    }

    public class StartupSubscriber : IStartupSubscriber
    {
        private readonly IBus _bus;

        public StartupSubscriber(IBus bus)
        {
            _bus = bus;
        }

        public IEnumerable<BindingKey> GetStartupSubscriptionBindingKeys(Type messageType)
        {
            if (messageType != typeof(RoutableEvent))
                throw new NotSupportedException();

            yield return new BindingKey(_bus.PeerId.ToString());
        }
    }
}