public void AsyncProducerSendsFewShortFixedMessagesInSeparateSendActions() { var prodConfig = this.AsyncProducerConfig1; using (var producer = new AsyncProducer(prodConfig)) { var req1 = new ProducerRequest( CurrentTestTopic, 0, new List <Message> { new Message(Encoding.UTF8.GetBytes("Async Test Message 1")) }); producer.Send(req1); var req2 = new ProducerRequest( CurrentTestTopic, 0, new List <Message> { new Message(Encoding.UTF8.GetBytes("Async Test Message 2")) }); producer.Send(req2); var req3 = new ProducerRequest( CurrentTestTopic, 0, new List <Message> { new Message(Encoding.UTF8.GetBytes("Async Test Message 3")) }); producer.Send(req3); } }
public void AsyncProducerSendsManyLongRandomMessages() { var prodConfig = this.AsyncProducerConfig1; List <Message> messages = GenerateRandomTextMessages(50); using (var producer = new AsyncProducer(prodConfig)) { producer.Send(CurrentTestTopic, 0, messages); } }
public void AsyncProducerSendsCompressedAndConsumerReceivesSingleSimpleMessage() { var prodConfig = this.AsyncProducerConfig1; var consumerConfig = this.ConsumerConfig1; var sourceMessage = new Message(Encoding.UTF8.GetBytes("test message")); var compressedMessage = CompressionUtils.Compress(new List <Message> { sourceMessage }, CompressionCodecs.GZIPCompressionCodec); long currentOffset = TestHelper.GetCurrentKafkaOffset(CurrentTestTopic, consumerConfig); using (var producer = new AsyncProducer(prodConfig)) { var producerRequest = new ProducerRequest( CurrentTestTopic, 0, new List <Message> { compressedMessage }); producer.Send(producerRequest); } IConsumer consumer = new Consumer(consumerConfig); var request = new FetchRequest(CurrentTestTopic, 0, currentOffset); BufferedMessageSet response; int totalWaitTimeInMiliseconds = 0; int waitSingle = 100; while (true) { Thread.Sleep(waitSingle); response = consumer.Fetch(request); if (response != null && response.Messages.Count() > 0) { break; } totalWaitTimeInMiliseconds += waitSingle; if (totalWaitTimeInMiliseconds >= MaxTestWaitTimeInMiliseconds) { break; } } Assert.NotNull(response); Assert.AreEqual(1, response.Messages.Count()); Message resultMessage = response.Messages.First(); Assert.AreEqual(compressedMessage.ToString(), resultMessage.ToString()); }
public void AsyncProducerSendsFewShortFixedMessages() { var prodConfig = this.AsyncProducerConfig1; var messages = new List <Message> { new Message(Encoding.UTF8.GetBytes("Async Test Message 1")), new Message(Encoding.UTF8.GetBytes("Async Test Message 2")), new Message(Encoding.UTF8.GetBytes("Async Test Message 3")), new Message(Encoding.UTF8.GetBytes("Async Test Message 4")) }; using (var producer = new AsyncProducer(prodConfig)) { producer.Send(CurrentTestTopic, 0, messages); } }
public void AsyncProducerSendsMessageWithCallback() { var prodConfig = this.AsyncProducerConfig1; var messages = new List <Message> { new Message(Encoding.UTF8.GetBytes("Async Test Message 1")), }; var myHandler = new TestCallbackHandler(); using (var producer = new AsyncProducer(prodConfig)) { producer.Send(CurrentTestTopic, 0, messages, myHandler.Handle); } Thread.Sleep(1000); Assert.IsTrue(myHandler.WasRun); }