K
- the key type.V
- the value type.
If the Kafka topic is set with CreateTime
all send operations will use the user provided time if provided, else
KafkaProducer
will generate one
If the topic is set with LogAppendTime
then the user provided timestamp will be ignored and instead will be the
Kafka broker local time when the message is appendedpublic interface KafkaOperations<K,V>
ListenableFuture
s.Modifier and Type | Interface and Description |
---|---|
static interface |
KafkaOperations.OperationsCallback<K,V,T>
A callback for executing arbitrary operations on the
KafkaOperations . |
static interface |
KafkaOperations.ProducerCallback<K,V,T>
A callback for executing arbitrary operations on the
Producer . |
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(KafkaOperations.ProducerCallback<K,V,T> callback)
Execute some arbitrary operation(s) on the producer and return the result.
|
<T> T |
executeInTransaction(KafkaOperations.OperationsCallback<K,V,T> callback)
Execute some arbitrary operation(s) on the operations and return the result.
|
void |
flush()
Flush the producer.
|
java.util.Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> |
metrics()
See
Producer.metrics() . |
java.util.List<org.apache.kafka.common.PartitionInfo> |
partitionsFor(java.lang.String topic)
See
Producer.partitionsFor(String) . |
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(org.springframework.messaging.Message<?> message)
Send a message with routing information in message headers.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
Send the provided
ProducerRecord . |
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(java.lang.String topic,
java.lang.Integer partition,
K key,
V data)
Send the data to the provided topic with the provided key and partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(java.lang.String topic,
java.lang.Integer partition,
java.lang.Long timestamp,
K key,
V data)
Send the data to the provided topic with the provided key and partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(java.lang.String topic,
K key,
V data)
Send the data to the provided topic with the provided key and no partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
send(java.lang.String topic,
V data)
Send the data to the provided topic with no key or partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
sendDefault(java.lang.Integer partition,
K key,
V data)
Send the data to the default topic with the provided key and partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
sendDefault(java.lang.Integer partition,
java.lang.Long timestamp,
K key,
V data)
Send the data to the default topic with the provided key and partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
sendDefault(K key,
V data)
Send the data to the default topic with the provided key and no partition.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> |
sendDefault(V data)
Send the data to the default topic with no key or partition.
|
void |
sendOffsetsToTransaction(java.util.Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets)
When running in a transaction (usually synchronized with some other transaction),
send the consumer offset(s) to the transaction.
|
void |
sendOffsetsToTransaction(java.util.Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets,
java.lang.String consumerGroupId)
When running in a transaction (usually synchronized with some other transaction),
send the consumer offset(s) to the transaction.
|
org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> sendDefault(V data)
data
- The data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> sendDefault(K key, V data)
key
- the key.data
- The data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> sendDefault(java.lang.Integer partition, K key, V data)
partition
- the partition.key
- the key.data
- the data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> sendDefault(java.lang.Integer partition, java.lang.Long timestamp, K key, V data)
partition
- the partition.timestamp
- the timestamp of the record.key
- the key.data
- the data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(java.lang.String topic, V data)
topic
- the topic.data
- The data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(java.lang.String topic, K key, V data)
topic
- the topic.key
- the key.data
- The data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(java.lang.String topic, java.lang.Integer partition, K key, V data)
topic
- the topic.partition
- the partition.key
- the key.data
- the data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(java.lang.String topic, java.lang.Integer partition, java.lang.Long timestamp, K key, V data)
topic
- the topic.partition
- the partition.timestamp
- the timestamp of the record.key
- the key.data
- the data.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
ProducerRecord
.record
- the record.SendResult
.org.springframework.util.concurrent.ListenableFuture<SendResult<K,V>> send(org.springframework.messaging.Message<?> message)
message
- the message to send.SendResult
.KafkaHeaders.TOPIC
,
KafkaHeaders.PARTITION_ID
,
KafkaHeaders.MESSAGE_KEY
java.util.List<org.apache.kafka.common.PartitionInfo> partitionsFor(java.lang.String topic)
Producer.partitionsFor(String)
.topic
- the topic.java.util.Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics()
Producer.metrics()
.<T> T execute(KafkaOperations.ProducerCallback<K,V,T> callback)
T
- the result type.callback
- the callback.<T> T executeInTransaction(KafkaOperations.OperationsCallback<K,V,T> callback)
T
- the result type.callback
- the callback.void flush()
void sendOffsetsToTransaction(java.util.Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets)
ProducerFactoryUtils.getConsumerGroupId()
. It is not necessary to call
this method if the operations are invoked on a listener container thread since the
container will take care of sending the offsets to the transaction.offsets
- The offsets.void sendOffsetsToTransaction(java.util.Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets, java.lang.String consumerGroupId)
offsets
- The offsets.consumerGroupId
- the consumer's group.id.