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