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多线程.在第二种 ...
随机推荐
- logback.xml 文件
1.logback.xml <?xml version="1.0" encoding="UTF-8"?> <configuration> ...
- 全局安装 vue
通过npm命令安装vuejs在用 Vue.js 构建大型应用时推荐使用 NPM 安装,NPM 能很好地和诸如 Webpack 或Browserify 的 CommonJS 模块打包器配合使用.(以下操 ...
- $stateParams 详解
如何传递参数(参考 http://www.cnblogs.com/jager/p/5293225.html) 首先,要在目标页面定义接受的参数: 传参, ui-sref: $state.go: 接收 ...
- springmvc ModelAndView 和 Model
@RequestMapping("") public ModelAndView index(HttpSession session) { Object data = session ...
- mysql中innodb和myisam的区别
InnoDB和MyISAM是很多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,5.7之后就不一样了 1.事务和外键 InnoDB具有事务,支持4个事务隔离级别,回滚,崩溃修复能力和多版 ...
- java.lang.NoClassDefFoundError: Could not initialize class com.demo.jdbc.utils.MyJdbcUtils
jdbc编写工具类的过程中测试失败, 出现如下错误: 原因:初始化的过程中执行静态代码块的过程中出现错误, 也就是说, 加载配置文件错误: 没有加载到指定路径的配置文件. 我的MyJdbcUtil ...
- 手机imie号介绍使用
http://zhidao.baidu.com/question/3682744.html手机机身号又叫手机串号,是国际移动设备识别码,GSM手机机身号简称IMEI,CDMA手机机身号简称ESN. 一 ...
- AsyncTask与ProgressDialog使用笔记(安卓在背景运行耗时任务)
AsyncTask用在需要在ui线程中调用.在背景线程中执行耗时任务.并且在ui线程中返回结果的场合.下面就是一个在背景中运行的AsyncTask的实现DownloadDBTask, Android中 ...
- WCF 的 WebGet 方式
.NET 3.5以后,WCF中提供了WebGet的方式,允许通过url的形式进行Web 服务的访问.在以前的代码中,写过多次类似的例子,但总是忘记如何配置,现在将设置步骤记录如下: endpoint通 ...
- 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.'
产生这个错误的原因是,StaticResource必须先定义再引用,但是DynamicResource就没有这个限制,为避免这个错误出现,可将StaticResource的定义放在Window.xam ...