zoukankan      html  css  js  c++  java
  • kafka consumer demo

    kafka消费者demo

    pom文件

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <project xmlns="http://maven.apache.org/POM/4.0.0"
      3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5     <modelVersion>4.0.0</modelVersion>
      6 
      7     <groupId>com.donfaquir.kafka</groupId>
      8     <artifactId>consumer-demo</artifactId>
      9     <version>1.0-SNAPSHOT</version>
     10     <packaging>jar</packaging>
     11 
     12     <dependencies>
     13         <dependency>
     14             <groupId>org.apache.kafka</groupId>
     15             <artifactId>kafka_2.10</artifactId>
     16             <!-- 如果版本和kafka版本不匹配,会出现消费不到数据的问题 -->
     17             <version>0.9.0.0</version>
     18             <exclusions>
     19                 <exclusion>
     20                     <groupId>org.apache.zookeeper</groupId>
     21                     <artifactId>zookeeper</artifactId>
     22                 </exclusion>
     23                 <exclusion>
     24                     <groupId>log4j</groupId>
     25                     <artifactId>log4j</artifactId>
     26                 </exclusion>
     27                 <exclusion>
     28                     <groupId>org.slf4j</groupId>
     29                     <artifactId>slf4j-log4j12</artifactId>
     30                 </exclusion>
     31                 <exclusion>
     32                     <groupId>org.slf4j</groupId>
     33                     <artifactId>slf4j-api</artifactId>
     34                 </exclusion>
     35             </exclusions>
     36         </dependency>
     37        <!-- <dependency>
     38             <groupId>log4j</groupId>
     39             <artifactId>log4j</artifactId>
     40             <version>1.2.17</version>
     41         </dependency>-->
     42         <dependency>
     43             <groupId>org.apache.zookeeper</groupId>
     44             <artifactId>zookeeper</artifactId>
     45             <version>3.4.6</version>
     46             <exclusions>
     47                 <exclusion>
     48                     <groupId>org.slf4j</groupId>
     49                     <artifactId>slf4j-log4j12</artifactId>
     50                 </exclusion>
     51                 <exclusion>
     52                     <groupId>org.slf4j</groupId>
     53                     <artifactId>slf4j-api</artifactId>
     54                 </exclusion>
     55             </exclusions>
     56         </dependency>
     57         <!-- fastjson -->
     58         <dependency>
     59             <groupId>com.alibaba</groupId>
     60             <artifactId>fastjson</artifactId>
     61             <version>1.2.11</version>
     62         </dependency>
     63 
     64         <dependency>
     65             <groupId>org.slf4j</groupId>
     66             <artifactId>slf4j-api</artifactId>
     67             <version>1.7.25</version>
     68         </dependency>
     69 
     70         <dependency>
     71             <groupId>ch.qos.logback</groupId>
     72             <artifactId>logback-classic</artifactId>
     73             <version>1.1.6</version>
     74             <exclusions>
     75                 <exclusion>
     76                     <groupId>org.slf4j</groupId>
     77                     <artifactId>slf4j-api</artifactId>
     78                 </exclusion>
     79             </exclusions>
     80         </dependency>
     81     </dependencies>
     82 
     83     <build>
     84         <finalName>kafka_consumer_demo</finalName>
     85         <resources>
     86             <!--指定src/main/resources资源要过滤-->
     87             <resource>
     88                 <directory>src/main/resources</directory>
     89                 <filtering>true</filtering>
     90             </resource>
     91         </resources>
     92         <plugins>
     93             <!-- 可执行jar插件 -->
     94             <plugin>
     95                 <groupId>org.apache.maven.plugins</groupId>
     96                 <artifactId>maven-jar-plugin</artifactId>
     97                 <configuration>
     98                     <outputDirectory>${project.build.directory}/${build.finalName}</outputDirectory>
     99                     <archive>
    100                         <manifest>
    101                             <addClasspath>true</addClasspath>
    102                             <classpathPrefix>lib/</classpathPrefix>
    103                             <mainClass>com.donfaquir.kafka.KafkaComsumerDemo</mainClass>
    104                         </manifest>
    105                         <manifestEntries>
    106                             <Class-Path>.</Class-Path>
    107                         </manifestEntries>
    108                     </archive>
    109                     <excludes>
    110                         <exclude>**/*.xml</exclude>
    111                         <exclude>**/*.conf</exclude>
    112                         <exclude>**/*.properties</exclude>
    113                         <exclude>**/*.bat</exclude>
    114                     </excludes>
    115 
    116                 </configuration>
    117             </plugin>
    118             <!-- maven资源文件复制插件 -->
    119             <plugin>
    120                 <groupId>org.apache.maven.plugins</groupId>
    121                 <artifactId>maven-resources-plugin</artifactId>
    122                 <version>2.7</version>
    123                 <executions>
    124                     <execution>
    125                         <id>copy-resources</id>
    126                         <!-- here the phase you need -->
    127                         <phase>package</phase>
    128                         <goals>
    129                             <goal>copy-resources</goal>
    130                         </goals>
    131                         <configuration>
    132                             <outputDirectory>${project.build.directory}/${build.finalName}</outputDirectory>
    133                             <resources>
    134                                 <resource>
    135                                     <directory>src/main/resources</directory>
    136                                     <includes>
    137                                         <exclude>**/*.xml</exclude>
    138                                         <exclude>**/*.conf</exclude>
    139                                         <exclude>**/*.properties</exclude>
    140                                         <exclude>**/*.bat</exclude>
    141                                     </includes>
    142                                     <filtering>true</filtering>
    143                                 </resource>
    144                             </resources>
    145                             <encoding>UTF-8</encoding>
    146                         </configuration>
    147                     </execution>
    148                 </executions>
    149             </plugin>
    150             <!-- 依赖包插件 -->
    151             <plugin>
    152                 <groupId>org.apache.maven.plugins</groupId>
    153                 <artifactId>maven-dependency-plugin</artifactId>
    154                 <executions>
    155                     <execution>
    156                         <id>copy-dependencies</id>
    157                         <phase>package</phase>
    158                         <goals>
    159                             <goal>copy-dependencies</goal>
    160                         </goals>
    161                         <configuration>
    162                             <outputDirectory>${project.build.directory}/${build.finalName}/lib</outputDirectory>
    163                             <!-- 是否不包含间接依赖 -->
    164                             <excludeTransitive>false</excludeTransitive>
    165                             <!-- 忽略版本 -->
    166                             <stripVersion>false</stripVersion>
    167                         </configuration>
    168                     </execution>
    169                 </executions>
    170             </plugin>
    171 
    172             <plugin>
    173                 <groupId>org.apache.maven.plugins</groupId>
    174                 <artifactId>maven-surefire-plugin</artifactId>
    175                 <version>2.18.1</version>
    176                 <configuration>
    177                     <skipTests>true</skipTests>
    178                 </configuration>
    179             </plugin>
    180             <plugin>
    181                 <groupId>org.apache.maven.plugins</groupId>
    182                 <artifactId>maven-compiler-plugin</artifactId>
    183                 <version>3.1</version>
    184                 <configuration>
    185                     <encoding>UTF-8</encoding>
    186                     <source>1.8</source>
    187                     <target>1.8</target>
    188 
    189                 </configuration>
    190                 <dependencies>
    191                     <dependency>
    192                         <groupId>org.codehaus.plexus</groupId>
    193                         <artifactId>plexus-compiler-javac</artifactId>
    194                         <version>2.5</version>
    195                     </dependency>
    196                 </dependencies>
    197             </plugin>
    198         </plugins>
    199     </build>
    200 </project>

    consumer类

  • 相关阅读:
    食物链(带权&种类并查集)
    抓屏工具 faststone capture
    ViewerJS 一个在浏览器上查看 PDF 和电子表格的 JavaScript 库
    html中调用本地exe应用程序
    html+css构成的框架,可自行改造
    普通人每天应该睡多长时间??
    利用PDF.JS插件解决了本地pdf文件在线浏览问题(根据需要隐藏下载功能,只保留打印功能)
    解决在IE11浏览器上,css样式不起作用的问题
    Dreamweaver cs6 的安装与破解
    博客生活第一天
  • 原文地址:https://www.cnblogs.com/donfaquir/p/10386801.html
Copyright © 2011-2022 走看看