Esempio n. 1
0
        public async Task WithAcknowledge()
        {
            TestMqServer server = new TestMqServer();

            server.Initialize(42602);
            server.Start();

            TmqClient client1 = new TmqClient();
            TmqClient client2 = new TmqClient();

            client1.ClientId        = "client-1";
            client2.ClientId        = "client-2";
            client2.AutoAcknowledge = true;

            await client1.ConnectAsync("tmq://localhost:42602");

            await client2.ConnectAsync("tmq://localhost:42602");

            Assert.True(client1.IsConnected);
            Assert.True(client2.IsConnected);

            bool received = false;

            client2.MessageReceived += (c, m) => received = m.Source == "client-1";

            TmqMessage message = new TmqMessage(MessageType.Client, "client-2");

            message.SetStringContent("Hello, World!");

            bool sent = await client1.SendWithAcknowledge(message);

            Assert.True(sent);
            Assert.True(received);
        }
Esempio n. 2
0
        public async Task FromClientToClientManuel()
        {
            TestMqServer server = new TestMqServer();

            server.Initialize(42302);
            server.Start();

            server.Server.Server.Options.PingInterval   = 300;
            server.Server.Server.Options.RequestTimeout = 300;
            await Task.Delay(250);

            TmqClient client1 = new TmqClient();
            TmqClient client2 = new TmqClient();

            client1.ClientId         = "client-1";
            client2.ClientId         = "client-2";
            client2.AutoAcknowledge  = false;
            client2.MessageReceived += async(c, m) =>
            {
                if (m.AcknowledgeRequired)
                {
                    await client2.SendAsync(m.CreateAcknowledge());
                }
            };

            await client1.ConnectAsync("tmq://localhost:42302");

            await client2.ConnectAsync("tmq://localhost:42302");

            Assert.True(client1.IsConnected);
            Assert.True(client2.IsConnected);

            TmqMessage message = new TmqMessage();

            message.HighPriority = true;
            message.Type         = MessageType.Client;
            message.SetTarget(client2.ClientId);
            message.SetStringContent("Hello, World!");

            bool acknowledge = await client1.SendWithAcknowledge(message);

            Assert.True(acknowledge);
        }
Esempio n. 3
0
        public async Task FromClientToClientTimeout()
        {
            TestMqServer server = new TestMqServer();

            server.Initialize(42393);
            server.Start(15, 15);

            server.Server.Server.Options.PingInterval   = 300;
            server.Server.Server.Options.RequestTimeout = 300;
            await Task.Delay(250);

            TmqClient client1 = new TmqClient();
            TmqClient client2 = new TmqClient();

            client1.ClientId           = "client-1";
            client2.ClientId           = "client-2";
            client1.AcknowledgeTimeout = TimeSpan.FromSeconds(5);
            client2.AutoAcknowledge    = false;

            await client1.ConnectAsync("tmq://localhost:42393");

            await client2.ConnectAsync("tmq://localhost:42393");

            Assert.True(client1.IsConnected);
            Assert.True(client2.IsConnected);

            TmqMessage message = new TmqMessage();

            message.HighPriority = true;
            message.Type         = MessageType.Client;
            message.SetTarget(client2.ClientId);
            message.SetStringContent("Hello, World!");

            bool acknowledge = await client1.SendWithAcknowledge(message);

            Assert.False(acknowledge);
        }