Send() public method

Sends request to Kafka server asynchronously
public Send ( ProducerRequest request ) : void
request Kafka.Client.Requests.ProducerRequest /// The request. ///
return void
Esempio n. 1
0
        public void AsyncProducerSendsAndConsumerReceivesSingleSimpleMessage()
        {
            Message sourceMessage = new Message(Encoding.UTF8.GetBytes("test message"));

            var config = new AsyncProducerConfig(clientConfig);
            var producer = new AsyncProducer(config);
            var producerRequest = new ProducerRequest(CurrentTestTopic, 0, new List<Message>() { sourceMessage });

            long currentOffset = TestHelper.GetCurrentKafkaOffset(CurrentTestTopic, clientConfig);

            producer.Send(producerRequest);

            ConsumerConfig consumerConfig = new ConsumerConfig(clientConfig);
            IConsumer consumer = new Consumers.Consumer(consumerConfig);
            FetchRequest 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;
                }
                else
                {
                    totalWaitTimeInMiliseconds += waitSingle;
                    if (totalWaitTimeInMiliseconds >= MaxTestWaitTimeInMiliseconds)
                    {
                        break;
                    }
                }
            }

            Assert.NotNull(response);
            Assert.AreEqual(1, response.Messages.Count());
            Message resultMessage = response.Messages.First();
            Assert.AreEqual(sourceMessage.ToString(), resultMessage.ToString());
        }
Esempio n. 2
0
        public void AsyncProducerSendsManyLongRandomMessages()
        {
            List<Message> messages = GenerateRandomTextMessages(50);

            var config = new AsyncProducerConfig(clientConfig);

            var producer = new AsyncProducer(config);
            producer.Send(CurrentTestTopic, 0, messages);
        }
Esempio n. 3
0
 public void AsyncProducerSendsMessageWithCallbackClass()
 {
     List<Message> messages = new List<Message>()
                                  {
                                      new Message(Encoding.UTF8.GetBytes("Async Test Message 1")),
                                  };
     var config = new AsyncProducerConfig(clientConfig);
     TestCallbackHandler myHandler = new TestCallbackHandler();
     var producer = new AsyncProducer(config, myHandler);
     producer.Send(CurrentTestTopic, 0, messages);
     Thread.Sleep(1000);
     Assert.IsTrue(myHandler.WasRun);
 }
Esempio n. 4
0
        public void AsyncProducerSendsFewShortFixedMessages()
        {
            List<Message> 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"))
                                         };

            var config = new AsyncProducerConfig(clientConfig);

            var producer = new AsyncProducer(config);
            producer.Send(CurrentTestTopic, 0, messages);
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        public void AsyncProducerSendsMessageWithCallbackClass()
        {
            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, myHandler))
            {
                producer.Send(CurrentTestTopic, 0, messages);
            }

            Thread.Sleep(1000);
            Assert.IsTrue(myHandler.WasRun);
        }
Esempio n. 7
0
 public void AsyncProducerSendsManyLongRandomMessages()
 {
     var prodConfig = this.AsyncProducerConfig1;
     List<Message> messages = GenerateRandomTextMessages(50);
     using (var producer = new AsyncProducer(prodConfig))
     {
         producer.Send(CurrentTestTopic, 0, messages);
     }
 }
Esempio n. 8
0
        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);
            }
        }