コード例 #1
0
ファイル: CapabilityGraph.cs プロジェクト: skovsende/jasper
        private async Task <ServiceCapabilities> compile(HandlerGraph handlers, SerializationGraph serialization, IChannelGraph channels, ITransport[] transports, UriAliasLookup lookups, JasperRuntime runtime)
        {
            var validTransports = transports.Select(x => x.Protocol).ToArray();

            var capabilities = new ServiceCapabilities
            {
                ServiceName   = runtime.ServiceName,
                Subscriptions = determineSubscriptions(handlers, serialization),
                Published     = determinePublishedMessages(serialization, runtime, validTransports)
            };

            // Hokey.
            foreach (var subscription in capabilities.Subscriptions)
            {
                subscription.ServiceName = runtime.ServiceName;
            }

            foreach (var message in capabilities.Published)
            {
                message.ServiceName = runtime.ServiceName;
            }

            await capabilities.ApplyLookups(lookups);

            // Now, do some validation
            var missingDestination = capabilities.Subscriptions
                                     .Where(x => x.Destination == null)
                                     .Select(s => $"Could not determine an incoming receiver for message '{s.MessageType}'");


            var invalidTransport = capabilities.Subscriptions
                                   .Where(x => x.Destination != null && !validTransports.Contains(x.Destination.Scheme))
                                   .Select(x => $"Unknown transport '{x.Destination.Scheme}' for subscription to message '{x.MessageType}'");

            var missingHandlers = capabilities.Subscriptions
                                  .Where(x => !handlers.CanHandle(x.DotNetType))
                                  .Select(x => $"No handler for message '{x.MessageType}' referenced in a subscription");

            capabilities.Errors = missingDestination.Concat(invalidTransport).Concat(missingHandlers).ToArray();


            return(capabilities);
        }
コード例 #2
0
 public Task PersistCapabilities(ServiceCapabilities capabilities)
 {
     _subscriptions.RemoveAll(x => x.ServiceName == capabilities.ServiceName);
     _subscriptions.Add(capabilities);
     return(Task.CompletedTask);
 }