Beispiel #1
0
 /// <summary>
 /// 添加响应消息处理事件
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="builder"></param>
 /// <param name="responder"></param>
 /// <returns></returns>
 public static IEasyNetQConsumerBuilder AddResponder <TRequest, TResponse>(this IEasyNetQConsumerBuilder builder, Func <TRequest, TResponse> responder)
     where TRequest : class
     where TResponse : class
 {
     return(builder.AddResponder <TRequest, TResponse>(async(_, t) =>
     {
         var result = responder?.Invoke(t);
         return await Task.FromResult(result);
     }));
 }
Beispiel #2
0
 /// <summary>
 /// 添加响应消息处理事件
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <typeparam name="TResponder"></typeparam>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IEasyNetQConsumerBuilder AddResponder <TRequest, TResponse, TResponder>(this IEasyNetQConsumerBuilder builder)
     where TRequest : class
     where TResponse : class
     where TResponder : class, IEasyNetQResponder <TRequest, TResponse>
 {
     builder.Services.AddTransient <TResponder>();
     return(builder.AddResponder <TRequest, TResponse>(async(serviceProvicer, request) =>
     {
         var responder = serviceProvicer.GetRequiredService <TResponder>();
         return await responder?.RespondAsync(request);
     }));
 }