Kafka 1.1.0 AdminClient create topic throws exception

245 views
Skip to first unread message

Webster Homer

unread,
Jul 10, 2018, 1:04:33 PM7/10/18
to Confluent Platform
I recently upgraded to Kafka 1.1.0. I am trying to create unit tests for the kafka consumer. For this purpose it would be ideal if the unit test can create the topic it uses for the test. I found some code that looks like it should do what I want. However, when I run it it throws an exception: java.lang.NoSuchMethodError: org.apache.kafka.common.utils.Utils.closeQuietly(Ljava/lang/AutoCloseable;Ljava/lang/String;)V

Here is the code to create a topic:
@BeforeClass
public static void createTopic() {
       try (final AdminClient adminClient = AdminClient.create(configure())) {
            try {
                // Define topic
        NewTopic newTopic = new NewTopic("test-orders", 1, (short)1);

                // Create topic, which is async call.
                final CreateTopicsResult createTopicsResult = adminClient.createTopics(Collections.singleton(newTopic));

                // Since the call is Async, Lets wait for it to complete.
                createTopicsResult.values().get(ordersTopic).get();
            } catch (InterruptedException | ExecutionException e) {
                if (!(e.getCause() instanceof TopicExistsException)) {
                    throw new RuntimeException(e.getMessage(), e);
                }
                // TopicExistsException - Swallow this exception, just means the topic already exists.
            }
        }
}

The call to create the AdminClient fails:
java.lang.NoSuchMethodError: org.apache.kafka.common.utils.Utils.closeQuietly(Ljava/lang/AutoCloseable;Ljava/lang/String;)V
at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:334)
at org.apache.kafka.clients.admin.AdminClient.create(AdminClient.java:52)
at com.sial.notifications.topics.OrdersTopicsTests.createTopic(OrdersTopicsTests.java:162)


Is there a different way to do this? The documentation on creating topics dynamically is sparse at best.

Thanks
Reply all
Reply to author
Forward
0 new messages