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 启动测试类的更多相关文章

  1. 【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 ...

  2. 【原创】kafka consumer源代码分析

    顾名思义,就是kafka的consumer api包. 一.ConsumerConfig.scala Kafka consumer的配置类,除了一些默认值常量及验证参数的方法之外,就是consumer ...

  3. 15.junit测试类使用及注解

    1.junit简介 JUnit是一个Java语言的单元测试框架,可以大大缩短你的测试时间和准确度.多数Java的开发环境都已经集成了JUnit作为单元测试的工具. 2.实现junitDemo示例 2. ...

  4. SpringBoot让测试类飞起来的方法

    单元测试是项目开发中必不可少的一环,在 SpringBoot 的项目中,我们用 @SpringBootTest 注解来标注一个测试类,在测试类中注入这个接口的实现类之后对每个方法进行单独测试. 比如下 ...

  5. kafka 消费者和生产者测试类

    pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...

  6. 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 ...

  7. kafka 安装以及测试

    1,下载kafka 并进行解压 http://mirrors.cnnic.cn/apache/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz 2,启动Zookeeper  ...

  8. Kafka设计解析(四)- Kafka Consumer设计解析

    本文转发自Jason’s Blog,原文链接 http://www.jasongj.com/2015/08/09/KafkaColumn4 摘要 本文主要介绍了Kafka High Level Con ...

  9. 【原创】Kafka Consumer多线程实例续篇

    在上一篇<Kafka Consumer多线程实例>中我们讨论了KafkaConsumer多线程的两种写法:多KafkaConsumer多线程以及单KafkaConsumer多线程.在第二种 ...

随机推荐

  1. EasyMock的使用

    1.Mock 方法是单元测试中常见的一种技术,它的主要作用是模拟一些在应用中不容易构造或者比较复杂的对象,从而把测试与测试边界以外的对象隔离开.同时也可以当调用别人的模块,而该模块又没有实现时(只提供 ...

  2. MySQL 设置慢查询为200ms

    1:查看当前版本并设置long_query_time为0.2 mysql> select version(); +------------+ | version() | +----------- ...

  3. MySQL_Oracle_事物的隔离级别

    数据库会话的设置: 1:脏读 情景:A事物读取B事物修改了但是未提交的数据 问题:若B回滚了事物,A就读到了错误数据. 2:不可重复读 情景:A事物查询数据,B修改了数据,A又查询数据 问题:A事物前 ...

  4. UVa 1303 - Wall

    题目:有非常多点.修一座最短的围墙把素有点围起来,使得全部点到墙的距离不小于l. 分析:计算几何,凸包. 假设.没有距离l的限制.则答案就是凸包的周长了.有了距离限制事实上是添加了2*π*l. 证明: ...

  5. 【Oracle】存储过程之完整篇

    1.语法 create [or replace] procedure pro_name[(parameter1,parameter2,...)] is|as begin plsql_sentences ...

  6. Web服务器(容器)请求常见的错误及其解决方法

    首先我们来看看容器如何找到service()方法?(1)当在浏览器中输入 http://localhost:8080/firstweb/sayHi 这个地址后,容器是如何找到 HelloServlet ...

  7. Android 线性布局(LinearLayout)相关官方文档 - 指南部分

    Android 线性布局(LinearLayout)相关官方文档 - 指南部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用 ...

  8. static不实现多态

    class Father { public static String getName() { return "father"; } } class Children extend ...

  9. 面试题 Comparable、Comparator 比较

    Comparable 用作默认的比较方式 Comparator 用作自定义的比较方式,当默认的比较方式不适用时或者没有提供默认的比较方式,使用Comparator就非常有用. 像Arrays和Coll ...

  10. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...