Kafka Cluster 2019(3)Spring Boot Kafka
Support more complex object other than String
https://codenotfound.com/spring-kafka-apache-avro-serializer-deserializer-example.html
https://codenotfound.com/spring-kafka-json-serializer-deserializer-example.html
More Option to support in the YAML configuration
https://github.com/spring-projects/spring-boot/blob/v2.1.6.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java
It supports the Object as well, I just use string for my performance check here
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html#boot-features-kafka
Here is the pom.xml change
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
I just like to use interface, so I define an interface there
package com.sillycat.mvclatency.service;
public interface KafkaService {
public void send(String payload);
}
The implementation class is as follow:
package com.sillycat.mvclatency.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class KafkaServiceImpl implements KafkaService {
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send(String payload) {
log.info("sending payload='{}'", payload);
kafkaTemplate.send("helloworld.mvc", payload);
}
@KafkaListener(topics = "helloworld.mvc")
public void receive(String payload) {
log.info("received payload='{}'", payload);
}
}
It will use the kafkaTemplate to send out message, and @KafkaListener to consume the messages.
Here is the related configuration
spring:
kafka:
consumer:
group-id: mvccluster
bootstrap-servers: ubuntu-master:9092, ubuntu-dev2:9092, ubuntu-dev4:9092
That is it. We can have more configurations, but I just want to compare it with reactive, so I just directly use the simple String one.
References:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html#boot-features-kafka
https://codenotfound.com/spring-kafka-consumer-producer-example.html
https://www.e4developer.com/2018/05/21/getting-started-with-kafka-in-spring-boot/
https://codar.club/blogs/reactor-kafka-via-spring-boot-webflux.html
https://github.com/reactor/reactor-kafka
Sample Projects
https://github.com/bjedrzejewski/kafkaintro
https://github.com/TechPrimers/spring-boot-kafka-producer-example
https://github.com/CloudKarafka/springboot-kafka-example
https://www.jianshu.com/p/d811f7421e71
分享到:
相关推荐
使用Spring Initializr或者Spring CLI创建一个新的SpringBoot项目,添加`spring-boot-starter-web`和`spring-kafka`依赖。确保`pom.xml`或`build.gradle`文件中包含这些依赖。 ### 5. 配置Kafka在SpringBoot中的...
最近学习springboot吧...其中包括mybatis,cfx的webservice,定时器quartz,消息队列kafka以及redis其中redis包含了三种连接方式(单机模式,集群cluster,哨兵模式),给大家做一个参考 希望能让别人学习时少走弯路
SpringCloud 是一个基于 Spring Boot 实现的云应用开发工具集,它为开发者提供了在分布式系统(如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、分布式会话、集群状态)...
simple,cluster,zookeeper,kafka客户端支持 同步异步处理支持 spring boot 开箱即用 如何使用 spring boot 方式 maven 依赖 <groupId>top.javatool <artifactId>canal-spring-boot-starter <version>1.2.1-RELEASE ...
,例如Spring Boot应用程序测试,性能测试,Kotlin应用程序测试等。 要运行以下测试,请跳至相应的JUnit @Test。 @TargetEnv ( " kafka_servers/kafka_test_server.properties " ) @RunWith ( ZeroCodeUnitRunner...
本主题将深入探讨Java的新特性,特别是针对Spring Boot 2.x、Redis和Kafka这三个关键组件的测试实践。 首先,Spring Boot 2.x是Spring框架的一个子项目,旨在简化Java应用程序的开发过程。它通过默认配置、自动配置...
Spring Cloud 是一个基于 Spring Boot 实现的云应用开发工具集,它为开发人员提供了在分布式系统(如配置管理、服务发现、断路器、负载均衡、熔断机制、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、...
3. **数据库设计**: 设备管理可能涉及到实体如`Device`、`Cluster`、`User`等,需要设计合理的数据库模式来存储和查询设备信息。 4. **安全认证**: Spring Security可以用来实现用户认证和授权,保护API接口,防止...
它基于Spring Boot的约定优于配置的理念,使得开发人员能够快速搭建出具备上述功能的微服务应用。 1. **服务发现**:在微服务架构中,服务发现是关键。Spring Cloud Netflix Eureka 提供了服务注册与发现的功能。...
- Spring Boot特性及快速开发优势。 3. **Spring Cloud**: - Eureka服务注册与发现。 - Ribbon客户端负载均衡。 - Hystrix熔断器,防止服务雪崩。 - Zuul或Spring Cloud Gateway作为API网关。 - Spring ...
在Java领域,常见的分布式技术包括分布式缓存(如Redis)、分布式数据库(如MySQL Cluster)、分布式消息队列(如RabbitMQ或Kafka)以及负载均衡(如Nginx)。这些技术能够实现数据的分布式存储和计算,确保服务在...
1. Spring Boot:简化了Spring应用的初始搭建和配置,自动配置特性。 2. Spring Cloud:为微服务提供一套完整的解决方案,包括服务发现、配置中心、断路器、路由、熔断等。 3. Spring Data:简化数据库操作,支持JPA...
### 数据源管理与分布式NoSQL系统——Cassandra集群管理 #### Cassandra简介 ...通过本文介绍的环境搭建步骤,用户能够快速搭建起Cassandra集群,并结合Spring Boot框架进行高效的数据管理和应用程序开发。
3. **Spring框架**:Spring的核心是依赖注入(DI),Bean的生命周期包括初始化、使用和销毁。Spring Boot简化了Spring的应用启动,它集成了许多默认配置。Spring AOP用于面向切面编程,事务管理支持编程式和声明式。...
对于Spring Boot、Spring Cloud等相关技术也有一定的了解要求。 7. **其他技术**:面试可能会涵盖NIO(非阻塞I/O)、Netty框架、消息队列(如RocketMQ、Kafka)的原理及其应用,以及网络编程、分布式通信等相关知识...
- **Spring框架**:依赖注入(DI),AOP面向切面编程,Spring Boot的自动配置。 - **MyBatis**:动态SQL,Mapper接口,事务管理,结果映射。 - **Spring Cloud**:服务发现(Eureka)、API网关(Zuul或Gateway)...
- **Spring Boot/Spring Cloud**:Spring Boot简化了Java应用的开发和配置过程;Spring Cloud则提供了构建微服务架构所需的一系列工具和服务。 - **数据库选型**:根据业务需求,可以选择关系型数据库如MySQL或NoSQL...
2. **后端基础**:涵盖数据库设计、SQL优化、事务处理、索引原理、JDBC操作,以及Spring Boot/Spring Cloud等主流框架的使用和原理。 3. **Redis缓存**:Redis的常用数据类型(String、List、Set、Hash、Sorted Set...
框架能提高开发效率,如Spring框架的依赖注入(DI)、面向切面编程(AOP),以及Spring Boot和Spring Cloud在微服务开发中的应用。还要理解MVC设计模式,以及Struts、Hibernate等其他Java Web框架。对于前端框架,如...