K
- the key type.V
- the outbound data type.R
- the reply data type.public class ReplyingKafkaTemplate<K,V,R> extends KafkaTemplate<K,V> implements BatchMessageListener<K,R>, org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean, ReplyingKafkaOperations<K,V,R>
Modifier and Type | Class and Description |
---|---|
static class |
ReplyingKafkaTemplate.TemplateRequestReplyFuture<K,V,R>
A listenable future for requests/replies.
|
KafkaOperations.OperationsCallback<K,V,T>, KafkaOperations.ProducerCallback<K,V,T>
logger
Constructor and Description |
---|
ReplyingKafkaTemplate(ProducerFactory<K,V> producerFactory,
GenericMessageListenerContainer<K,R> replyContainer) |
ReplyingKafkaTemplate(ProducerFactory<K,V> producerFactory,
GenericMessageListenerContainer<K,R> replyContainer,
boolean autoFlush) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected CorrelationKey |
createCorrelationId(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
Subclasses can override this to generate custom correlation ids.
|
void |
destroy() |
java.util.Collection<org.apache.kafka.common.TopicPartition> |
getAssignedReplyTopicPartitions()
Return the topics/partitions assigned to the replying listener container.
|
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isRunning() |
void |
onMessage(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,R>> data)
Invoked with data from kafka.
|
RequestReplyFuture<K,V,R> |
sendAndReceive(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
Send a request and receive a reply.
|
void |
setAutoStartup(boolean autoStartup) |
void |
setPhase(int phase) |
void |
setReplyTimeout(long replyTimeout) |
void |
setSharedReplyTopic(boolean sharedReplyTopic)
Set to true when multiple templates are using the same topic for replies.
|
void |
setTaskScheduler(org.springframework.scheduling.TaskScheduler scheduler) |
void |
start() |
void |
stop() |
void |
stop(java.lang.Runnable callback) |
closeProducer, doSend, execute, executeInTransaction, flush, getDefaultTopic, getMessageConverter, inTransaction, isTransactional, metrics, partitionsFor, send, send, send, send, send, send, sendDefault, sendDefault, sendDefault, sendDefault, sendOffsetsToTransaction, sendOffsetsToTransaction, setDefaultTopic, setMessageConverter, setProducerListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onMessage, wantsPollResult
onMessage, onMessage, onMessage
public ReplyingKafkaTemplate(ProducerFactory<K,V> producerFactory, GenericMessageListenerContainer<K,R> replyContainer)
public ReplyingKafkaTemplate(ProducerFactory<K,V> producerFactory, GenericMessageListenerContainer<K,R> replyContainer, boolean autoFlush)
public void setTaskScheduler(org.springframework.scheduling.TaskScheduler scheduler)
public void setReplyTimeout(long replyTimeout)
public boolean isRunning()
isRunning
in interface org.springframework.context.Lifecycle
public int getPhase()
getPhase
in interface org.springframework.context.Phased
getPhase
in interface org.springframework.context.SmartLifecycle
public void setPhase(int phase)
public boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void setAutoStartup(boolean autoStartup)
public java.util.Collection<org.apache.kafka.common.TopicPartition> getAssignedReplyTopicPartitions()
public void setSharedReplyTopic(boolean sharedReplyTopic)
sharedReplyTopic
- true if using a shared topic.public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void start()
start
in interface org.springframework.context.Lifecycle
public void stop()
stop
in interface org.springframework.context.Lifecycle
public void stop(java.lang.Runnable callback)
stop
in interface org.springframework.context.SmartLifecycle
public RequestReplyFuture<K,V,R> sendAndReceive(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
ReplyingKafkaOperations
sendAndReceive
in interface ReplyingKafkaOperations<K,V,R>
record
- the record to send.public void destroy()
destroy
in interface org.springframework.beans.factory.DisposableBean
protected CorrelationKey createCorrelationId(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
record
- the record.public void onMessage(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,R>> data)
GenericMessageListener
onMessage
in interface GenericMessageListener<java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<K,R>>>
data
- the data to be processed.