public async Task HandleAsync( IMethodDiscoveryRequest request, IAppConnection sourceConnection, ITransportChannel sourceChannel) { Log.Info("Handling method discovery request {{{0}}} from {{{1}}}", request, sourceConnection); var appId = sourceConnection.Info.ApplicationId; IEnumerable <IProvidedMethod> matchingProvidedMethods = request.ConsumedMethod.HasValue ? _registryService.GetMatchingProvidedMethods(appId, request.ConsumedMethod.Value) : _registryService.GetMatchingProvidedMethods(appId); if (request.InputMessageId.HasValue) { matchingProvidedMethods = matchingProvidedMethods .Where(x => string.Equals(x.Method.InputMessage.Id, request.InputMessageId.Value)); } if (request.OutputMessageId.HasValue) { matchingProvidedMethods = matchingProvidedMethods .Where(x => string.Equals(x.Method.OutputMessage.Id, request.OutputMessageId.Value)); } IEnumerable <IDiscoveredMethod> discoveredMethods; if (request.DiscoveryMode == DiscoveryMode.Online) { var onlineConnections = _connectionTracker.GetOnlineConnections(); discoveredMethods = matchingProvidedMethods .Join( onlineConnections, x => x.ProvidedService.Application.Id, y => y.Info.ApplicationId, (method, connection) => (method, connection)) .Select(pm => Convert(pm.method, pm.connection.Id)); } else { discoveredMethods = matchingProvidedMethods .Select(pm => Convert(pm, Maybe <UniqueId> .Nothing)); } using (var response = _protocol.MessageFactory.CreateMethodDiscoveryResponse(discoveredMethods.ToList())) { Log.Info("Completed method discovery request {{{0}}} from {{{1}}}: {2}", request, sourceConnection, response); var serializedResponse = _protocol.Serializer.Serialize(response); try { await sourceChannel.Out .WriteAsync(new TransportMessageFrame(serializedResponse)) .ConfigureAwait(false); } catch { serializedResponse.Dispose(); throw; } } }
private IPooledBuffer Serialize(IMethodDiscoveryRequest msg, Nothing _) { using (var envelope = ClientToBrokerRequestEnvelope.Rent()) { var proto = MethodDiscoveryRequest.Rent(); proto.DiscoveryMode = ConvertToProto(msg.DiscoveryMode); proto.InputMessageId = msg.InputMessageId.ConvertToProto(); proto.ConsumedMethod = ConvertToProto(msg.ConsumedMethod); proto.OutputMessageId = msg.OutputMessageId.ConvertToProto(); envelope.MethodDiscoveryRequest = proto; return(envelope.Serialize()); } }
public T Handle(IMethodDiscoveryRequest message, TArgs args) { return(_handleMethodDiscoveryRequest(message, args)); }
public async Task HandleAsync( IMethodDiscoveryRequest request, IAppConnection sourceConnection, ITransportChannel sourceChannel) { Log.Info("Handling method discovery request {{{0}}} from {{{1}}}", request, sourceConnection); var appId = sourceConnection.Info.ApplicationId; IEnumerable <IProvidedMethod> matchingProvidedMethods = request.ConsumedMethod.HasValue ? _registryService.GetMatchingProvidedMethods(appId, request.ConsumedMethod.Value) : _registryService.GetMatchingProvidedMethods(appId); if (request.InputMessageId.HasValue) { matchingProvidedMethods = matchingProvidedMethods .Where(x => string.Equals(x.Method.InputMessage.Id, request.InputMessageId.Value)); } if (request.OutputMessageId.HasValue) { matchingProvidedMethods = matchingProvidedMethods .Where(x => string.Equals(x.Method.OutputMessage.Id, request.OutputMessageId.Value)); } IEnumerable <IDiscoveredMethod> discoveredMethods; bool online = request.DiscoveryMode == DiscoveryMode.Online; if (_contextLinkageManager.IsContextShouldBeConsidered(request.ContextLinkageOptions, sourceConnection)) { discoveredMethods = _contextLinkageManager.GetAppsInContexts(request.ContextLinkageOptions, sourceConnection, online) .Join(matchingProvidedMethods, x => x.AppId, y => y.ProvidedService.Application.Id, (connection, method) => (method, connection)) .Select(pm => Convert(pm.method, pm.connection.ConnectionId, new Maybe <UniqueId>(pm.connection.AppInstanceId))); } else { if (online) { var onlineConnections = _appLifecycleManager.GetOnlineConnections(); discoveredMethods = matchingProvidedMethods .Join( onlineConnections, x => x.ProvidedService.Application.Id, y => y.Info.ApplicationId, (method, connection) => (method, connection)) .Select(pm => Convert(pm.method, pm.connection.Id, pm.connection.Info.ApplicationInstanceId)); } else { var providedMethods = matchingProvidedMethods.ToArray(); var providerApps = providedMethods.Select(x => x.ProvidedService.Application.Id).Distinct().ToArray(); var availableProviderApps = FilterAvailableApps(providerApps); discoveredMethods = providedMethods .Join(availableProviderApps, x => x.ProvidedService.Application.Id, y => y, (x, y) => x) .Select(pm => Convert(pm, Maybe <UniqueId> .Nothing, Maybe <UniqueId> .Nothing)); } } using (var response = _protocol.MessageFactory.CreateMethodDiscoveryResponse(discoveredMethods.ToList())) { Log.Info("Completed method discovery request {{{0}}} from {{{1}}}: {2}", request, sourceConnection, response); var serializedResponse = _protocol.Serializer.Serialize(response); try { await sourceChannel.Out .WriteAsync(new TransportMessageFrame(serializedResponse)) .ConfigureAwait(false); } catch { serializedResponse.Dispose(); throw; } } }