码迷,mamicode.com
首页 > 其他好文 > 详细

Kafka Consumer 启动测试类

时间:2017-03-12 16:57:00      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:str   art   int   exce   https   pack   oid   启动   read   

https://github.com/MarcoGhise/SpringKafka.git

 1 package it.demo.kafka.springkafka.listener;
 2 
 3 import org.springframework.beans.BeansException;
 4 import org.springframework.context.ApplicationContext;
 5 import org.springframework.context.ApplicationContextAware;
 6 import org.springframework.integration.endpoint.EventDrivenConsumer;
 7 import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
 8 import org.springframework.integration.kafka.support.ConsumerConfiguration;
 9 import org.springframework.integration.kafka.support.KafkaConsumerContext;
10 
11 import com.yammer.metrics.Metrics;
12 
13 public class KafkaConsumerStarter implements ApplicationContextAware
14 {
15     private ApplicationContext appContext;
16     
17     private SourcePollingChannelAdapter kafkaInboundChannelAdapter;
18     
19     private KafkaConsumerContext kafkaConsumerContext;
20 
21     public void initIt() throws Exception
22     {
23         kafkaInboundChannelAdapter = appContext.getBean("kafka-inbound-channel-adapter", SourcePollingChannelAdapter.class);
24         kafkaInboundChannelAdapter.start();
25                 
26         kafkaConsumerContext = appContext.getBean("consumerContext", KafkaConsumerContext.class);
27     }
28 
29     public void cleanUp() throws Exception
30     {
31         if (kafkaInboundChannelAdapter != null)
32         {
33             kafkaInboundChannelAdapter.stop();
34         }
35         
36         Thread.sleep(1000);
37         
38         Metrics.defaultRegistry().shutdown();
39     }
40 
41     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
42     {
43         this.appContext = applicationContext;
44     }
45     
46 }

 

Kafka Consumer 启动测试类

标签:str   art   int   exce   https   pack   oid   启动   read   

原文地址:http://www.cnblogs.com/jun1019/p/6538157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!