public async Task SendMessageAsync(Message message) { while (!_messageStorageService.IsEmpty()) { var msg = _messageStorageService.GetNext(); if (msg != null) { var connections = _connectionService.GetConnectionsBySensor(msg.Sensor); foreach (var conn in connections) { await NotifySubscriber(msg, conn); } } } }
private void DoSendWork(object state) { while (!_messageStorage.IsEmpty()) { var message = _messageStorage.GetNext(); if (message != null) { var connections = _connectionStorage.GetConnectionsByTopic(message.Topic); foreach (var connection in connections) { var client = new Notifier.NotifierClient(connection.Channel); var request = new NotifyRequest() { Content = message.Content }; try { var reply = client.Notify(request); Console.WriteLine($"Notified subscriber {connection.Addres} with {message.Content}. Response: {reply.IsSuccess}"); } catch (RpcException rpcException) { if (rpcException.StatusCode == StatusCode.Internal) { _connectionStorage.Remove(connection.Addres); } Console.WriteLine($"RPC Error notifying subscriber {connection.Addres}. {rpcException.Message}"); } catch (Exception e) { Console.WriteLine($"Error notifying subscriber {connection.Addres}. {e.Message}"); } } } } }