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