예제 #1
0
        /// <summary>
        /// Entry point for routing tag based data portal operations.
        /// </summary>
        /// <param name="operation">Name of the data portal operation to perform</param>
        /// <param name="routingTag">Routing tag from caller</param>
        /// <param name="request">Request message</param>
        protected virtual async Task <ResponseMessage> RouteMessage(string operation, string routingTag, RequestMessage request)
        {
            if (RoutingTagUrls.TryGetValue(routingTag, out string route) && route != "localhost")
            {
                var options = new GrpcProxyOptions {
                    DataPortalUrl = $"{route}?operation={operation}"
                };
                var channel       = ApplicationContext.CreateInstanceDI <global::Grpc.Net.Client.GrpcChannel>();
                var proxy         = new GrpcProxy(ApplicationContext, channel, options);
                var clientRequest = new RequestMessage
                {
                    Body      = request.Body,
                    Operation = operation
                };
                var clientResponse = await proxy.RouteMessage(clientRequest);

                return(new ResponseMessage {
                    Body = clientResponse.Body
                });
            }
            else
            {
                return(await InvokePortal(operation, request.Body).ConfigureAwait(false));
            }
        }
예제 #2
0
 /// <summary>
 /// Creates an instance of the object, initializing
 /// it to use the supplied GrpcChannel object and URL.
 /// </summary>
 /// <param name="applicationContext"></param>
 /// <param name="channel">GrpcChannel instance</param>
 /// <param name="options">Proxy options</param>
 public GrpcProxy(ApplicationContext applicationContext, GrpcChannel channel, GrpcProxyOptions options)
     : base(applicationContext)
 {
     _channel      = channel;
     DataPortalUrl = options.DataPortalUrl;
 }