コード例 #1
0
        public void TestAmqpFixtureRequestReply()
        {
            var amqpFixture = new AmqpFixture();

            //Setup Listener:
            bool MessageReceiver(Message message)
            {
                var subject = message.Properties?.Subject;

                if (subject != null && subject == "EchoMessage")
                {
                    var m = AmqpUtils.DeserializeMessage(message.Body);
                    amqpFixture.AmqpService.SendMessage(message.Properties.ReplyTo, message.Properties.Subject, m, message.Properties.CorrelationId);
                    return(true);
                }
                return(false);
            }

            var listener = amqpFixture.AmqpService.GetAmqpListener(MessageReceiver, "TestRequest");

            //RequestReply Message:
            var requestMsg = new
            {
                Key = "Test"
            };
            var response = amqpFixture.AmqpService.RequestReply(requestMsg, "EchoMessage", "TestRequest");

            Assert.NotNull(response);
            Assert.NotNull(response["Key"]);
            Assert.Equal("Test", response["Key"]);

            listener.Disconnect();
        }
コード例 #2
0
        public AmqpConnectorsTest(AmqpFixture fixture, ITestOutputHelper output) :
            base((ActorSystem)null, output)
        {
            _materializer = ActorMaterializer.Create(Sys);
            _serializer   = Sys.Serialization.FindSerializerForType(typeof(string));
            _fixture      = fixture;

            _address = new Address(_fixture.HostName, _fixture.AmqpPort, _fixture.UserName, _fixture.Password, scheme: "AMQP");
        }
コード例 #3
0
        public void TestAmqpFixtureSendAndReceive()
        {
            var amqpFixture = new AmqpFixture();
            var service     = amqpFixture.AmqpService;
            var num         = new Random((int)DateTime.Now.Ticks).Next(999999);

            bool MessageReceiver(Message message)
            {
                var body = AmqpUtils.DeserializeMessage(message.Body);

                Assert.Equal("Test", body["Name"]);
                Assert.Equal(true, body["Test"]);

                ReceivedMessageNum++;
                return(true);
            }

            var amqpListener = service.GetAmqpListener(MessageReceiver, $"TestQueue/{num}");

            Task.Delay(100);
            const int msgNum = 5;

            for (var i = 0; i < msgNum; i++)
            {
                var msg = new
                {
                    Name  = "Test",
                    Test  = true,
                    Value = i
                };

                service.SendMessage($"TestQueue/{num}", "Test", msg);
            }

            var watch = Stopwatch.StartNew();

            while (ReceivedMessageNum < msgNum && watch.ElapsedMilliseconds < 10000)
            {
                Thread.Sleep(100);
            }
            Assert.Equal(msgNum, ReceivedMessageNum);

            amqpListener.Disconnect();
        }
コード例 #4
0
ファイル: SimpleAmqpTest.cs プロジェクト: vkulikov/Alpakka
 public SimpleAmqpV1Test(AmqpFixture fixture, ITestOutputHelper output)
 {
     _output  = output;
     _fixture = fixture;
 }