public ProducerConsumerQueue(MessageHandlerResolver messageHandlerResolver, CancellationToken cancellationToken)
        {
            this._messageHandlerResolver  = messageHandlerResolver;
            this._cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            StartWorker();
        }
        public void MessageHandlerResolverReturnsMessageHandlerInstanceForCustomSubscriptionFilterMessageProperties()
        {
            var subscriptionFilter = new SubscriptionFilter
            {
                MessageProperties = new Dictionary <string, string>
                {
                    { "MessageType", "AL" }
                }
            };

            subscriptionFilter.Build(new(), typeof(AircraftLanded));

            var services = new ServiceCollection();
            var sut      = new MessageHandlerResolver(services);

            sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(subscriptionFilter);
            sut.Initialize();
            var handler = sut.Resolve("AL");

            Assert.NotNull(handler);
            Assert.IsType <AircraftLandedHandler>(handler);

            var messageContext = new MessageContext <AircraftLanded>(new BinaryData("Hello world!"), new object(),
                                                                     new Mock <IMessageBus>().Object);

            typeof(AircraftLandedHandler).GetMethod("HandleAsync").Invoke(handler, new object[] { messageContext });
        }
        public void AddMessageSubscriptionAddsAMessageSubscription()
        {
            var subscriptionFilter = new SubscriptionFilter
            {
                Label             = nameof(AircraftLanded),
                MessageProperties = new Dictionary <string, string>
                {
                    { "AircraftType", "Commercial" }
                }
            };

            subscriptionFilter.Build(new(), typeof(AircraftLanded));

            var sut = new MessageHandlerResolver(new ServiceCollection());

            sut.SubcribeToMessage <AircraftTakenOff, AircraftTakenOffHandler>(BuildSubscriptionFilter <AircraftTakenOff>());
            sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(subscriptionFilter);
            var messageSubscriptions = sut.GetMessageHandlerMappings();

            Assert.Equal(2, messageSubscriptions.Count());
            Assert.Single(messageSubscriptions.Where(m => m.MessageHandlerType == typeof(AircraftLandedHandler)));
            Assert.Single(messageSubscriptions.Where(m => m.MessageHandlerType == typeof(AircraftTakenOffHandler)));
            Assert.Equal(subscriptionFilter.MessageProperties, messageSubscriptions.First(m =>
                                                                                          m.MessageHandlerType == typeof(AircraftLandedHandler)).SubscriptionFilter.MessageProperties);
        }
예제 #4
0
        public void Initialize()
        {
            _messageHandlers.Clear();

            var resolvedHandlers = MessageHandlerResolver.Resolve();

            AddHandlers(resolvedHandlers);
        }
        public void AddMessageSubscriptionThrowsIfNullSubscriptionFilter()
        {
            var sut = new MessageHandlerResolver(new ServiceCollection());

            sut.SubcribeToMessage <AircraftTakenOff, AircraftTakenOffHandler>(BuildSubscriptionFilter <AircraftTakenOff>());

            Assert.Throws <ArgumentNullException>(() => sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(null));
        }
        public void WhenResolvingUnknownMessageTypes_ShouldReturnDefaultHandler()
        {
            var dependencies = MockDependencyResolver
                               .Create()
                               .Register <IPoisonMessageHandler>(null);

            var resolver = new MessageHandlerResolver(new[] { typeof(TestMessageHandler) }, dependencies);
            var headers  = new Dictionary <string, string> {
                { EventDataPropertyKeys.MessageType, UnknownMessageType }
            };
            var handler = resolver.GetHandler(headers, "test-message-0");

            Assert.IsType <UnknownTypeMessageHandler>(handler);
        }
        public void WhenResolving_ShouldUseTypeFromMessageHeaders()
        {
            var dependencies = MockDependencyResolver
                               .Create()
                               .Register <IPoisonMessageHandler>(null);

            var resolver = new MessageHandlerResolver(new[] { typeof(TestMessageHandler) }, dependencies);
            var headers  = new Dictionary <string, string>
            {
                { EventDataPropertyKeys.MessageType, RegisteredMessageType },
                { EventDataPropertyKeys.MessageTypeVersion, "1" }
            };
            var handler = resolver.GetHandler(headers, "test-message-0");

            Assert.NotNull(handler);
            Assert.IsType <TestMessageHandler>(handler);
            Assert.Equal("TestMessageHandler", handler.Name);
        }
        public void MessageHandlerResolverReturnsMessageHandlerInstanceForGivenMessageType()
        {
            var services = new ServiceCollection();
            var sut      = new MessageHandlerResolver(services);

            sut.SubcribeToMessage <AircraftTakenOff, AircraftTakenOffHandler>(BuildSubscriptionFilter <AircraftTakenOff>());
            sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(BuildSubscriptionFilter <AircraftLanded>());
            sut.Initialize();
            var handler = sut.Resolve(nameof(AircraftLanded));

            Assert.NotNull(handler);
            Assert.IsType <AircraftLandedHandler>(handler);

            var messageContext = new MessageContext <AircraftLanded>(new BinaryData("Hello world!"), new object(),
                                                                     new Mock <IMessageBus>().Object);

            typeof(AircraftLandedHandler).GetMethod("HandleAsync").Invoke(handler, new object[] { messageContext });
        }
예제 #9
0
 public ProcessManagerEventDispatcher(MessageHandlerResolver <Checkpoint> resolver)
 {
     _resolver = resolver;
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AodvRoutingProtocol"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public AodvRoutingProtocol(NetSimClient client)
     : base(client)
 {
     this.handlerResolver = new MessageHandlerResolver(this.GetType());
 }
        public void MessageHandlerResolverThrowsIfCannotFindMessageHandler()
        {
            var sut = new MessageHandlerResolver(new ServiceCollection());

            Assert.Throws <MessageHandlerNotFoundException>(() => sut.Resolve("UnknownMessage"));
        }
예제 #12
0
 public CommandDispatcher(MessageHandlerResolver <Checkpoint> resolver)
 {
     _resolver = resolver;
 }