中文 | English
Simple and easy-to-use high-performance template for Kafka message processing. Suggestions for modifications are welcome.
Managed by Spring Boot, simply implement your business logic to handle Kafka messages effortlessly.
Distributes messages to message queues based on topics and asynchronously processes them.
Suppose you need to process messages from a topic named create-news
. Follow these steps:
Define a channel in the config package, where the @ChannelBean
annotation indicates the name of the corresponding
topic.
@ChannelBean("create-news")
public Channel createChannel(){
return new MemoryChannel();
}
Define a MessageProcessor in the config package.
@ProcessorBean("create-news-processor")
public MessageProcessor createChannel(@Qualifier("create-news") Channel channel){
return new StringMessageProcessor(channel);
}
Implement MessageReceiver in the service package, then bind it to the channel using the @Sink
annotation.
@Component
@Slf4j
@Sink(bindTo = "create-news")
@RequiredArgsConstructor
public class NewsSaveToESSink implements MessageReceiver {
@Override
public void process(String message) {
log.info("NewsSaveToESSink");
}
}