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");
        }
Exemplo n.º 2
0
 async Task PublishMessageAsync(NsqProducer producer, Topic topic, byte[] message)
 {
     await producer.PublishAsync(topic, message);
     StatusLabel.Text = "Published message: " + BitConverter.ToString(message);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Publishes a message to NSQ.
 /// </summary>
 public Task PublishAsync(Topic topic, MessageBody message)
 {
     return SendCommandAsync(new Publish(topic, message));
 }
Exemplo n.º 4
0
 public Subscribe(Topic topic, Channel channel)
 {
     _topic = topic;
     _channel = channel;
 }