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); }
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); }
public async Task FromClientToChannelTimeout() { TestMqServer server = new TestMqServer(); server.Initialize(42306); server.Start(); TmqClient client = new TmqClient(); client.AutoAcknowledge = false; client.AcknowledgeTimeout = TimeSpan.FromSeconds(3); await client.ConnectAsync("tmq://localhost:42306"); 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.False(sent); }
public async Task CreateWithProperties() { TestMqServer server = new TestMqServer(); server.Initialize(41206); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:41206"); Assert.True(client.IsConnected); TmqResponseCode created = await client.CreateChannel("new-channel", o => { o.AllowMultipleQueues = false; o.SendOnlyFirstAcquirer = true; o.AcknowledgeTimeout = TimeSpan.FromSeconds(33); o.Status = MessagingQueueStatus.Pull; }); Assert.Equal(TmqResponseCode.Ok, created); Channel found = server.Server.FindChannel("new-channel"); Assert.NotNull(found); Assert.False(found.Options.AllowMultipleQueues); Assert.True(found.Options.SendOnlyFirstAcquirer); }
public async Task ClientReadsMessageFromQueue() { TestMqServer server = new TestMqServer(); server.Initialize(42801); server.Start(); bool received = false; MessageReader reader = MessageReader.JsonReader(); reader.On <MessageA>("ch-1", MessageA.ContentType, a => { received = true; }); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42801"); Assert.True(client.IsConnected); reader.Attach(client); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(1000); MessageA m = new MessageA("Msg-A"); MemoryStream ms = new MemoryStream(); await System.Text.Json.JsonSerializer.SerializeAsync(ms, m); bool sent = await client.Push("ch-1", MessageA.ContentType, ms, false); Assert.True(sent); await Task.Delay(500); Assert.True(received); }
public async Task SendToOnlineConsumers(int onlineConsumerCount) { int port = 47100 + onlineConsumerCount; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); TmqClient producer = new TmqClient(); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); int msgReceived = 0; for (int i = 0; i < onlineConsumerCount; i++) { TmqClient consumer = new TmqClient(); consumer.ClientId = "consumer-" + i; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); consumer.MessageReceived += (c, m) => Interlocked.Increment(ref msgReceived); TmqResponseCode joined = await consumer.Join("ch-route", true); Assert.Equal(TmqResponseCode.Ok, joined); } await producer.Push("ch-route", MessageA.ContentType, "Hello, World!", false); await Task.Delay(1500); Assert.Equal(onlineConsumerCount, msgReceived); }
public async Task SendToOfflineConsumers() { int port = 47117; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); TmqClient producer = new TmqClient(); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); await producer.Push("ch-route", MessageA.ContentType, "Hello, World!", false); await Task.Delay(700); bool msgReceived = false; TmqClient consumer = new TmqClient(); consumer.ClientId = "consumer"; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); consumer.MessageReceived += (c, m) => msgReceived = true; TmqResponseCode joined = await consumer.Join("ch-route", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(800); Assert.False(msgReceived); }
public async Task CreateWithProperties() { TestMqServer server = new TestMqServer(); server.Initialize(41206); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:41206"); Assert.True(client.IsConnected); TmqResponseCode created = await client.CreateQueue("ch-test", MessageA.ContentType, true, o => { o.SendOnlyFirstAcquirer = true; o.AcknowledgeTimeout = TimeSpan.FromSeconds(33); o.Status = MessagingQueueStatus.Pull; }); Assert.Equal(TmqResponseCode.Ok, created); Channel channel = server.Server.FindChannel("ch-test"); Assert.NotNull(channel); ChannelQueue queue = channel.FindQueue(MessageA.ContentType); Assert.NotNull(queue); Assert.True(queue.Options.SendOnlyFirstAcquirer); Assert.Equal(TimeSpan.FromSeconds(33), queue.Options.AcknowledgeTimeout); Assert.Equal(QueueStatus.Pull, queue.Status); }
public async Task RequestAcknowledge(bool queueAckIsActive) { int port = 47118 + Convert.ToInt32(queueAckIsActive); TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); Channel ch = server.Server.FindChannel("ch-route"); ChannelQueue queue = ch.Queues.FirstOrDefault(); Assert.NotNull(queue); queue.Options.AcknowledgeTimeout = TimeSpan.FromSeconds(3); queue.Options.RequestAcknowledge = queueAckIsActive; TmqClient producer = new TmqClient(); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); TmqClient consumer = new TmqClient(); consumer.AutoAcknowledge = true; consumer.AcknowledgeTimeout = TimeSpan.FromSeconds(4); consumer.ClientId = "consumer"; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); TmqResponseCode joined = await consumer.Join("ch-route", true); Assert.Equal(TmqResponseCode.Ok, joined); bool ack = await producer.Push("ch-route", MessageA.ContentType, "Hello, World!", true); Assert.Equal(queueAckIsActive, ack); }
public async Task RequestAcknowledge() { int port = 47412; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); Channel channel = server.Server.FindChannel("ch-pull"); ChannelQueue queue = channel.FindQueue(MessageA.ContentType); Assert.NotNull(channel); Assert.NotNull(queue); queue.Options.RequestAcknowledge = true; queue.Options.AcknowledgeTimeout = TimeSpan.FromSeconds(15); TmqClient consumer = new TmqClient(); consumer.AutoAcknowledge = true; consumer.ClientId = "consumer"; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); bool msgReceived = false; consumer.MessageReceived += (c, m) => msgReceived = true; TmqResponseCode joined = await consumer.Join("ch-pull", true); Assert.Equal(TmqResponseCode.Ok, joined); TmqClient producer = new TmqClient(); producer.AcknowledgeTimeout = TimeSpan.FromSeconds(15); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); Task <bool> taskAck = producer.Push("ch-pull", MessageA.ContentType, "Hello, World!", true); await Task.Delay(500); Assert.False(taskAck.IsCompleted); Assert.False(msgReceived); Assert.Single(queue.RegularMessages); TmqMessage pull = await consumer.Pull("ch-pull", MessageA.ContentType); Assert.NotNull(pull); }
public async Task PushToLateClients() { TestMqServer server = new TestMqServer(); server.Initialize(42506); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42506"); Assert.True(client.IsConnected); Channel channel = server.Server.Channels.FirstOrDefault(); Assert.NotNull(channel); ChannelQueue queue = channel.Queues.FirstOrDefault(); Assert.NotNull(queue); await queue.SetStatus(QueueStatus.Push); bool received = false; client.MessageReceived += (c, m) => { if (m.Type == MessageType.Channel) { received = true; } }; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")); bool sent = await client.Push(channel.Name, queue.Id, ms, false); Assert.True(sent); await Task.Delay(1500); Assert.NotEmpty(queue.RegularMessages); Assert.False(received); TmqResponseCode joined = await client.Join(channel.Name, true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(1500); Assert.Empty(queue.RegularMessages); Assert.True(received); }
public async Task QueueWaitAcknowledgeOneClient() { TestMqServer server = new TestMqServer(); server.Initialize(40582); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:40582"); client.AutoAcknowledge = true; Assert.True(client.IsConnected); Channel channel = server.Server.Channels.FirstOrDefault(); Assert.NotNull(channel); ChannelQueue queue = channel.Queues.FirstOrDefault(); Assert.NotNull(queue); queue.Options.Status = QueueStatus.Push; queue.Options.RequestAcknowledge = true; queue.Options.AcknowledgeTimeout = TimeSpan.FromSeconds(6); TmqResponseCode joined = await client.Join(channel.Name, true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(250); bool received = false; client.MessageReceived += (c, m) => { if (m.Type == MessageType.Channel) { received = true; } }; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")); bool sent = await client.Push(channel.Name, queue.Id, ms, true); Assert.True(sent); Assert.Empty(queue.HighPriorityMessages); Assert.Empty(queue.RegularMessages); Assert.True(received); }
public async Task UseUniqueMessageId(bool enabled) { int port = enabled ? 42701 : 42702; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Server.Options.UseMessageId = enabled; server.Server.FindChannel("ch-1").FindQueue(MessageA.ContentType).Options.UseMessageId = false; server.Start(); TmqClient client = new TmqClient(); client.UseUniqueMessageId = false; await client.ConnectAsync("tmq://localhost:" + port); Assert.True(client.IsConnected); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(250); TmqMessage received = null; client.MessageReceived += (c, m) => received = m; MessageA a = new MessageA("A"); string serialized = Newtonsoft.Json.JsonConvert.SerializeObject(a); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized)); bool sent = await client.Push("ch-1", MessageA.ContentType, ms, false); Assert.True(sent); await Task.Delay(1000); Assert.NotNull(received); if (enabled) { Assert.NotNull(received.MessageId); } else { Assert.Null(received.MessageId); } }
public async Task SendAcknowledgeFromServerToProducer() { TestMqServer server = new TestMqServer(); server.Initialize(42599); server.Start(); server.SendAcknowledgeFromMQ = true; TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42599"); Assert.True(client.IsConnected); bool ack = await client.Push("ch-route", MessageA.ContentType, "Hello", true); Assert.True(ack); }
public async Task ClientReadsMessagesFromMultipleChannels() { TestMqServer server = new TestMqServer(); server.Initialize(42802); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42802"); Assert.True(client.IsConnected); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); joined = await client.Join("ch-0", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(250); bool ch0 = false; bool ch1 = false; MessageReader reader = MessageReader.JsonReader(); reader.On <MessageA>("ch-0", MessageA.ContentType, a => ch0 = true); reader.On <MessageA>("ch-1", MessageA.ContentType, a => ch1 = true); reader.Attach(client); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(System.Text.Json.JsonSerializer.Serialize(new MessageA("Ax")))); bool sent = await client.Push("ch-1", MessageA.ContentType, ms, false); Assert.True(sent); sent = await client.Push("ch-0", MessageA.ContentType, ms, false); Assert.True(sent); await Task.Delay(1000); Assert.True(ch0); Assert.True(ch1); }
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); }
public async Task CatchResponseMessages(bool enabled) { int port = enabled ? 42711 : 42712; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(); TmqClient client1 = new TmqClient(); TmqClient client2 = new TmqClient(); client1.ClientId = "client-1"; client2.ClientId = "client-2"; client1.CatchResponseMessages = enabled; await client1.ConnectAsync("tmq://localhost:" + port); await client2.ConnectAsync("tmq://localhost:" + port); Assert.True(client1.IsConnected); Assert.True(client2.IsConnected); bool responseCaught = false; client1.MessageReceived += (c, m) => responseCaught = true; client2.MessageReceived += async(c, m) => { TmqMessage rmsg = m.CreateResponse(); rmsg.SetStringContent("Response!"); await((TmqClient)c).SendAsync(rmsg); }; TmqMessage msg = new TmqMessage(MessageType.Client, "client-2"); msg.ResponseRequired = true; msg.SetStringContent("Hello, World!"); TmqMessage response = await client1.Request(msg); Assert.NotNull(response); Assert.Equal(msg.MessageId, response.MessageId); Assert.Equal(enabled, responseCaught); }
public async Task SendAndPull() { int port = 47411; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); TmqClient consumer = new TmqClient(); consumer.ClientId = "consumer"; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); TmqResponseCode joined = await consumer.Join("ch-pull", true); Assert.Equal(TmqResponseCode.Ok, joined); TmqClient producer = new TmqClient(); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); await producer.Push("ch-pull", MessageA.ContentType, "Hello, World!", false); await Task.Delay(700); Channel channel = server.Server.FindChannel("ch-pull"); ChannelQueue queue = channel.FindQueue(MessageA.ContentType); Assert.NotNull(channel); Assert.NotNull(queue); Assert.Single(queue.RegularMessages); TmqMessage pull1 = await consumer.Pull("ch-pull", MessageA.ContentType); Assert.NotNull(pull1); TmqMessage pull2 = await consumer.Pull("ch-pull", MessageA.ContentType); Assert.Null(pull2); }
public async Task ClientReadsMessagesFromMultipleQueues() { TestMqServer server = new TestMqServer(); server.Initialize(42803); server.Start(); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42803"); Assert.True(client.IsConnected); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(250); bool ma = false; bool mc = false; MessageReader reader = MessageReader.JsonReader(); reader.On <MessageA>("ch-1", MessageA.ContentType, a => ma = true); reader.On <MessageA>("ch-1", MessageC.ContentType, c => mc = true); reader.Attach(client); MemoryStream astream = new MemoryStream(Encoding.UTF8.GetBytes(System.Text.Json.JsonSerializer.Serialize(new MessageA("Ax")))); MemoryStream cstream = new MemoryStream(Encoding.UTF8.GetBytes(System.Text.Json.JsonSerializer.Serialize(new MessageC("Cx", "x")))); bool sent = await client.Push("ch-1", MessageA.ContentType, astream, false); Assert.True(sent); sent = await client.Push("ch-1", MessageC.ContentType, cstream, false); Assert.True(sent); await Task.Delay(1000); Assert.True(ma); Assert.True(mc); }
public async Task WithResponse() { TestMqServer server = new TestMqServer(); server.Initialize(42603); 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:42603"); await client2.ConnectAsync("tmq://localhost:42603"); Assert.True(client1.IsConnected); Assert.True(client2.IsConnected); client2.MessageReceived += async(c, m) => { if (m.Source == "client-1") { TmqMessage rmsg = m.CreateResponse(); rmsg.ContentType = 123; rmsg.SetStringContent("Hello, World Response!"); await((TmqClient)c).SendAsync(rmsg); } }; TmqMessage message = new TmqMessage(MessageType.Client, "client-2"); message.SetStringContent("Hello, World!"); TmqMessage response = await client1.Request(message); Assert.NotNull(response); Assert.Equal(123, response.ContentType); }
public async Task SendToOfflineConsumers() { int port = 47217; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300, 300); TmqClient producer = new TmqClient(); await producer.ConnectAsync("tmq://localhost:" + port); Assert.True(producer.IsConnected); await producer.Push("ch-push", MessageA.ContentType, "Hello, World!", false); await Task.Delay(700); Channel channel = server.Server.FindChannel("ch-push"); ChannelQueue queue = channel.FindQueue(MessageA.ContentType); Assert.NotNull(channel); Assert.NotNull(queue); Assert.Single(queue.RegularMessages); bool msgReceived = false; TmqClient consumer = new TmqClient(); consumer.ClientId = "consumer"; await consumer.ConnectAsync("tmq://localhost:" + port); Assert.True(consumer.IsConnected); consumer.MessageReceived += (c, m) => msgReceived = true; TmqResponseCode joined = await consumer.Join("ch-push", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(800); Assert.True(msgReceived); }
public async Task ExceptionOnBindMethod() { TestMqServer server = new TestMqServer(); server.Initialize(42805); server.Start(); bool thrown = false; MessageReader reader = MessageReader.JsonReader(); reader.OnException += (tm, e) => thrown = true; reader.On <MessageA>("ch-1", MessageA.ContentType, a => throw new InvalidOperationException()); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:42805"); Assert.True(client.IsConnected); reader.Attach(client); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(1000); MessageA m = new MessageA("Msg-A"); MemoryStream ms = new MemoryStream(); await System.Text.Json.JsonSerializer.SerializeAsync(ms, m); bool sent = await client.Push("ch-1", MessageA.ContentType, ms, false); Assert.True(sent); await Task.Delay(1500); Assert.True(client.IsConnected); Assert.True(thrown); }
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); }
public async Task HideNamesInChannel(bool enabled) { int port = enabled ? 42531 : 42532; TestMqServer server = new TestMqServer(); server.Initialize(port); server.Start(300); Channel channel = server.Server.FindChannel("ch-1"); Assert.NotNull(channel); ChannelQueue queue = channel.FindQueue(MessageA.ContentType); Assert.NotNull(queue); queue.Options.HideClientNames = enabled; queue.Options.RequestAcknowledge = true; queue.Options.AcknowledgeTimeout = TimeSpan.FromSeconds(15); TmqClient client = new TmqClient(); await client.ConnectAsync("tmq://localhost:" + port); client.AutoAcknowledge = true; client.CatchAcknowledgeMessages = true; Assert.True(client.IsConnected); TmqResponseCode joined = await client.Join("ch-1", true); Assert.Equal(TmqResponseCode.Ok, joined); TmqMessage received = null; TmqMessage ack = null; client.MessageReceived += (c, m) => { switch (m.Type) { case MessageType.Channel: received = m; break; case MessageType.Acknowledge: ack = m; break; } }; await Task.Delay(500); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")); bool sent = await client.Push("ch-1", MessageA.ContentType, ms, true); Assert.True(sent); await Task.Delay(1000); Assert.NotNull(received); Assert.NotNull(ack); Assert.Equal("ch-1", received.Target); Assert.Equal("ch-1", ack.Target); if (enabled) { Assert.Null(received.Source); Assert.Null(ack.Source); } else { Assert.Equal(client.ClientId, received.Source); Assert.Equal(client.ClientId, ack.Source); } }
public async Task SendOnlyFirstLateClients() { TestMqServer server = new TestMqServer(); server.Initialize(42509); server.Start(); Channel channel = server.Server.Channels.FirstOrDefault(); Assert.NotNull(channel); ChannelQueue queue = channel.Queues.FirstOrDefault(); Assert.NotNull(queue); queue.Options.SendOnlyFirstAcquirer = true; await queue.SetStatus(QueueStatus.Push); bool[] received = new bool[3]; async Task <TmqClient> join(int no) { TmqClient client = new TmqClient(); client.ClientId = "client-" + no; await client.ConnectAsync("tmq://localhost:42509"); Assert.True(client.IsConnected); client.MessageReceived += (cx, m) => { if (m.Type == MessageType.Channel) { received[no - 1] = true; } }; return(client); } TmqClient client1 = await join(1); TmqClient client2 = await join(2); TmqClient client3 = await join(3); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")); bool sent = await client1.Push(channel.Name, queue.Id, ms, false); Assert.True(sent); await Task.Delay(1500); TmqResponseCode joined = await client1.Join(channel.Name, true); Assert.Equal(TmqResponseCode.Ok, joined); joined = await client2.Join(channel.Name, true); Assert.Equal(TmqResponseCode.Ok, joined); joined = await client3.Join(channel.Name, true); Assert.Equal(TmqResponseCode.Ok, joined); await Task.Delay(250); Assert.Empty(queue.HighPriorityMessages); Assert.Empty(queue.RegularMessages); int c = received.Count(x => x); Assert.Equal(1, c); }