cancel
Showing results for 
Search instead for 
Did you mean: 

Apache Kafka consumer in SOAPUI pro

SOLVED
Occasional Contributor

Apache Kafka consumer in SOAPUI pro

Hi,

 

Can anyone help me in recording and asserting the data from a kafka producer application in SOAPUI Pro?

I tried with groovy script and example code from the apache website but I was not successful yet.

 

Thanky in advance.

 

Regards

Markus

 

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Apache Kafka consumer in SOAPUI pro

Hi Markus,

 

Thank you for your email. Do you use a sample code from here: https://kafka.apache.org/22/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html ?
What error do you get?



 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post

3 REPLIES 3
Moderator

Re: Apache Kafka consumer in SOAPUI pro

Hi Markus,

 

Thank you for your email. Do you use a sample code from here: https://kafka.apache.org/22/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html ?
What error do you get?



 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post

Occasional Contributor

Re: Apache Kafka consumer in SOAPUI pro

I get too many errors, therefore this seems for me be not straight forward.

 

The example code is:

     Properties props = new Properties();
     props.setProperty("bootstrap.servers", "localhost:9092");
     props.setProperty("group.id", "test");
     props.setProperty("enable.auto.commit", "true");
     props.setProperty("auto.commit.interval.ms", "1000");
     props.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
     props.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
     KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
     consumer.subscribe(Arrays.asList("foo", "bar"));
     while (true) {
         ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
         for (ConsumerRecord<String, String> record : records)
             System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
     }

 

Do you know what to add into the lace braces instead of "String, String"?

KafkaConsumer<String, String>

ConsumerRecords<String, String>

Highlighted
Moderator

Re: Apache Kafka consumer in SOAPUI pro

Hi Markus,

 

Did you place the kafka jar file(s) to the <ReadyAPI_Install>\bin\ext folder?

 

1. I generated the kafka-producer-consumer-1.0-SNAPSHOT.jar file as it's described here:

https://github.com/Azure-Samples/hdinsight-kafka-java-get-started

2. Then, I place it to the bin\ext folder.

3. Also, I added the below line to the script:

import org.apache.kafka.clients.consumer.*;

 

After this, I don't get errors about the KafkaConsume class. But, I get the error about the Duration. You can get more info about this here: https://stackoverflow.com/questions/55067611/kafka-consumer-needs-a-long-poll-duration



 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!