Skip to content

Instantly share code, notes, and snippets.

@serdarmumcu
Last active March 28, 2024 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serdarmumcu/93214764602f0a90ce3d28bdb7e1efb7 to your computer and use it in GitHub Desktop.
Save serdarmumcu/93214764602f0a90ce3d28bdb7e1efb7 to your computer and use it in GitHub Desktop.
@Service
public class DataService {
@Autowired
private DatabaseRepository databaseRepository;
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
@Transactional
public void updateDataAndPublishEvent(String data) {
databaseRepository.save(new DataEntity(data)); // Database operation
kafkaTemplate.send("topicName", "Data updated event"); // Kafka event publishing
// The above operations are not atomically consistent, risking data inconsistency.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment