Esempio n. 1
0
        public virtual IDisposable Respond(Func <byte[], Task <byte[]> > responder, Action <IResponderConfiguration> configure, string queueName)
        {
            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(byte[])), "byte[]");

            //var requestType = typeof(byte[]);

            var configuration = new ResponderConfiguration(connectionConfiguration.PrefetchCount);

            configure(configuration);

            //var queue = advancedBus.QueueDeclare(queueName);
            var queue = new Queue(queueName, false);

            return(advancedBus.Consume(queue
                                       , (message, requestMessage, messageReceivedInfo) => ExecuteResponder(responder, message, requestMessage, messageReceivedInfo)
                                       , c => c.WithPrefetchCount(configuration.PrefetchCount)
                                       ));
        }
Esempio n. 2
0
        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 requestType = typeof(TRequest);

            var configuration = new ResponderConfiguration(connectionConfiguration.PrefetchCount);

            configure(configuration);

            var routingKey = conventions.RpcRoutingKeyNamingConvention(requestType);
            var exchange   = advancedBus.ExchangeDeclare(conventions.RpcRequestExchangeNamingConvention(requestType), ExchangeType.Direct);
            var queue      = advancedBus.QueueDeclare(routingKey);

            advancedBus.Bind(exchange, queue, routingKey);

            return(advancedBus.Consume <TRequest>(queue, (requestMessage, messageReceivedInfo) => ExecuteResponder(responder, requestMessage),
                                                  c => c.WithPrefetchCount(configuration.PrefetchCount)));
        }