Exemplo n.º 1
0
        /// <summary>
        /// Receives the next message from the queue identified by the configured <see cref="AbstractRebusTransport.Address"/>, returning null if none was available
        /// </summary>
        public override async Task <TransportMessage> Receive(ITransactionContext context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (_inputQueueAddress == null)
            {
                throw new InvalidOperationException("This in-mem transport is initialized without an input queue, hence it is not possible to receive anything!");
            }

            var nextMessage = _network.GetNextOrNull(_inputQueueAddress);

            if (nextMessage == null)
            {
                return(null);
            }

            context.OnAborted(() =>
            {
                _network.Deliver(_inputQueueAddress, nextMessage, alwaysQuiet: true);
            });

            return(nextMessage.ToTransportMessage());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receives the next message from the queue identified by the configured <see cref="Address"/>, returning null if none was available
        /// </summary>
        public async Task <TransportMessage> Receive(ITransactionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var nextMessage = _network.GetNextOrNull(_inputQueueAddress);

            if (nextMessage != null)
            {
                context.OnAborted(() =>
                {
                    _network.Deliver(_inputQueueAddress, nextMessage, alwaysQuiet: true);
                });

                return(nextMessage.ToTransportMessage());
            }

            await Task.Delay(20);

            return(null);
        }