Exemple #1
0
        /// <inheritdoc />
        public virtual IDisposable Consume(
            IQueue queue, MessageHandler onMessage, Action <IConsumerConfiguration> configure
            )
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(configure, "configure");

            if (disposed)
            {
                throw new EasyNetQException("This bus has been disposed");
            }

            var consumerConfiguration = new ConsumerConfiguration(configuration.PrefetchCount);

            configure(consumerConfiguration);
            var consumer = consumerFactory.CreateConsumer(queue, (body, properties, receivedInfo, cancellationToken) =>
            {
                var rawMessage = produceConsumeInterceptor.OnConsume(new ConsumedMessage(receivedInfo, properties, body));
                return(onMessage(rawMessage.Body, rawMessage.Properties, receivedInfo, cancellationToken));
            }, consumerConfiguration);

            consumer.StartConsuming();
            return(consumer);
        }
        public virtual IDisposable Consume(IQueue queue, Func <Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, Action <IConsumerConfiguration> configure)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(configure, "configure");

            if (disposed)
            {
                throw new EasyNetQException("This bus has been disposed");
            }
            var consumerConfiguration = new ConsumerConfiguration();

            configure(consumerConfiguration);
            var consumer = consumerFactory.CreateConsumer(queue, onMessage, connection, consumerConfiguration);

            return(consumer.StartConsuming());
        }
Exemple #3
0
        // ---------------------------------- consume --------------------------------------

        public IDisposable Consume(IEnumerable <QueueConsumerPair> queueConumserPairs, Action <IConsumerConfiguration> configure)
        {
            Preconditions.CheckNotNull(queueConumserPairs, nameof(queueConumserPairs));
            Preconditions.CheckNotNull(configure, "configure");

            if (disposed)
            {
                throw new EasyNetQException("This bus has been disposed");
            }

            var queueOnMessages = queueConumserPairs.Select(x =>
            {
                var onMessage = x.OnMessage;
                if (onMessage == null)
                {
                    var handlerCollection = handlerCollectionFactory.CreateHandlerCollection();
                    x.AddHandlers(handlerCollection);

                    onMessage = (body, properties, messageRecivedInfo) =>
                    {
                        var deserializedMessage = messageSerializationStrategy.DeserializeMessage(properties, body);
                        var handler             = handlerCollection.GetHandler(deserializedMessage.MessageType);
                        return(handler(deserializedMessage, messageRecivedInfo));
                    };
                }

                return(Tuple.Create(x.Queue, onMessage));
            }).ToList();


            var consumerConfiguration = new ConsumerConfiguration(connectionConfiguration.PrefetchCount);

            configure(consumerConfiguration);
            var consumer = consumerFactory.CreateConsumer(queueOnMessages, connection, consumerConfiguration);

            return(consumer.StartConsuming());
        }