Example #1
0
        public async Task FromClientToChannelManuel()
        {
            TestMqServer server = new TestMqServer();

            server.Initialize(42305);
            server.Start();

            TmqClient client = new TmqClient();

            client.AutoAcknowledge  = false;
            client.MessageReceived += async(c, m) => { await client.SendAsync(m.CreateAcknowledge()); };

            await client.ConnectAsync("tmq://localhost:42305");

            Assert.True(client.IsConnected);

            Channel channel = server.Server.Channels.FirstOrDefault();

            Assert.NotNull(channel);
            ChannelQueue queue = channel.Queues.FirstOrDefault();

            Assert.NotNull(queue);
            queue.Options.RequestAcknowledge = true;

            //subscribe
            await client.Join(channel.Name, true);

            //push a message to the queue
            MemoryStream ms   = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"));
            bool         sent = await client.Push(channel.Name, queue.Id, ms, true);

            Assert.True(sent);
        }
Example #2
0
        public async Task WithoutAnyResponse()
        {
            TestMqServer server = new TestMqServer();

            server.Initialize(42601);
            server.Start();

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

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

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

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

            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.SendAsync(message);

            Assert.True(sent);
            await Task.Delay(1000);

            Assert.True(received);
        }
Example #3
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);
        }