P
- Message payload typepublic final class DatabusPushConsumer<P> extends DatabusConsumer<P> implements java.io.Closeable
DatabusConsumer
to replace poll model for push message model.
pushAsync()
reads messages from an
already-subscribed topic and push them to a DatabusPushConsumerListener
listener
instance implemented by the SDK Databus client.
The listener receives messages read from Databus and it should implement some logic to process them.
The listener returns a DatabusPushConsumerListenerResponse
enum value to let Push Databus Consumer known
which action it should take.Constructor and Description |
---|
DatabusPushConsumer(java.util.Map<java.lang.String,java.lang.Object> configs,
Deserializer<P> messageDeserializer,
DatabusPushConsumerListener consumerListener)
Constructor
|
DatabusPushConsumer(java.util.Map<java.lang.String,java.lang.Object> configs,
Deserializer<P> messageDeserializer,
DatabusPushConsumerListener consumerListener,
Credential credential) |
DatabusPushConsumer(java.util.Properties properties,
Deserializer<P> messageDeserializer,
DatabusPushConsumerListener consumerListener) |
DatabusPushConsumer(java.util.Properties properties,
Deserializer<P> messageDeserializer,
DatabusPushConsumerListener consumerListener,
Credential credential) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the consumer, waiting for up to the default timeout of 30 seconds for any needed cleanup.
|
ConsumerRecords |
poll(java.time.Duration timeout)
Fetch data for the topics or partitions specified using one of the subscribe/assign APIs.
|
ConsumerRecords |
poll(long timeout)
Fetch data for the topics or topicPartitions specified using one of the subscribe/assign APIs.
|
DatabusPushConsumerFuture |
pushAsync()
Reads messages from Databus and push them to
DatabusPushConsumerListener instance which was passed
in the constructor |
DatabusPushConsumerFuture |
pushAsync(java.time.Duration timeout)
Reads messages from Databus and push them to
DatabusPushConsumerListener instance which was passed
in the constructor |
assign, assignment, beginningOffsets, bytesFetchRequestSizeAvgMetric, bytesPerSecondAvgMetric, bytesTotalMetric, close, commitAsync, commitAsync, commitAsync, commitSync, commitSync, committed, endOffsets, fetchRequestAvgMetric, listTopics, metrics, offsetsForTimes, partitionsFor, pause, paused, position, recordsLagAvgPerTopicPartition, recordsLagMaxMetric, recordsLagMaxPerTopicPartition, recordsLagPerTopicPartition, recordsPerRequestAvgMetric, recordsPerSecondAvgMetric, recordsTotalMetric, resume, seek, seekToBeginning, seekToEnd, subscribe, subscribe, subscribe, subscribe, subscribe, subscription, totalFetchRequestMetric, unsubscribe, wakeup
public DatabusPushConsumer(java.util.Map<java.lang.String,java.lang.Object> configs, Deserializer<P> messageDeserializer, DatabusPushConsumerListener consumerListener)
configs
- consumer configurationmessageDeserializer
- consumer message deserializerconsumerListener
- consumer listenerpublic DatabusPushConsumer(java.util.Map<java.lang.String,java.lang.Object> configs, Deserializer<P> messageDeserializer, DatabusPushConsumerListener consumerListener, Credential credential)
configs
- consumer configurationmessageDeserializer
- consumer message deserializerconsumerListener
- consumer listenercredential
- credential to get access to Databus in case security is enabledpublic DatabusPushConsumer(java.util.Properties properties, Deserializer<P> messageDeserializer, DatabusPushConsumerListener consumerListener)
properties
- consumer configurationmessageDeserializer
- consumer message deserializerconsumerListener
- consumer listenerpublic DatabusPushConsumer(java.util.Properties properties, Deserializer<P> messageDeserializer, DatabusPushConsumerListener consumerListener, Credential credential)
properties
- consumer configurationmessageDeserializer
- consumer message deserializerconsumerListener
- consumer listenercredential
- credential to get access to Databus in case security is enabledpublic ConsumerRecords poll(java.time.Duration timeout)
On each poll, consumer will try to use the last consumed offset as the starting offset and fetch sequentially.
The last
consumed offset can be manually set through Consumer.seek(TopicPartition, long)
or automatically set as the last
committed
offset for the subscribed list of partitions
This method returns immediately if there are records available. Otherwise, it will await the passed timeout.
If the timeout expires, an empty record set will be returned. Note that this method may block beyond the
timeout in order to execute custom ConsumerRebalanceListener
callbacks.
poll
in class Consumer<P>
timeout
- The time, in milliseconds, spent waiting in poll if data is not available. If 0, returns
immediately with any records that are available now. Must not be negative.public ConsumerRecords poll(long timeout)
On each poll, consumer will try to use the last consumed offset as the starting offset and fetch sequentially.
The last
consumed offset can be manually set through Consumer.seek(TopicPartition, long)
or automatically set as the
last committed
offset for the subscribed list of topicPartitions
poll
in class Consumer<P>
timeout
- The time, in milliseconds, spent waiting in poll if data is not available. If 0, returns
immediately with any records that are available now. Must not be negative.public DatabusPushConsumerFuture pushAsync(java.time.Duration timeout)
DatabusPushConsumerListener
instance which was passed
in the constructortimeout
- The time, in milliseconds, spent waiting in poll if data is not available. If 0, returns
immediately with any records that are available now. Must not be negative.DatabusClientRuntimeException
- if DatabusPushConsumer
is closed.public DatabusPushConsumerFuture pushAsync()
DatabusPushConsumerListener
instance which was passed
in the constructorpublic void close()
Consumer.close(Duration)
for details. Note that Consumer.wakeup()
cannot be used to interrupt close.