コード例 #1
0
        public void Low_Level_Transport_Test()
        {
            var clientManager = new PooledRedisClientManager();

            var messageMapper = new MessageMapper();

            messageMapper.Initialize(new[] { typeof(TestMessage), typeof(TestEvent) });

            var sendAddress = Address.Parse("lowlevel@localhost");

            var queue = new RedisQueue(new JsonSerializer(), clientManager, new QueueKeyNameProvider(true));

            queue.Init(sendAddress, true);

            var nsbSerializer = new JsonMessageSerializer(messageMapper);

            var message = new TestMessage()
            {
                Name = "Bob"
            };

            var transportMessage = new TransportMessage()
            {
                MessageIntent = MessageIntentEnum.Send
            };

            using (var ms = new MemoryStream())
            {
                nsbSerializer.Serialize(new [] { message }, ms);
                transportMessage.Body = ms.ToArray();
            }

            using (var tran = new TransactionScope())
            {
                for (int x = 0; x < 2; x++)
                {
                    queue.Send(transportMessage, sendAddress);
                }
                tran.Complete();
            }

            for (int x = 0; x < 2; x++)
            {
                if (queue.HasMessage())
                {
                    using (var tran = new TransactionScope())
                    {
                        queue.Receive();
                        tran.Complete();
                    }
                }
            }
        }