Example #1
0
        public IEnumerable <ChannelNode> FindSubscribingChannelsFor(Type inputType)
        {
            var staticNodes = _graph.Where(x => x.Publishes(inputType));

            var subscriptions = _subscriptions.Where(x => x.Matches(inputType));
            var dynamicNodes  = subscriptions.Select(x => findDestination(x.Receiver));

            return(staticNodes.Union(dynamicNodes).Distinct());
        }
Example #2
0
        public void Start(IHandlerPipeline pipeline, ChannelGraph channels)
        {
            foreach (var node in channels.IncomingChannelsFor(Protocol))
            {
                var receiver = new Receiver(pipeline, channels, node);
                ReceiveAt(node, receiver);
            }

            var replyNode     = new ChannelNode(ReplyChannel.Address);
            var replyReceiver = new Receiver(pipeline, channels, replyNode);

            ReceiveAt(replyNode, replyReceiver);

            channels.Where(x => x.Uri.Scheme == Protocol).Each(x => {
                x.ReplyUri    = ReplyChannel.Address;
                x.Destination = x.Uri;
            });
        }
Example #3
0
        // virtual for testing
        public virtual void OpenChannels()
        {
            try
            {
                _transports.Each(x => x.OpenChannels(_graph));

                var missingChannels = _graph.Where(x => x.Channel == null);
                if (missingChannels.Any())
                {
                    throw new InvalidOrMissingTransportException(_transports, missingChannels);
                }
            }
            catch (InvalidOrMissingTransportException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new InvalidOrMissingTransportException(e, _transports, _graph);
            }
        }
Example #4
0
        public void Start(IHandlerPipeline pipeline, ChannelGraph channels)
        {
            var nodes = channels.Where(x => x.Uri.Scheme == Protocol).ToArray();

            if (!nodes.Any())
            {
                return;
            }

            var replyNode = nodes.FirstOrDefault(x => x.Incoming) ??
                            channels.AddChannelIfMissing(_settings.DefaultReplyUri);

            replyNode.Incoming = true;
            _replyUri          = replyNode.Uri.ToLightningUri().Address;


            var groups = nodes.GroupBy(x => x.Uri.Port);

            foreach (var group in groups)
            {
                // TODO -- need to worry about persistence or not here
                var queue = _queues.GetOrAdd(group.Key, key => new LightningQueue(group.Key, true, _settings));
                queue.Start(channels, group);

                foreach (var node in group)
                {
                    var lightningUri = node.Uri.ToLightningUri();
                    node.Destination = lightningUri.Address;
                    node.ReplyUri    = _replyUri;
                    node.Sender      = new QueueSender(node.Destination, queue, node.Destination.ToLightningUri().QueueName);

                    if (node.Incoming)
                    {
                        queue.ListenForMessages(lightningUri.QueueName, new Receiver(pipeline, channels, node));
                    }
                }
            }
        }