public async Task Stop() { await _approvedAdoProjcetMessageReceiverClient?.CloseAsync(); await _rejectedAdoProjcetMessageReceiverClient?.CloseAsync(); //await _queueReceiverClient?.CloseAsync(); }
private static async Task <T> GetMessageBodyAsync <T>(IReceiverClient client) { string body = null; client.RegisterMessageHandler(async(msg, token) => { Message message = msg; if (message != null) { body = Encoding.UTF8.GetString(message.Body); if (body.Contains("spoiled", StringComparison.OrdinalIgnoreCase)) { await client.DeadLetterAsync(msg.SystemProperties.LockToken); } else { await client.CompleteAsync(msg.SystemProperties.LockToken); } } }, new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 1, AutoComplete = false }); await client.UnregisterMessageHandlerAsync(TimeSpan.FromMilliseconds(2000)); await client.CloseAsync(); if (body != null) { return(JsonSerializer.Deserialize <T>(body)); } return(default);
public void Dispose() { _receiverClient.CloseAsync(); }
static string Read(IReceiverClient client, bool peek, int numMessages, int time) { System.Timers.Timer timer = new System.Timers.Timer(); System.Timers.Timer logTimer = new System.Timers.Timer() { Interval = 2000, AutoReset = true }; client.PrefetchCount = numMessages; var messages = new StringBuilder(); int n = 0; bool isTimeUp = false; timer.Elapsed += (object source, System.Timers.ElapsedEventArgs e) => { isTimeUp = true; }; logTimer.Elapsed += (object source, System.Timers.ElapsedEventArgs e) => { if (Verbose) { Console.WriteLine("Waiting for messages..."); } }; if (time >= 0) { timer.Interval = time * 1000; timer.Start(); } logTimer.Start(); var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 1, AutoComplete = false }; try { client.RegisterMessageHandler(async(Message message, CancellationToken token) => { if (Verbose) { Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber}"); } Console.WriteLine(Encoding.UTF8.GetString(message.Body)); messages.Append(Encoding.UTF8.GetString(message.Body)); if (!peek) { await client.CompleteAsync(message.SystemProperties.LockToken); } n++; }, messageHandlerOptions); while (n < numMessages && !isTimeUp) { } } catch (Exception e) { Console.WriteLine($"Ooops, trying to read messages failed: {e}"); } finally { client.CloseAsync(); timer.Stop(); logTimer.Stop(); } return(messages.ToString()); }
public async Task Stop() { await _wmOperationRequestMessageReceiverClient?.CloseAsync(); }
public async Task CloseAsync() { await _onClose?.Invoke(_client); await _client.CloseAsync(); }
public async ValueTask DisposeAsync() { await Task.WhenAll(_sender.CloseAsync(), _receiver.CloseAsync()); }