Issue
KafkaAutoConfiguration has kafkaTransactionManager
bean configured only if "spring.kafka.producer.transaction-id-prefix" property is set.
Is it ok to set this property for obtaining this autoconfigured bean in an application that just consumes data from a topic and doesn't have any producer logic?
I'm going to implement 1pc best effort pattern in my consumer app, so I need to have both kafkaTransactionManager
and JpaTransactionManager
in the context to use them with @Transactional
annotations.
Solution
If you don't use a producer side, then you don't need this KafkaTransactionManager
. Just inject that JpaTransactionManager
into the ContainerProperties
:
/**
* Set the transaction manager to start a transaction; offsets are committed with
* semantics equivalent to {@link AckMode#RECORD} and {@link AckMode#BATCH} depending
* on the listener type (record or batch).
* @param transactionManager the transaction manager.
* @since 1.3
* @see #setAckMode(AckMode)
*/
public void setTransactionManager(@Nullable PlatformTransactionManager transactionManager) {
Answered By - Artem Bilan
Answer Checked By - Timothy Miller (JavaFixing Admin)