Beispiel #1
0
        public async Task SingleQueueSingleDirect()
        {
            TestHorseMq server = new TestHorseMq();
            await server.Initialize();

            int port = server.Start(300, 300);

            Router router = new Router(server.Server, "router", RouteMethod.Distribute);

            router.AddBinding(new QueueBinding("qbind-1", "push-a", 0, BindingInteraction.None));
            router.AddBinding(new DirectBinding("dbind-1", "client-1", 0, BindingInteraction.None));
            server.Server.AddRouter(router);

            HorseClient producer = new HorseClient();
            await producer.ConnectAsync("hmq://localhost:" + port);

            Assert.True(producer.IsConnected);

            bool        client1Received = false;
            HorseClient client1         = new HorseClient();

            client1.ClientId = "client-1";
            await client1.ConnectAsync("hmq://localhost:" + port);

            client1.MessageReceived += (c, m) => client1Received = true;
            Assert.True(client1.IsConnected);

            HorseResult result = await producer.Routers.Publish("router", "Hello, World!", true);

            Assert.Equal(HorseResultCode.Ok, result.Code);
            await Task.Delay(500);

            HorseQueue queue1 = server.Server.FindQueue("push-a");

            Assert.Equal(1, queue1.MessageCount());
            Assert.True(client1Received);
        }