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多线程.在第二种 ...
随机推荐
- PHPCMS V9 加密规则
PHPCMS V9 加密规则 相关表:v9_admin 加密方式: md5(md5(password)+encrypt) 第一步:对输入的密码32位小写 MD5 对输入的密码进行trim过滤 第二 ...
- vue 常见报错问题
情况一:http://eslint.org/docs/rules/no-tabs Unexpected tab character 解决方案:缩进是4个空格,而不是tab,设置indent 情况二 ...
- 安装调试Installing Odoo
来自odoo的安装步骤 There are mutliple ways to install Odoo, or not install it at all, depending on the inte ...
- [Unity-1] Unity简单介绍
Unity是一套包含图形.声音.物理等功能的游戏引擎,提供了一个强大的关卡编辑器.支持大部分主流3D软件格式,使用C#或者JavaScript等高级语言实现脚本功能.使开发人员无需了解底层复杂技术,高 ...
- /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 错误:
在安装tomcat时报了错: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 本机环境: [root@AY1405 ...
- HTTP协议详解之User Agent篇
•User Agent:用户代理 指浏览器他的信息包括硬件平台.系统软件.应用软件和用户个人偏好.用户代理不仅仅指浏览器,还包括搜索引擎. •为什么所有浏览器的User Agent都带有Mozilla ...
- java beanUtils框架
beanUtils是Apache觉得sun公司的内省不够爽,自己又开发了一套可以操作JavaBean的API 所以beanUtils是第三方jar包,使用beanUtils要导包: 在工程目录下新建一 ...
- java 正则举例
Greedy 数量词 X? X,一次或一次也没有 X* X,零次或多次 X+ X,一次或多次 X{n} X,恰好 n 次 X{n,} X,至少 n 次 X{n,m} X,至少 n 次,但是不超过 m ...
- 判断是否为SIM卡联系人
判断是否为SIM卡联系人 在AsyncQueryContacts类中. private List<TxrjAccount> accounts = new ArrayList<Txrj ...
- jquery ajax例子
(1)取得服务端当前时间 jquery对象.load(url,sendData,function(backData,textStatus,xhr){... ...}) load():如果无参的话,就以 ...