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
@Component | |
public class MessageListener { | |
private final Logger logger = LoggerFactory.getLogger(MessageListener.class); | |
@Value("${demo.consumerIdempotency:false}") | |
private boolean consumerIdempotencyEnabled; | |
@Autowired | |
private RedisService redisService; |
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
@Configuration | |
public class KafkaProducerConfig { | |
@Bean | |
public ProducerFactory<String, String> producerFactory() { | |
Map<String, Object> configProps = new HashMap<>(); | |
... | |
configProps.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true); | |
... |
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
@Service | |
public class EventProcessingService { | |
@Autowired | |
private OutboxRepository outboxRepository; | |
@Transactional | |
public void deleteProcessedEvents(List<Long> eventIds) { | |
if (!eventIds.isEmpty()) { | |
outboxRepository.deleteAllByIdIn(eventIds); |
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
@Service | |
public class EventPublisherService { | |
@Autowired | |
private OutboxRepository outboxRepository; | |
@Autowired | |
private KafkaTemplate<String, String> kafkaTemplate; | |
@Autowired |
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
@Service | |
public class EventPublisherService { | |
@Autowired | |
private OutboxRepository outboxRepository; | |
@Autowired | |
private KafkaTemplate<String, String> kafkaTemplate; | |
@Scheduled(fixedRate = 10000) // Every 10 seconds | |
public void publishEvents() { |
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
@RestController | |
public class MessageController { | |
@Autowired | |
private MessageRepository messageRepository; | |
@Autowired | |
private OutboxRepository outboxRepository; | |
private final ObjectMapper objectMapper = new ObjectMapper(); | |
@PostMapping("/messages") |
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
@Service | |
public class DataService { | |
@Autowired | |
private DatabaseRepository databaseRepository; | |
@Autowired | |
private KafkaTemplate<String, String> kafkaTemplate; | |
@Transactional |
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
package com.yazilimmimari.hackerrank; | |
import java.util.*; | |
public class RandomCache<S,T> { | |
HashMap<S,T> cache; | |
int capacity; | |
RandomCache(int capacity) { | |
cache = new HashMap<>(capacity); | |
this.capacity = capacity; |
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
package com.yazilimmimari.hackerrank; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
public class FIFOCache<S,T> { | |
LinkedHashMap<S,T> cache; | |
int capacity; | |
FIFOCache(int capacity) { | |
cache = new LinkedHashMap<>(capacity); |
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
package com.yazilimmimari.hackerrank; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.Objects; | |
public class LFUCache<S,T> { | |
public class Node<S,T> |
NewerOlder