public void Start() { var messageListeningSettings = new MessageSettingsIn(settings.ListenOn); listener.OnMessage += Listener_OnMessageReceive; listener.StartListening(messageListeningSettings); }
public void ReceiveAllMessages_2() { generateTestMessages(6); var randint = new Random().Next(); var queueName = "queuetwo"; var messageSettings = new MessageSettingsIn(queueName); using (var listener = new Listener <TestMessage>(hostSettings, processor, messageLogger)) { listener.OnError += OnError; listener.OnMessage += Listener_OnMessage; //Start listener foreach (var message in testMessages) { SendTestMessageToQueue(message, queueName); Thread.Sleep(1000); } Thread.Sleep(1 * 1000); var task = Task.Run(() => listener.StartListening(messageSettings, listenerTimeoutCancelationToken)); var dealy = new Task(() => { while (!listenerTimeoutCancelationToken.IsCancellationRequested) { Thread.Sleep(200); } }); dealy.Start(); dealy.Wait(180 * 1000); //Wait 3 minutes on messages listenerTimeoutCancelationToken.Cancel(false); } foreach (var sent in testMessages) { var received = receivedMessages.SingleOrDefault(x => x.Id == sent.Id); Assert.NotNull(received); Assert.Equal(sent.Id, received.Id); Assert.Equal(sent.IsTest, received.IsTest); Assert.Equal(sent.TestValue, received.TestValue); } }
public void ReceiveMessageFromListenerAndCallAnnouncer() { ModuleSettings setting = new ModuleSettings() { AppId = Guid.Empty, ListenOn = "test", SendTo = "test", }; var fakeMessageFormListener = new CreateOrderMessage { Id = Guid.Empty, IsTest = true, OrderId = 53462, OrderName = "Test order", }; var messageSendSettings = new MessageSettingsOut(setting.SendTo); var messageListenSettings = new MessageSettingsIn(setting.ListenOn); var loggerMock = new Mock <ILogger <UpdateAddressModule> >(); var queueListenerMok = new Mock <IListener>(); queueListenerMok.Setup(x => x.StartListening(messageListenSettings, null)); var queueAnnouncerMok = new Mock <IAnnouncer>(); queueAnnouncerMok.Setup(x => x.Announce(fakeMessageFormListener, It.IsAny <IMessageSettingsOut>())).Verifiable("Listener should call anouncer!"); var module = new UpdateAddressModule(setting, loggerMock.Object, queueListenerMok.Object, queueAnnouncerMok.Object); module.Start(); queueListenerMok.Raise(x => x.OnMessage += (test) => { }, fakeMessageFormListener); Task.Delay(2000); queueAnnouncerMok.VerifyAll(); //If we are in here it's mean success Assert.True(true); }
public void ReceiveMessagesOnlyOnce() { generateTestMessages(10); maxMessagesToReadInSingleListener = 5; var randint = new Random().Next(); var queueName = "queuethree"; var messageSettings = new MessageSettingsIn(queueName); using (var listener = new Listener <TestMessage>(hostSettings, processor, messageLogger)) { listener.OnError += OnError; listener.OnMessage += Listener_OnMessage; SendTestMessageToQueue(testMessages, queueName); var task = Task.Run(() => listener.StartListening(messageSettings, listenerTimeoutCancelationToken)); var dealy = new Task(() => { while (!listenerTimeoutCancelationToken.IsCancellationRequested) { Thread.Sleep(200); } }); dealy.Start(); dealy.Wait(180 * 1000); //Wait 3 minutes on messages listenerTimeoutCancelationToken.Cancel(false); } consumedMessages = 0; listenerTimeoutCancelationToken = new CancellationTokenSource(); //Start listener once again. To check are we read messages only once by listener. using (var listener = new Listener <TestMessage>(hostSettings, processor, messageLogger)) { listener.OnError += OnError; listener.OnMessage += Listener_OnMessage; var task = Task.Run(() => listener.StartListening(messageSettings, listenerTimeoutCancelationToken)); var dealy = new Task(() => { while (!listenerTimeoutCancelationToken.IsCancellationRequested) { Thread.Sleep(200); } }); dealy.Start(); dealy.Wait(60 * 1000); //Wait 60 seconds on messages listenerTimeoutCancelationToken.Cancel(false); } Assert.Equal(testMessages.Count, receivedMessages.Count); foreach (var sent in testMessages) { var received = receivedMessages.SingleOrDefault(x => x.Id == sent.Id); Assert.NotNull(received); Assert.Equal(sent.Id, received.Id); Assert.Equal(sent.IsTest, received.IsTest); Assert.Equal(sent.TestValue, received.TestValue); } }