Class KafkaClient
java.lang.Object
dev.lydtech.component.framework.client.kafka.KafkaClient
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionconsumeAndAssert(String testName, org.apache.kafka.clients.consumer.Consumer consumer, int expectedEventCount, int furtherPolls) consumeAndAssert(String testName, org.apache.kafka.clients.consumer.Consumer consumer, int expectedEventCount, int furtherPolls, int awaitAtMostSeconds) 1.org.apache.kafka.clients.consumer.ConsumercreateConsumer(String groupId, String topic) Create a standard Consumer.org.apache.kafka.clients.consumer.ConsumercreateConsumer(String groupId, String topic, Properties additionalConfig) Create a Consumer with additional config.Create a standard Producer.createProducer(Properties additionalConfig) Create a Producer with additional config.protected Stringstatic KafkaClientorg.apache.kafka.clients.consumer.ConsumerinitConsumer(String groupId, String topic, Long initialPollSeconds) Create a consumer and perform an initial long poll for the given number of seconds in order to clear the topic.org.apache.kafka.clients.consumer.ConsumerinitConsumer(String groupId, String topic, Properties additionalConfig, Long initialPollSeconds) Create a Consumer with additional config, and perform an initial long poll for the given number of seconds in order to clear the topic.org.apache.kafka.clients.producer.RecordMetadatasendMessage(String topic, String key, Object payload) Send a message synchronously without headers and with the default Producer.org.apache.kafka.clients.producer.RecordMetadataSend a message synchronously with the provided headers and with the default Producer.org.apache.kafka.clients.producer.RecordMetadatasendMessage(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload) Send a message synchronously without headers and with the provided Producer.org.apache.kafka.clients.producer.RecordMetadatasendMessage(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload, Map<String, String> headers) Send a message synchronously.Future<org.apache.kafka.clients.producer.RecordMetadata>sendMessageAsync(String topic, String key, Object payload) Send a message asynchronously without headers and with the default Producer.Future<org.apache.kafka.clients.producer.RecordMetadata>Send a message asynchronously with the provided headers and with the default Producer.Future<org.apache.kafka.clients.producer.RecordMetadata>sendMessageAsync(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload) Send a message asynchronously without headers and with the provided Producer.Future<org.apache.kafka.clients.producer.RecordMetadata>sendMessageAsync(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload, Map<String, String> headers) Send a message asynchronously.
-
Field Details
-
brokerUrl
-
-
Method Details
-
getInstance
-
getBrokerUrl
-
createConsumer
Create a standard Consumer. -
createConsumer
public org.apache.kafka.clients.consumer.Consumer createConsumer(String groupId, String topic, Properties additionalConfig) Create a Consumer with additional config. -
initConsumer
public org.apache.kafka.clients.consumer.Consumer initConsumer(String groupId, String topic, Long initialPollSeconds) Create a consumer and perform an initial long poll for the given number of seconds in order to clear the topic. -
initConsumer
public org.apache.kafka.clients.consumer.Consumer initConsumer(String groupId, String topic, Properties additionalConfig, Long initialPollSeconds) Create a Consumer with additional config, and perform an initial long poll for the given number of seconds in order to clear the topic. -
createProducer
Create a standard Producer. -
createProducer
public org.apache.kafka.clients.producer.KafkaProducer<String,String> createProducer(Properties additionalConfig) Create a Producer with additional config. -
sendMessage
public org.apache.kafka.clients.producer.RecordMetadata sendMessage(String topic, String key, Object payload) throws Exception Send a message synchronously without headers and with the default Producer.- Throws:
Exception
-
sendMessage
public org.apache.kafka.clients.producer.RecordMetadata sendMessage(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload) throws Exception Send a message synchronously without headers and with the provided Producer.- Throws:
Exception
-
sendMessage
public org.apache.kafka.clients.producer.RecordMetadata sendMessage(String topic, String key, Object payload, Map<String, String> headers) throws ExceptionSend a message synchronously with the provided headers and with the default Producer.- Throws:
Exception
-
sendMessage
public org.apache.kafka.clients.producer.RecordMetadata sendMessage(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload, Map<String, String> headers) throws ExceptionSend a message synchronously. Awaits for the result of the send before returning.- Throws:
Exception
-
sendMessageAsync
public Future<org.apache.kafka.clients.producer.RecordMetadata> sendMessageAsync(String topic, String key, Object payload) Send a message asynchronously without headers and with the default Producer. -
sendMessageAsync
public Future<org.apache.kafka.clients.producer.RecordMetadata> sendMessageAsync(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload) Send a message asynchronously without headers and with the provided Producer. -
sendMessageAsync
public Future<org.apache.kafka.clients.producer.RecordMetadata> sendMessageAsync(String topic, String key, Object payload, Map<String, String> headers) Send a message asynchronously with the provided headers and with the default Producer. -
sendMessageAsync
public Future<org.apache.kafka.clients.producer.RecordMetadata> sendMessageAsync(org.apache.kafka.clients.producer.Producer producer, String topic, String key, Object payload, Map<String, String> headers) Send a message asynchronously. Allows for producing batches of messages, by tuning the producer linger.ms config. -
consumeAndAssert
public <T> List<org.apache.kafka.clients.consumer.ConsumerRecord<String,T>> consumeAndAssert(String testName, org.apache.kafka.clients.consumer.Consumer consumer, int expectedEventCount, int furtherPolls) throws Exception - Throws:
Exception
-
consumeAndAssert
public <T> List<org.apache.kafka.clients.consumer.ConsumerRecord<String,T>> consumeAndAssert(String testName, org.apache.kafka.clients.consumer.Consumer consumer, int expectedEventCount, int furtherPolls, int awaitAtMostSeconds) throws Exception 1. Poll for messages on the application’s outbound topic. 2. Assert the expected number are received within the specified number of seconds. 3. Performs the specified number of extra polls after the expected number received to ensure no further events. 4. Returns the consumed events.- Throws:
Exception
-