public static IMessageForwardingConfiguration Configuration()
        {
            var section       = ConfigurationSectionProvider.Open <MessageForwardingSection>("shuttle", "messageForwarding");
            var configuration = new MessageForwardingConfiguration();

            if (section?.ForwardingRoutes == null)
            {
                return(configuration);
            }

            var factory = new MessageRouteSpecificationFactory();

            foreach (MessageRouteElement mapElement in section.ForwardingRoutes)
            {
                var map = configuration.MessageRoutes.Find(mapElement.Uri);

                if (map == null)
                {
                    map = new MessageRoute(new Uri(mapElement.Uri));

                    configuration.MessageRoutes.Add(map);
                }

                foreach (SpecificationElement specificationElement in mapElement)
                {
                    map.AddSpecification(factory.Create(specificationElement.Name, specificationElement.Value));
                }
            }

            return(configuration);
        }
Exemple #2
0
 private void tryToMatch(PublishedMessage sender, Subscription receiver)
 {
     if (MessageRoute.TryToRoute(sender, receiver, out MessageRoute route,
                                 out PublisherSubscriberMismatch mismatch))
     {
         _routes.Add(route);
     }
        public void Apply(IServiceBusConfiguration configuration)
        {
            if (ServiceBusConfiguration.ServiceBusSection == null ||
                ServiceBusConfiguration.ServiceBusSection.MessageRoutes == null)
            {
                return;
            }

            var specificationFactory = new MessageRouteSpecificationFactory();
            var provider             = configuration.MessageRouteProvider;

            foreach (MessageRouteElement mapElement in ServiceBusConfiguration.ServiceBusSection.MessageRoutes)
            {
                var messageRoute = provider.Find(mapElement.Uri);

                if (messageRoute == null)
                {
                    messageRoute = new MessageRoute(configuration.QueueManager.GetQueue(mapElement.Uri));

                    provider.Add(messageRoute);
                }

                foreach (SpecificationElement specificationElement in mapElement)
                {
                    messageRoute.AddSpecification(specificationFactory.Create(specificationElement.Name, specificationElement.Value));
                }
            }
        }
Exemple #4
0
        private async Task <Envelope> sendEnvelope(Envelope envelope, MessageRoute route, IMessageCallback callback)
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            ITransport transport = null;

            if (_transports.TryGetValue(route.Destination.Scheme, out transport))
            {
                var sending = route.CloneForSending(envelope);

                var channel = _channels.TryGetChannel(route.Destination);

                if (channel != null)
                {
                    await sendToStaticChannel(callback, sending, channel);
                }
                else
                {
                    await sendToDynamicChannel(route.Destination, callback, sending, transport);
                }

                Logger.Sent(sending);

                return(sending);
            }
            else
            {
                throw new InvalidOperationException($"Unrecognized transport scheme '{route.Destination.Scheme}'");
            }
        }
        public void Apply(IServiceBusConfiguration configuration)
        {
            if (ServiceBusConfiguration.ServiceBusSection == null ||
                ServiceBusConfiguration.ServiceBusSection.MessageRoutes == null)
            {
                return;
            }

            var specificationFactory = new MessageRouteSpecificationFactory();
            var provider = configuration.MessageRouteProvider;

            foreach (MessageRouteElement mapElement in ServiceBusConfiguration.ServiceBusSection.MessageRoutes)
            {
                var messageRoute = provider.Find(mapElement.Uri);

                if (messageRoute == null)
                {
                    messageRoute = new MessageRoute(configuration.QueueManager.GetQueue(mapElement.Uri));

                    provider.Add(messageRoute);
                }

                foreach (SpecificationElement specificationElement in mapElement)
                {
                    messageRoute.AddSpecification(specificationFactory.Create(specificationElement.Name, specificationElement.Value));
                }
            }
        }
        private void routedTo(Envelope envelope, params string[] destinations)
        {
            var outgoing = destinations.Select(x => new Envelope
            {
                Destination = x.ToUri(),
                Message     = envelope?.Message ?? new Message1(),
            }).ToArray();

            var props = typeof(Envelope).GetProperties(BindingFlags.Instance | BindingFlags.NonPublic);
            var prop  = props
                        .FirstOrDefault(x => x.PropertyType == typeof(MessageRoute));

            foreach (var env in outgoing)
            {
                var route = new MessageRoute(typeof(Message1), env?.Destination ?? destinations.First().ToUri(), "application/json");
                route.Channel = Substitute.For <IChannel>();
                route.Channel.IsDurable.Returns(true);

                prop.SetValue(env, route);
            }

            if (envelope == null)
            {
                theMessagingRoot.Router.Route(Arg.Any <Envelope>()).Returns(outgoing);
            }
            else
            {
                theMessagingRoot.Router.Route(envelope).Returns(outgoing);
            }
        }
        internal void Initialize(IServiceBus bus)
        {
            var section = ConfigurationSectionProvider.Open <MessageForwardingSection>("shuttle", "messageForwarding");

            if (section == null || section.ForwardingRoutes == null)
            {
                return;
            }

            var factory = new MessageRouteSpecificationFactory();

            foreach (MessageRouteElement mapElement in section.ForwardingRoutes)
            {
                var map = _messageRoutes.Find(mapElement.Uri);

                if (map == null)
                {
                    map = new MessageRoute(bus.Configuration.QueueManager.GetQueue(mapElement.Uri));

                    _messageRoutes.Add(map);
                }

                foreach (SpecificationElement specificationElement in mapElement)
                {
                    map.AddSpecification(factory.Create(specificationElement.Name, specificationElement.Value));
                }
            }
        }
        public void Should_be_able_to_create_a_new_route()
        {
            IMessageRoute map = new MessageRoute(new MemoryQueue(new Uri("memory://.")));

            map.AddSpecification(new RegexMessageRouteSpecification("simple"));

            Assert.IsFalse(map.IsSatisfiedBy(new OtherNamespaceCommand()));
            Assert.IsTrue(map.IsSatisfiedBy(new SimpleCommand()));
        }
        public void Should_be_able_to_create_a_new_route()
        {
            var map = new MessageRoute(new Uri("route://"));

            map.AddSpecification(new RegexMessageRouteSpecification("simple"));

            Assert.IsFalse(map.IsSatisfiedBy(new OtherNamespaceCommand().GetType().FullName));
            Assert.IsTrue(map.IsSatisfiedBy(new SimpleCommand().GetType().FullName));
        }
        public void Should_be_able_to_create_new_routes()
        {
            var route  = new MessageRoute(new Uri("route://"));
            var routes = new MessageRouteCollection();

            route.AddSpecification(new RegexMessageRouteSpecification("simple"));

            routes.Add(route);

            Assert.AreSame(route.Uri, routes.FindAll(new SimpleCommand().GetType().FullName)[0].Uri);
        }
Exemple #11
0
        public void Should_be_able_to_create_new_routes()
        {
            var queue  = new MemoryQueue(new Uri("memory://."));
            var route  = new MessageRoute(queue);
            var routes = new MessageRouteCollection();

            route.AddSpecification(new RegexMessageRouteSpecification("simple"));

            routes.Add(route);

            Assert.AreSame(queue, routes.FindAll(new SimpleCommand())[0].Queue);
        }
        public void Should_be_able_to_create_new_routes()
        {
            var queue  = new Mock <IQueue>();
            var route  = new MessageRoute(queue.Object);
            var routes = new MessageRouteCollection();

            queue.Setup(m => m.Uri).Returns(new Uri("uri://somewhere"));

            route.AddSpecification(new RegexMessageRouteSpecification("simple"));

            routes.Add(route);

            Assert.AreSame(queue.Object, routes.FindAll(new SimpleCommand().GetType().FullName)[0].Queue);
        }
        public void Should_be_able_to_create_new_routes()
        {
            var queue = new Mock<IQueue>();
            var route = new MessageRoute(queue.Object);
            var routes = new MessageRouteCollection();

            queue.Setup(m => m.Uri).Returns(new Uri("uri://somewhere"));

            route.AddSpecification(new RegexMessageRouteSpecification("simple"));

            routes.Add(route);

            Assert.AreSame(queue.Object, routes.FindAll(new SimpleCommand().GetType().FullName)[0].Queue);
        }
        public async Task MessagingProcessor(IMessageProcessor processor)
        {
            var messageHandler = await messageQueueIn.GetMessage <PlatformMessage>();

            MessageRoute messageRoute = new MessageRoute(pricipal);

            this.platformMessage = messageHandler.MessageObject;
            await processor.ProcessAsync(platformMessage);

            messageRoute.Complete();
            await messageHandler.Complete();

            this.platformMessage.Routes.Add(messageRoute);
            await messageQueueQut.SendQueueMessage(this.platformMessage);
        }
        public void use_json_if_that_is_the_only_match()
        {
            var published = new PublishedMessage(typeof(Message1))
            {
                ContentTypes = new string[] { "application/json", "app/v2", "app/v3" },
                Transports   = new string[] { "loopback" }
            };

            var subscription = new Subscription(typeof(Message1), "loopback://one".ToUri());

            subscription.Accept = new string[] { "application/json", "app/v4", "app/v5" };

            MessageRoute.TryToRoute(published, subscription, out MessageRoute route, out PublisherSubscriberMismatch mismatch)
            .ShouldBeTrue();

            route.ContentType.ShouldBe("application/json");
        }
        private void BuildRoutes()
        {
            foreach (ServerModule module in _moduleProvider.Modules)
            {
                List <MethodInfo> methods = module
                                            .GetType()
                                            .GetMethods()
                                            .Where(m => m.GetCustomAttributes(typeof(MessageHandlerAttribute)).Any())
                                            .ToList();

                foreach (MethodInfo method in methods)
                {
                    if (method.GetCustomAttribute(typeof(MessageHandlerAttribute)) is MessageHandlerAttribute attribute)
                    {
                        Func <Type[], Type> getType;
                        bool        isAction = method.ReturnType == typeof(void);
                        List <Type> types    = new List <Type>
                        {
                            attribute.MessageType
                        };

                        if (isAction)
                        {
                            getType = Expression.GetActionType;
                        }
                        else
                        {
                            getType = Expression.GetFuncType;
                            types.Add(method.ReturnType);
                        }

                        MessageRoute route = new MessageRoute
                        {
                            Attribute = attribute,
                            Module    = module,
                            Method    = Delegate.CreateDelegate(getType(types.ToArray()), module, method)
                        };

                        _routes.Add(route);
                    }
                }
            }

            _logger.LogInformation("Routes was built");
        }
        public void mismatch_with_no_matching_content_types_and_transport()
        {
            var published = new PublishedMessage(typeof(Message1))
            {
                ContentTypes = new string[] { "one", "two" },
                Transports   = new string[] { "jasper" }
            };

            var subscription = new Subscription(typeof(Message1), "fake://one".ToUri());

            subscription.Accept = new string[] { "three" };

            MessageRoute.TryToRoute(published, subscription, out MessageRoute route, out PublisherSubscriberMismatch mismatch)
            .ShouldBeFalse();

            mismatch.IncompatibleContentTypes.ShouldBeTrue();
            mismatch.IncompatibleTransports.ShouldBeTrue();
        }
        public void mismatch_with_no_matching_content_types()
        {
            var published = new PublishedMessage(typeof(Message1))
            {
                ContentTypes = new string[] { "one", "two" }
            };

            var subscription = new Subscription(typeof(Message1), "loopback://one".ToUri());

            subscription.Accept = new string[] { "three" };

            MessageRoute.TryToRoute(published, subscription, out MessageRoute route, out PublisherSubscriberMismatch mismatch)
            .ShouldBeFalse();

            mismatch.IncompatibleContentTypes.ShouldBeTrue();
            mismatch.PublishedContentTypes.ShouldBe(published.ContentTypes);
            mismatch.SubscriberContentTypes.ShouldBe(subscription.Accept);
        }
        private async Task <Envelope> sendEnvelope(Envelope envelope, MessageRoute route)
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }


            if (!envelope.RequiresLocalReply)
            {
                envelope.ReplyUri = envelope.ReplyUri ?? _channels.SystemReplyUri;
            }

            var sending = await route.Send(envelope);

            Logger.Sent(sending);

            return(sending);
        }
Exemple #20
0
        public void TwoMessageRoutesAreNotEqual_IfTheirReceiverPropertiesAreNotEqual()
        {
            var first = new MessageRoute
            {
                Message  = MessageIdentifier.Create <SimpleMessage>(),
                Receiver = ReceiverIdentities.CreateForActor()
            };
            var second = new MessageRoute
            {
                Message  = MessageIdentifier.Create <SimpleMessage>(),
                Receiver = ReceiverIdentities.CreateForActor()
            };

            //
            Assert.NotEqual(first, second);
            Assert.False(first.Equals(second));
            Assert.False(first.Equals((object)second));
            Assert.True(first != second);
            Assert.False(first == second);
        }
Exemple #21
0
 private void OnPacketCompleted(IClient client, object message)
 {
     MessageRoute.Invoke(message, this);
 }
Exemple #22
0
 private void OnError(IClient client, Exception e, string message)
 {
     MessageRoute.Invoke(e, this);
 }