private static async Task PublishMessage() { Console.WriteLine("Publishing Message"); var prod = new NsqProducer("localhost", 4151); await prod.PublishAsync("topic1", "hello world"); Console.WriteLine("Message Published"); }
public async Task ProducerCanEmptyAChannel() { // Put something in the channel await prod.PublishAsync(options.Topic, new byte[] { 1 }); // Now erase it await EmptyChannelAsync(options.Topic, options.Channel); // Now try to receive anything bool receivedData = false; conn = new NsqTcpConnection(endPoint, options); await conn.ConnectAndWaitAsync(async msg => { receivedData = true; await msg.FinishAsync(); }); await conn.SetMaxInFlightAsync(100); await Task.Delay(100); Assert.False(receivedData); }
public async Task ConnectAndWaitIsConnectedImmediatelyAfter() { options.Topic = "foo"; options.Channel = "bar"; var tcs = new TaskCompletionSource <bool>(); using (var conn = new NsqTcpConnection(endPoint, options)) { Assert.False(conn.Connected); await conn.ConnectAndWaitAsync(msg => { tcs.TrySetResult(true); return(msg.FinishAsync()); }); Assert.True(conn.Connected); // Just for kicks, verify we're working await Task.WhenAll( prod.PublishAsync(options.Topic, new byte[] { 1, 2, 3, 4 }), conn.SetMaxInFlightAsync(10)); var task = tcs.Task; var done = await Task.WhenAny(task, Task.Delay(1000)); Assert.Same(done, task); } }
static async Task Main(string[] args) { var consumerOptions = new NsqConsumerOptions("test", "test", 5, TimeSpan.FromSeconds(10)); INsqConsumer connection = new NsqConsumer(consumerOptions); connection.OnError += OnError; connection.OnMessage += OnMessage; connection.OnDisconnected += OnDisconnected; connection.OnReconnected += OnReconnected; await connection.ConnectAsync(); INsqProducer producer = new NsqProducer(new NsqProducerOptions()); await producer.ConnectAsync(); await producer.PublishAsync("test", DateTime.Now.ToString("o")); Console.ReadLine(); }
async Task PublishMessageAsync(NsqProducer producer, Topic topic, byte[] message) { await producer.PublishAsync(topic, message); StatusLabel.Text = "Published message: " + BitConverter.ToString(message); }
async Task PublishMessageAsync(NsqProducer producer, Topic topic, byte[] message) { await producer.PublishAsync(topic, message); StatusLabel.Text = "Published message: " + BitConverter.ToString(message); }