SpringCloud Stream简单笔记

news/2025/2/13 20:11:27/
  1. 添加kafka stream依赖

    <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-stream</artifactId>
    </dependency>
    <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-stream-binder-kafka</artifactId>
    </dependency>
    
  2. application.yml中添加配置

    --- #stream config
    spring:cloud:stream:binders:myKafka1:type: kafkaenvironment:spring:kafka:bootstrap-servers: 127.0.0.1:9092bindings:helloFunc-in-0:destination: hello-topicgroup: hello-local-test-10binder: myKafka1consumer:batch-mode: truehelloFunc-out-0:destination: hello-topicgroup: hello-local-test-10binder: myKafka1consumer:batch-mode: true# 注意 function 节点与stream 同级,而非子节点function:definition: helloFunc;
    
  3. 编写消费者:

    @Slf4j
    @Component
    @RequiredArgsConstructor
    public class HelloConsumer {@Beanpublic Consumer<Message<List<String>>> helloFunc() {return message -> {log.info("---------------------> ");List<String> list = message.getPayload();boolean result = this.handle(list);if (result) {Acknowledgment acknowledgment = message.getHeaders().get(KafkaHeaders.ACKNOWLEDGMENT, Acknowledgment.class);if (acknowledgment != null) {acknowledgment.acknowledge();}} else {throw new RuntimeException("消费数据出错!");}};}private boolean handle(List<String> list){log.info("list size : {}", list.size());if (!CollectionUtils.isEmpty(list)){log.info("group first message : {}", list.get(0));}return true ;}
    }
    

http://www.ppmy.cn/news/1379290.html

相关文章

crossover玩不了qq游戏大厅怎么办 仍有五亿人坚持用QQ crossover玩游戏 Mac电脑玩QQ游戏

从1999年2月&#xff0c;QQ首个版本QICQ&#xff08;OPEN-ICQ&#xff09;上线。到2024年&#xff0c;靠着5亿月活用户&#xff0c;守住社交领域TOP2位置。你还记得QQ经典的铃声吗&#xff1f; 根据月狐数据2023年12月的统计&#xff0c;QQ月活跃账户数比微博和知乎加在一起还要…

Everything:文件查找工具,一搜即得

名人说&#xff1a;东边日出西边雨&#xff0c;道是无晴却有晴。——刘禹锡 创作者&#xff1a;Code_流苏(CSDN)&#xff08;一个喜欢古诗词和编程的Coder&#x1f60a;&#xff09; 目录 一、软件介绍①Everything②核心功能③原理 二、下载安装①下载②安装 三、使用方法①文…

Java面试题(主要分清区别!!!)

RequestBody和ResponseBody的区别&#xff1f; RequestBody&#xff1a;接收json或xml数据 ResponseBody的&#xff1a;返回json或xml数据 RestController和Controller的区别&#xff1f; Controller&#xff1a;默认返回的是jsp页面 RestController&#xff1a;返回的是一个js…

Autosar Crypto Driver学习笔记(一)

文章目录 Crypto DriverPre-ConfigurationCryptographic capabilities加密能力Available Keys可用密钥 General BehaviorNormal OperationFunctional RequirementsSynchronous Job ProcessingAsynchronous Job Processing Design NotesPriority-dependent Job Queue基于优先级的…

可免费使用的AI平台汇总 + 常用赋能科研的AI工具推荐

赋能科研&#xff0c;AI工具助你飞跃学术巅峰&#xff01;(推荐收藏) 文章目录 赋能科研&#xff0c;AI工具助你飞跃学术巅峰&#xff01;(推荐收藏)一、可免费使用的AI平台汇总1. ChatGPT2. New Bing3. Slack4. POE5. Vercel6. 其他平台7. 特定功能平台8. 学术资源平台9. 中文…

NXP iMX8MM Cortex-M4 核心 GPT Capture 测试

By Toradex秦海 1). 简介 NXP i.MX8 系列处理器均为异构多核架构 SoC&#xff0c;除了可以运行 Linux 等复杂操作系统的 Cortax-A 核心&#xff0c;还包含了可以运行实时操作系统比如 FreeRTOS 的 Cortex-M 核心&#xff0c;本文就演示通过 NXP i.MX8MM 处理器集成的 Cortex-…

Elasticsearch 通过索引阻塞实现数据保护深入解析

目录 前言 1、索引阻塞的种类 2、什么时候使用阻塞&#xff1f; 场景1&#xff1a;进行系统维护场景。 场景2&#xff1a;保护数据不被随意更改场景。 场景3&#xff1a;优化资源使用的场景。 场景4&#xff1a;遵守安全规则场景。 3、添加索引阻塞API 4、解除设置 AP…

讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so

1.需求 最近linux下的Qt项目中要连接oracle数据库&#xff0c;用户需要我们访问他们的oracle数据库&#xff0c;查询数据 2.遇到的问题 qt连接oracle数据库需要oracle的驱动库libqsqloci.so插件&#xff0c;需要编译下&#xff0c;之前没有编译过&#xff0c;看了网上的…