예제 #1
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);
            }
        }
예제 #2
0
        public void AsyncProducerSendsManyLongRandomMessages()
        {
            var            prodConfig = this.AsyncProducerConfig1;
            List <Message> messages   = GenerateRandomTextMessages(50);

            using (var producer = new AsyncProducer(prodConfig))
            {
                producer.Send(CurrentTestTopic, 0, messages);
            }
        }
예제 #3
0
        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());
        }
예제 #4
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);
            }
        }
예제 #5
0
        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);
        }