Kafka Consumer 启动测试类
https://github.com/MarcoGhise/SpringKafka.git
- package it.demo.kafka.springkafka.listener;
- import org.springframework.beans.BeansException;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.integration.endpoint.EventDrivenConsumer;
- import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
- import org.springframework.integration.kafka.support.ConsumerConfiguration;
- import org.springframework.integration.kafka.support.KafkaConsumerContext;
- import com.yammer.metrics.Metrics;
- public class KafkaConsumerStarter implements ApplicationContextAware
- {
- private ApplicationContext appContext;
- private SourcePollingChannelAdapter kafkaInboundChannelAdapter;
- private KafkaConsumerContext kafkaConsumerContext;
- public void initIt() throws Exception
- {
- kafkaInboundChannelAdapter = appContext.getBean("kafka-inbound-channel-adapter", SourcePollingChannelAdapter.class);
- kafkaInboundChannelAdapter.start();
- kafkaConsumerContext = appContext.getBean("consumerContext", KafkaConsumerContext.class);
- }
- public void cleanUp() throws Exception
- {
- if (kafkaInboundChannelAdapter != null)
- {
- kafkaInboundChannelAdapter.stop();
- }
- Thread.sleep(1000);
- Metrics.defaultRegistry().shutdown();
- }
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
- {
- this.appContext = applicationContext;
- }
- }
Kafka Consumer 启动测试类的更多相关文章
- 【IntellJ IDEA】idea启动测试类报错Error running 'Test1.test': Command line is too long. Shorten command line for Test1.test or also for JUnit default configuration.
idea启动测试类报错 Error running 'Test1.test': Command line is too long. Shorten command line for Test1.tes ...
- 【原创】kafka consumer源代码分析
顾名思义,就是kafka的consumer api包. 一.ConsumerConfig.scala Kafka consumer的配置类,除了一些默认值常量及验证参数的方法之外,就是consumer ...
- 15.junit测试类使用及注解
1.junit简介 JUnit是一个Java语言的单元测试框架,可以大大缩短你的测试时间和准确度.多数Java的开发环境都已经集成了JUnit作为单元测试的工具. 2.实现junitDemo示例 2. ...
- SpringBoot让测试类飞起来的方法
单元测试是项目开发中必不可少的一环,在 SpringBoot 的项目中,我们用 @SpringBootTest 注解来标注一个测试类,在测试类中注入这个接口的实现类之后对每个方法进行单独测试. 比如下 ...
- kafka 消费者和生产者测试类
pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- kafka 安装以及测试
1,下载kafka 并进行解压 http://mirrors.cnnic.cn/apache/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz 2,启动Zookeeper ...
- Kafka设计解析(四)- Kafka Consumer设计解析
本文转发自Jason’s Blog,原文链接 http://www.jasongj.com/2015/08/09/KafkaColumn4 摘要 本文主要介绍了Kafka High Level Con ...
- 【原创】Kafka Consumer多线程实例续篇
在上一篇<Kafka Consumer多线程实例>中我们讨论了KafkaConsumer多线程的两种写法:多KafkaConsumer多线程以及单KafkaConsumer多线程.在第二种 ...
随机推荐
- ios 的 desciption
前段时间,终于将 ipa 文件打包完毕,上传appStore ,最后被打回,是因为 敏感的调用设备功能没有写描述. 有两种解决方式: A.直接修改 info.plist 文件 1.设置启动图标(CFB ...
- IntelliJ IDEA 2017.2.2 的破解 有效期 2116年
破解三部曲 下载破解文件 JetbrainsCrack-2.6.6-release-enc.jar http://idea.lanyus.com/jar/JetbrainsCrack-2.6.6- ...
- SettingsSVNPlugin
迁移时间:2017年5月20日11:24:50CreateTime--2016年9月18日17:53:20Author:Marydonmyeclipse/eclipse中配置svn插件参考链接:h ...
- 2、classpath、path、JAVA_HOME的作用
windows xp下配置JDK环境变量: 1.安装JDK,安装过程中可以自定义安装目录等信息,例如我们选择安装目录为D:\java\jdk1.5.0_08: 2.安装完成后,右击“我的电脑”,点击“ ...
- Linux下MySQL链接被防火墙阻止
Linux下安装了MySQL,不能从其它机器访问 帐号已经授权从任意主机进行访问 vi /etc/sysconfig/iptables 在后面添加 -A RH-Firewall-1-INPUT -m ...
- 关于 while(1)和for(;;)效率问题的一点想法
这几天看到好友的文章关于while(1)和for(;;)效率的讨论,手痒说了两句.回头一寻思,自己也仅仅是判断.没有做不论什么实验,我们就看看这两种写法究竟有什么差别: 实验环境:IAR EWARM ...
- Codeigniter base_url() 返回的怎么是ip地址
本篇文章由:http://xinpure.com/codeigniter-base-url-to-return-what-is-an-ip-address/ 简单说说情况 虽然也是有一段时间没有用过 ...
- 给定随机数列求第k大的数字
原来STL我还是有很多不知道的地方 STL 采用的算法是: 当数组长度 <= 3时, 采用插入排序. 当长度 > 3时, 采用快排 Partition 的思想,也就是说类似快速排序(这里不 ...
- 有效Log4j按指定级别定向输出日志到指定的输出文件地址配置Threshold,log4j中如何屏蔽父logger输出源rootlogger的additivity配置,log4j向多个文件记录日志
log4j向多个文件记录日志 关键配置,指定想要的日志级别信息输出到指定的日志文件中: log4j.appender.errorLogger.Threshold=ERROR #扩展,可指定只在子类自己 ...
- 越狱iphone在cydia下插件后出现exit safe mode肿么办小教程
http://bbs.app111.com/thread-318898-1-1.html 从简单的开始..最简单的点击状态栏会弹出来一个窗口,那窗口有三个选择请选择第二个,然后等待它重启,重启后还没消 ...