-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented kafka transaction for multiple partitions (#70)
* Implemented kafka transaction for multiple partitions * Added new producer file for transformer * [Hot Fix] - Topic Partition cont get from env file
- Loading branch information
1 parent
4b26409
commit fd1ddc9
Showing
6 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/uci/orchestrator/Service/TransformerProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.uci.orchestrator.Service; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.kafka.support.SendResult; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.util.concurrent.ListenableFutureCallback; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Service | ||
@Slf4j | ||
public class TransformerProducer { | ||
@Qualifier("transactionalKafkaTemplate") | ||
private final KafkaTemplate<String, String> transactionalKafkaTemplate; | ||
|
||
public TransformerProducer(KafkaTemplate<String, String> transactionalKafkaTemplate) { | ||
this.transactionalKafkaTemplate = transactionalKafkaTemplate; | ||
} | ||
|
||
@Transactional | ||
public void sendTransaction(String topic, String message) { | ||
transactionalKafkaTemplate | ||
.send(topic, message) | ||
.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { | ||
@Override | ||
public void onFailure(@NotNull Throwable throwable) { | ||
log.error("Kafka::Send:Exception: Unable to push topic {} message {} due to {}", topic, message, throwable.getMessage()); | ||
} | ||
|
||
@Override | ||
public void onSuccess(SendResult<String, String> stringStringSendResult) { | ||
log.info("Kafka::Send: Pushed to topic {}", topic); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters