/// <summary> /// Publishes a message to NSQ. /// </summary> public Task PublishAsync(Topic topic, MessageBody message) { return SendCommandAsync(new Publish(topic, message)); }
public async Task PublishAsync(Topic topic, MessageBody message) { ThrowIfDisposed(); await _firstConnectionTask.ConfigureAwait(false); List<NsqTcpConnection> connections; lock (_connections) { connections = _connections.Values.ToList(); } if (connections.Count == 0) throw new CommunicationException("No NSQ connections are available"); foreach (var thing in connections) { try { await thing.PublishAsync(topic, message).ConfigureAwait(false); return; } catch { continue; } } throw new CommunicationException("Write failed against all NSQ connections"); }
/// <summary> /// Publishes a message to NSQ. /// </summary> public Task PublishAsync(Topic topic, MessageBody message) { return(SendCommandAsync(new Publish(topic, message))); }