예제 #1
0
        public static IEnumerable <TransportMessage> GetMessages(this MySqlTransport transport)
        {
            var messages = new List <TransportMessage>();

            AsyncHelpers.RunSync(async() =>
            {
                while (true)
                {
                    using (var scope = new RebusTransactionScope())
                    {
                        var transportMessage = await transport.Receive(scope.TransactionContext, CancellationToken.None);
                        if (transportMessage == null)
                        {
                            break;
                        }

                        messages.Add(transportMessage);

                        await scope.CompleteAsync();
                    }
                }
            });

            return(messages);
        }
예제 #2
0
        public async Task ReceivesSentMessageWhenTransactionIsCommitted()
        {
            using (var scope = new RebusTransactionScope())
            {
                await _transport.Send(QueueName, RecognizableMessage(), AmbientTransactionContext.Current);

                await scope.CompleteAsync();
            }

            TransportMessage transportMessage;

            using (var scope = new RebusTransactionScope())
            {
                transportMessage = await _transport.Receive(AmbientTransactionContext.Current, _cancellationToken);

                await scope.CompleteAsync();
            }

            AssertMessageIsRecognized(transportMessage);
        }