Ejemplo n.º 1
0
        public Task RegisterRpcHandlerAsync(IRequestMatcher pattern, Func <Message, CancellationToken, Task <Message> > handler, RouteExecution execution = RouteExecution.Synchronous, RouteMode mode = RouteMode.Capture, CancellationToken cancellationToken = default)
        {
            return(_registration.RegisterRpcHandlerAsync(
                       pattern,
                       async(message, handlerToken) =>
            {
                Trace.Current = ExtractTracing(message);

                var trace = Trace.Current;
                trace.Record(Annotations.ServerRecv());
                trace.Record(Annotations.ServiceName(_serviceName));
                trace.Record(Annotations.Rpc("TODO"));
                try
                {
                    var response = await handler(message, handlerToken);
                    trace.Record(Annotations.ServerSend());
                    return response;
                }
                catch (Exception ex)
                {
                    trace.Record(Annotations.Tag("error", ex.Message));
                    trace.Record(Annotations.LocalOperationStop());

                    throw;
                }
            },
                       execution,
                       mode,
                       cancellationToken));
        }
 public Task RegisterRpcHandlerAsync(IRequestMatcher pattern, Func <Message, CancellationToken, Task <Message> > handler, RouteExecution execution = RouteExecution.Synchronous, RouteMode mode = RouteMode.Capture, CancellationToken cancellationToken = default)
 {
     return(_policy.ExecuteAsync((_, registerPolicyToken) => _registration.RegisterRpcHandlerAsync(
                                     pattern,
                                     (message, handlerToken) => _policy.AsAsyncPolicy <Message>().ExecuteAsync((__, handlerPolicyToken) => handler(message, handlerPolicyToken), new Context(), handlerToken),
                                     execution,
                                     mode,
                                     registerPolicyToken
                                     ), new Context(), cancellationToken));
 }
Ejemplo n.º 3
0
        private static async Task RegisterRouteAsync(IRoutingRegistration model, object plugin, RouteMetadata route)
        {
            var pattern = route.Route;

            if (RouteHandlerFactory.IsRpc(route))
            {
                var handler = RouteHandlerFactory.BuildRpcHandler(plugin, route);
                await model.RegisterRpcHandlerAsync(pattern, new Func <Message, CancellationToken, Task <Message> >(handler));
            }
            else
            {
                var handler = RouteHandlerFactory.BuildBusHandler(plugin, route);
                await model.RegisterBusHandlerAsync(pattern, new Func <Message, CancellationToken, Task>(handler));
            }
        }