public virtual IDisposable Respond <TRequest, TResponse>(Func <TRequest, Task <TResponse> > responder, Action <IResponderConfiguration> configure) where TRequest : class where TResponse : class { Preconditions.CheckNotNull(responder, "responder"); Preconditions.CheckNotNull(configure, "configure"); // We're explicitly validating TResponse here because the type won't be used directly. // It'll only be used when executing a successful responder, which will silently fail if TResponse serialized length exceeds the limit. Preconditions.CheckShortString(typeNameSerializer.Serialize(typeof(TResponse)), "TResponse"); var requestType = typeof(TRequest); var configuration = new ResponderConfiguration(connectionConfiguration.PrefetchCount); configure(configuration); var routingKey = configuration.QueueName ?? conventions.RpcRoutingKeyNamingConvention(requestType); var queue = advancedBus.QueueDeclare(routingKey); var exchange = DeclareAndBindRpcExchange( conventions.RpcRequestExchangeNamingConvention(requestType), queue, routingKey); return(advancedBus.Consume <TRequest>(queue, (requestMessage, messageReceivedInfo) => ExecuteResponder(responder, requestMessage), c => c.WithPrefetchCount(configuration.PrefetchCount))); }
public virtual IDisposable Respond <TRequest, TResponse>(Func <TRequest, Task <TResponse> > responder, Action <IResponderConfiguration> configure) where TRequest : class where TResponse : class { Preconditions.CheckNotNull(responder, "responder"); Preconditions.CheckNotNull(configure, "configure"); // We're explicitely validating TResponse here because the type won't be used directly. // It'll only be used when executing a successful responder, which will silently fail if TResponse serialized length exceeds the limit. Preconditions.CheckShortString(typeNameSerializer.Serialize(typeof(TResponse)), "TResponse"); var configuration = new ResponderConfiguration(connectionConfiguration.PrefetchCount); configure(configuration); var routingKey = conventions.RpcRoutingKeyNamingConvention(typeof(TRequest)); var exchange = advancedBus.ExchangeDeclare(conventions.RpcExchangeNamingConvention(), ExchangeType.Direct); var queue = advancedBus.QueueDeclare(routingKey, durable: configuration.Durable); advancedBus.Bind(exchange, queue, routingKey); return(advancedBus.Consume <TRequest>(queue, (requestMessage, messageRecievedInfo) => ExecuteResponder(responder, requestMessage), c => c.WithPrefetchCount(configuration.PrefetchCount).WithRecoveryAction(() => { //just in case we loose exchange and/or queue in case of owning cluster node went down, and they are nondurable var exc = advancedBus.ExchangeDeclare(conventions.RpcExchangeNamingConvention(), ExchangeType.Direct); var q = advancedBus.QueueDeclare(routingKey, durable: configuration.Durable); advancedBus.Bind(exc, q, routingKey); }))); }
public IDisposable Respond <TRequest, TResponse>(Func <TRequest, Task <TResponse> > responder, Action <IResponderConfiguration> configure) where TRequest : class where TResponse : class { Preconditions.CheckNotNull(responder, "responder"); Preconditions.CheckNotNull(configure, "configure"); var configuration = new ResponderConfiguration(connectionConfiguration.PrefetchCount); configure(configuration); var routingKey = conventions.RpcRoutingKeyNamingConvention(typeof(TRequest)); var exchange = advancedBus.ExchangeDeclare(conventions.RpcExchangeNamingConvention(), ExchangeType.Direct); var queue = advancedBus.QueueDeclare(routingKey); advancedBus.Bind(exchange, queue, routingKey); return(advancedBus.Consume <TRequest>(queue, (requestMessage, messageRecievedInfo) => ExecuteResponder(responder, requestMessage), c => c.WithPrefetchCount(configuration.PrefetchCount))); }