If you consume messages from one topic, transform and publish to other topics Kafka Stream is best suited.
Real-time processing, real-time analytics, and Machine learning.
Stateful transformation such as aggregation, join window, etc.
Supports exactly-once processing semantics via Kafka transactions (what EOS means)
Supports fault-tolerant stateful (as well as stateless, of course) processing including streaming joins, aggregations, and windowing. In other words, it supports management of your application's processing state out-of-the-box.
Supports event-time processing as well as processing based on processing-time and ingestion-time. It also seamlessly processes out-of-order data.
Has first-class support for both streams and tables, which is where stream processing meets databases; in practice, most stream processing applications need both streams AND tables for implementing their respective use cases, so if a stream processing technology lacks either of the two abstractions (say, no support for tables) you are either stuck or must manually implement this functionality yourself (good luck with that...)
Supports interactive queries (also called 'queryable state') to expose the latest processing results to other applications and services via a request-response API. This is especially useful for traditional apps that can only do request-response, but not the streaming side of things.
Is more expressive: it ships with (1) a functional programming style DSL with operations such as map, filter, reduce as well as (2) an imperative style Processor API for e.g. doing complex event processing (CEP), and (3) you can even combine the DSL and the Processor API.
Has its own testing kit for unit and integration testing.
xxxxxxxxxx
@Service("bookingService")
public class BookingServiceImpl extends BaseService<Booking, String>
implements BookingService {
private BookingRepository<Booking, String> bookingRepository;
/**
*
* @param bookingRepository
*/
@Autowired
public BookingServiceImpl(BookingRepository<Booking, String> bookingRepository) {
super(bookingRepository);
this.bookingRepository = bookingRepository;
}
@Override
public void add(Booking booking) throws Exception {
if (bookingRepository.containsName(booking.getName())) {
throw new Exception(String.format("There is already a product with the name - %s", booking.getName()));
}
if (booking.getName() == null || "".equals(booking.getName())) {
throw new Exception("Booking name cannot be null or empty string.");
}
super.add(booking);
}
@Override
public Collection<Booking> findByName(String name) throws Exception {
return bookingRepository.findByName(name);
}
@Override
public void update(Booking booking) throws Exception {
bookingRepository.update(booking);
}
@Override
public void delete(String id) throws Exception {
bookingRepository.remove(id);
}
@Override
public Entity findById(String id) throws Exception {
return bookingRepository.get(id);
}
@Override
public Collection<Booking> findByCriteria(Map<String, ArrayList<String>> name) throws Exception {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
https://stackoverflow.com/questions/44014975/kafka-consumer-api-vs-streams-api
xxxxxxxxxx
Kafka real time use cases
Let's look at the most common use cases of Apache Kafka.
Activity tracking. This was the original use case for Kafka.
Real-time data processing. Many systems require data to be processed as soon as it becomes available.
Messaging.
Operational Metrics/KPIs.
Log Aggregation.
“Little” Data.
Streaming ETL.