/// <summary> /// Emulates the messages processing /// </summary> /// <param name="message"></param> private void MessageHandler(SBMessage message) { Console.WriteLine($"MessageHandler - ClientId: {_ClientId} - SequenceNumber:{message.SequenceNumber} - Body:{message.Body}"); int wait = _Random.Next(1000 * _ClientId); Thread.Sleep(wait); Console.WriteLine($"MessageHandler - ClientId: {_ClientId} - Wait: {wait} - SequenceNumber:{message.SequenceNumber} - Body:{message.Body}"); }
private static List <SBMessage> generateTasks(int taskNumber) { List <SBMessage> tasks = new List <SBMessage>(); for (int i = 1; i <= taskNumber; i++) { SBMessage msg = new SBMessage("Test task " + i); msg.Headers.Add(HeaderName.PressureValue, rand.Next(1000, 10000) / 1000.0); msg.Headers.Add("ProductType", rand.Next(0, 2) == 0 ? "Cars" : "Trucks"); tasks.Add(msg); } return(tasks); }
private static async Task ProcessMessagesAsync(Message message, CancellationToken token) { // Process the message. Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); SBMessage sbMessage = new SBMessage() { SequenceNumber = message.SystemProperties.SequenceNumber, Body = Encoding.UTF8.GetString(message.Body) }; foreach (BufferBlock <SBMessage> SBMessageBufferBlock in SBMessageBufferBlockList) { await SBMessageBufferBlock.SendAsync(sbMessage); } // Complete the message so that it is not received again. // This can be done only if the subscriptionClient is created in ReceiveMode.PeekLock mode (which is the default). await _SubscriptionClient.CompleteAsync(message.SystemProperties.LockToken); }