`
sillycat
  • 浏览: 2527494 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Kafka Cluster 2019(3)Spring Boot Kafka

 
阅读更多
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

分享到:
评论

相关推荐

    SpringBoot 整合Kafka实现消息的发送和接收

    使用Spring Initializr或者Spring CLI创建一个新的SpringBoot项目,添加`spring-boot-starter-web`和`spring-kafka`依赖。确保`pom.xml`或`build.gradle`文件中包含这些依赖。 ### 5. 配置Kafka在SpringBoot中的...

    SpringBoot集成Redis,Webservice,kafka,quartz,mybatis例子

    最近学习springboot吧...其中包括mybatis,cfx的webservice,定时器quartz,消息队列kafka以及redis其中redis包含了三种连接方式(单机模式,集群cluster,哨兵模式),给大家做一个参考 希望能让别人学习时少走弯路

    springcloud学习笔记.docx

    SpringCloud 是一个基于 Spring Boot 实现的云应用开发工具集,它为开发者提供了在分布式系统(如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、分布式会话、集群状态)...

    java看源码看不到-canal-client:springbootcanalstarter易用的canal客户端canalclient

    simple,cluster,zookeeper,kafka客户端支持 同步异步处理支持 spring boot 开箱即用 如何使用 spring boot 方式 maven 依赖 &lt;groupId&gt;top.javatool &lt;artifactId&gt;canal-spring-boot-starter &lt;version&gt;1.2.1-RELEASE ...

    springCloud

    ActiveMQ Kafka RabbitMQ RocketMQ 目前Spring Cloud Bus 支持 RabbitMQ 和 Kafka,spring-cloud-starter-bus-amqp 、spring-cloud-starter-bus-kafka RabbitMQ简介 RabbitMQ是一个开源的AMQP实现,服务器端用...

    hello-kafka-stream-testing:在HBaseHadoop或其他数据提取管道中测试基于Kafka的应用程序或微服务(例如ReadWrite)的最简单方法

    ,例如Spring Boot应用程序测试,性能测试,Kotlin应用程序测试等。 要运行以下测试,请跳至相应的JUnit @Test。 @TargetEnv ( " kafka_servers/kafka_test_server.properties " ) @RunWith ( ZeroCodeUnitRunner...

    feat-test:Java的新功能测试,例如springboot2.x,redis和kafka。

    本主题将深入探讨Java的新特性,特别是针对Spring Boot 2.x、Redis和Kafka这三个关键组件的测试实践。 首先,Spring Boot 2.x是Spring框架的一个子项目,旨在简化Java应用程序的开发过程。它通过默认配置、自动配置...

    SpringCloud示例代码

    Spring Cloud 是一个基于 Spring Boot 实现的云应用开发工具集,它为开发人员提供了在分布式系统(如配置管理、服务发现、断路器、负载均衡、熔断机制、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、...

    Java &amp; Vue.js 全栈「集群设备管理云平台『后端部分』.zip

    3. **数据库设计**: 设备管理可能涉及到实体如`Device`、`Cluster`、`User`等,需要设计合理的数据库模式来存储和查询设备信息。 4. **安全认证**: Spring Security可以用来实现用户认证和授权,保护API接口,防止...

    微服务 (第二部分)springcould_17

    它基于Spring Boot的约定优于配置的理念,使得开发人员能够快速搭建出具备上述功能的微服务应用。 1. **服务发现**:在微服务架构中,服务发现是关键。Spring Cloud Netflix Eureka 提供了服务注册与发现的功能。...

    java面试知识点整理.zip

    - Spring Boot特性及快速开发优势。 3. **Spring Cloud**: - Eureka服务注册与发现。 - Ribbon客户端负载均衡。 - Hystrix熔断器,防止服务雪崩。 - Zuul或Spring Cloud Gateway作为API网关。 - Spring ...

    聚焦高并发、分布式集群、微服务架构迭代的互联网电商项目(Java技术栈).zip

    在Java领域,常见的分布式技术包括分布式缓存(如Redis)、分布式数据库(如MySQL Cluster)、分布式消息队列(如RabbitMQ或Kafka)以及负载均衡(如Nginx)。这些技术能够实现数据的分布式存储和计算,确保服务在...

    架构师最新面试专题.zip

    1. Spring Boot:简化了Spring应用的初始搭建和配置,自动配置特性。 2. Spring Cloud:为微服务提供一套完整的解决方案,包括服务发现、配置中心、断路器、路由、熔断等。 3. Spring Data:简化数据库操作,支持JPA...

    数据源管理 分布式NoSQL系统,Cassandra集群管理.docx

    ### 数据源管理与分布式NoSQL系统——Cassandra集群管理 #### Cassandra简介 ...通过本文介绍的环境搭建步骤,用户能够快速搭建起Cassandra集群,并结合Spring Boot框架进行高效的数据管理和应用程序开发。

    java面试题目整理需要的可以打印练习

    3. **Spring框架**:Spring的核心是依赖注入(DI),Bean的生命周期包括初始化、使用和销毁。Spring Boot简化了Spring的应用启动,它集成了许多默认配置。Spring AOP用于面向切面编程,事务管理支持编程式和声明式。...

    6面阿里 P6+面经1

    对于Spring Boot、Spring Cloud等相关技术也有一定的了解要求。 7. **其他技术**:面试可能会涵盖NIO(非阻塞I/O)、Netty框架、消息队列(如RocketMQ、Kafka)的原理及其应用,以及网络编程、分布式通信等相关知识...

    java常用技术面试问题整理

    - **Spring框架**:依赖注入(DI),AOP面向切面编程,Spring Boot的自动配置。 - **MyBatis**:动态SQL,Mapper接口,事务管理,结果映射。 - **Spring Cloud**:服务发现(Eureka)、API网关(Zuul或Gateway)...

    玩转电商系统 深入剖析智慧电商平台_完整版 PDF电子书下载 带书签目录

    - **Spring Boot/Spring Cloud**:Spring Boot简化了Java应用的开发和配置过程;Spring Cloud则提供了构建微服务架构所需的一系列工具和服务。 - **数据库选型**:根据业务需求,可以选择关系型数据库如MySQL或NoSQL...

    大厂超级详细的Java面试题.zip

    2. **后端基础**:涵盖数据库设计、SQL优化、事务处理、索引原理、JDBC操作,以及Spring Boot/Spring Cloud等主流框架的使用和原理。 3. **Redis缓存**:Redis的常用数据类型(String、List、Set、Hash、Sorted Set...

Global site tag (gtag.js) - Google Analytics