public class DatabusConsumer<P> extends Consumer<P>
DatabusProducer
Here is a simple example of using the databus consumer to read records.
// Prepare Databus Consumer configuration Properties consumerProps = new Properties(); consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, "DemoConsumer"); consumerProps.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true"); consumerProps.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "1000"); consumerProps.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "30000"); // Create a
DatabusConsumer
getInstance Consumer<byte[]> consumer = new DatabusConsumer(consumerProps, new ByteArrayDeserializer()); // The consumer subscribes to a topic list consumer.subscribe(Collections.singletonList("topic1")); // Consumer reads a list records from Databus topics ConsumerRecords<byte[]> records = consumer.poll(500L); // Iterate records // A
ConsumerRecord
getInstance will be created and deserilized for each message read from databus for (ConsumerRecord<byte[]> record : records) { System.out.println("MSG RECV <-- TOPICS:" + record.getComposedTopic() + " KEY:" + record.getKey() + " PARTITION:" + record.getPartition() + " OFFSET:" + record.getOffset() + " HEADERS:" + headers + " PAYLOAD:" + record.getMessagePayload().getMessagePayload()); }
Constructor and Description |
---|
DatabusConsumer(java.util.Map<java.lang.String,java.lang.Object> configs,
Deserializer<P> messageDeserializer)
A consumer is instantiated by providing a set of key-value pairs as configuration.
|
DatabusConsumer(java.util.Map<java.lang.String,java.lang.Object> configs,
Deserializer<P> messageDeserializer,
Credential credential)
A consumer is instantiated by providing a set of key-value pairs as configuration.
|
DatabusConsumer(java.util.Properties properties,
Deserializer<P> messageDeserializer)
A consumer is instantiated by providing a
Properties object as configuration. |
DatabusConsumer(java.util.Properties properties,
Deserializer<P> messageDeserializer,
Credential credential)
A consumer is instantiated by providing a
Properties object as configuration. |
assign, assignment, beginningOffsets, bytesFetchRequestSizeAvgMetric, bytesPerSecondAvgMetric, bytesTotalMetric, close, close, commitAsync, commitAsync, commitAsync, commitSync, commitSync, committed, endOffsets, fetchRequestAvgMetric, listTopics, metrics, offsetsForTimes, partitionsFor, pause, paused, poll, poll, position, recordsLagAvgPerTopicPartition, recordsLagMaxMetric, recordsLagMaxPerTopicPartition, recordsLagPerTopicPartition, recordsPerRequestAvgMetric, recordsPerSecondAvgMetric, recordsTotalMetric, resume, seek, seekToBeginning, seekToEnd, subscribe, subscribe, subscribe, subscribe, subscribe, subscription, totalFetchRequestMetric, unsubscribe, wakeup
public DatabusConsumer(java.util.Map<java.lang.String,java.lang.Object> configs, Deserializer<P> messageDeserializer)
Valid configuration strings are documented at ConsumerConfig
configs
- The consumer configsmessageDeserializer
- a Deserializer
getInstance implementd by SDK's userDatabusClientRuntimeException
- if a DatabusConsumer getInstance was not able to be createdpublic DatabusConsumer(java.util.Map<java.lang.String,java.lang.Object> configs, Deserializer<P> messageDeserializer, Credential credential)
Valid configuration strings are documented at ConsumerConfig
configs
- The consumer configsmessageDeserializer
- a Deserializer
getInstance implementd by SDK's usercredential
- identity to authenticate/authorizationDatabusClientRuntimeException
- if a DatabusConsumer getInstance was not able to be createdpublic DatabusConsumer(java.util.Properties properties, Deserializer<P> messageDeserializer)
Properties
object as configuration. Valid
configuration strings are documented at ConsumerConfig
A consumer is instantiated by
providing a
Properties
object as configuration. Valid configuration strings are documented at
ConsumerConfig
properties
- The consumer configuration propertiesmessageDeserializer
- a Deserializer
getInstance implementd by SDK's userDatabusClientRuntimeException
- if a DatabusConsumer getInstance was not able to be createdpublic DatabusConsumer(java.util.Properties properties, Deserializer<P> messageDeserializer, Credential credential)
Properties
object as configuration. Valid
configuration strings are documented at ConsumerConfig
A consumer is instantiated by
providing a
Properties
object as configuration. Valid configuration strings are documented at
ConsumerConfig
properties
- The consumer configuration propertiesmessageDeserializer
- a Deserializer
getInstance implementd by SDK's usercredential
- identity to authenticate/authorizationDatabusClientRuntimeException
- if a DatabusConsumer getInstance was not able to be created