kafka的使用
kafka基于zookeeper。
需要安装kafka、zookeeper。
安装方法参考:http://tzz6.iteye.com/blog/2401197
启动zookeeper:点击zkServer.cmd启动zookeeper。
启动kafka:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5oAAAEoCAYAAAA5aI7cAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAC0aSURBVHhe7d1PqG1ZWhjw8y4IIT3orkC1kIGWIgaCJg5CoEGaysCBIwexCNKDEKELdBAJ0vM47ULIRAcW3e0oIv0mgaAQE1JWoIvEQJfYKEHRegWB7hbS9qBDwMHL/a5nlavWW2uvtfde+91z7v394OPuvf5869v7nPveWfecd9+TX/qlX3p+Ovs3P/l/Tz/4s79xPgMAAID1njy/dT4+PXv6po0mAAAAu9ycvwIAAMAUNpoAAABM9cJHZ1974+3zGRzvnXfeOb3++uvnsxf1+nNrxgIAAMe5+dmnf3J65a33Tl9+/1vnJpgjNn55JPnxkjRudDyXIT3eKQAAeHxuPv2J7zsfwnzxDmOKnnKDsmYul8PjBgDAza//9I+cD/9G/kK/dp7U2vj4fcm/lveq1sblbVKWHqO9j+GM58CW+lJ7GbmlvmSpDwCAx+2FXwbUeoH/UN+dmP1i+T7u32N7wZ+ut4xe3xq9edEXj2nE1vx75y/N6+VPfXkk+dwUZY5efgAAHrn4ZUCf+uLXnn/p6998/sFXPx+/GOj57QvHuyiPH1rk11W7xq3XneaVX4+Ml7HG2mjVFO1ltNpTlDnKWDN2TdTyjba1Yu/8PLbU11tr7/w81owVQgghhBAPJ25+5d0Pb78S78zw8qR3w1Ik6bjW13K7mfnYvDgHAADuz80ffft758Nx8UI+xZLauLKtPE/y9rIvlP3lmJG+8jjp9e+Vctby5u0j49b25+et45DO8+DhWHpcy816HNc2/Es5AAB45OIjs/HR2bD2o7Ot9oiyr3aet7WOa217+5fa8uj1tyLNK7+WsdRe9uXntXmj/WVfbd7S/DXRmhPteeTt+deyvRa1+eX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M/fG4CAACA7fwbTQAAAKay0QQAAGAqG00AAACmstEEAABgqptvf++vT+9++N3zKQAAAOzz5Pmt8/Hp2dM3T6+98fb5DAAAANa7eeWt904pAAAAYC/vaAIAADCVXwYEAADAVDaaAAAATGWjCQAAwFQ2mgAAAExlowkAAMBUNpoAAABMZaMJAADAVDaaAAAATGWjCQAAwFQ2mgAAAExlowkAAMBUNpoAAABMZaMJAADAVDaaAAAATGWjCQAAwFQ2mgAAAExlowkAAMBUNpoAAABMZaMJAADARKfT/weprbVVuJ4IkAAAAABJRU5ErkJggg==" alt="" />
如果启动报错:
启动kafka的时候报错:
ERROR Error while deleting the clean shutdown file in dir E:\kafka_2.11-1.0.0\tmp\kafka-logs (kafka.server.LogDirFailureChannel)
java.nio.file.FileSystemException: E:\kafka_2.11-1.0.0\tmp\kafka-logs\__consumer_offsets-9\00000000000000000000.timeindex: 另一个程序正在使用此文件,进程无法访问。
解决办法:
删除日志:
日志的路径在kafka的文件中找到server.properties:log.dirs=/tmp/kafka-logs。删除tmp文件夹下的kafka-logs文件夹。重启kafka即可。
kafka配置:
kafka-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <context:component-scan base-package="com.unionpay.producer"></context:component-scan>
<context:component-scan base-package="com.unionpay.consumer"></context:component-scan> <bean id="kafkaProducerDemo" class="com.test.www.unionpay.producer.KafkaProducerDemo">
<property name="properties">
<props>
<prop key="topic">my-replicated-topic</prop>
<prop key="bootstrap.servers">127.0.0.1:9092</prop>
<prop key="acks">all</prop>
<prop key="key.serializer">org.apache.kafka.common.serialization.StringSerializer
</prop>
<prop key="value.serializer">org.apache.kafka.common.serialization.StringSerializer
</prop>
<prop key="buffer.memory">33554432</prop>
</props> </property>
</bean> <bean id="kafkaConsumerDemo" class="com.test.www.unionpay.consumer.KafkaConsumerDemo">
<property name="props">
<props>
<prop key="topic">my-replicated-topic</prop>
<prop key="bootstrap.servers">127.0.0.1:9092</prop>
<prop key="group.id">group1</prop>
<prop key="enable.auto.commit">true</prop>
<prop key="auto.commit.interval.ms">1000</prop>
<prop key="session.timeout.ms">30000</prop>
<prop key="key.deserializer">org.apache.kafka.common.serialization.StringDeserializer
</prop>
<prop key="value.deserializer">org.apache.kafka.common.serialization.StringDeserializer
</prop>
</props> </property>
</bean>
</beans>
redis.properties:
# 控制一个pool可分配多少个jedis实例
redis.pool.maxTotal=1000
# 控制一个pool最多有多少个状态为idle(空闲)的jedis实例
redis.pool.maxIdle=200
# 表示当borrow一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException
redis.pool.maxWaitMillis=2000
#在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的
redis.pool.testOnBorrow=true
# redis 单机
# 单机 host
jedis.host=127.0.0.1
# 单机 port
jedis.port=6379
KafkaProducerDemo.java:
package com.test.www.unionpay.producer; import java.util.Properties; import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord; public class KafkaProducerDemo {
Properties properties;
public KafkaProducerDemo() { }
public KafkaProducerDemo(Properties properties) {
super();
this.properties = properties;
} public Properties getProperties() {
return properties;
} public void setProperties(Properties properties) {
this.properties = properties;
} public void sendMessage(String msg) { KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties); ProducerRecord<String, String> record = new ProducerRecord<String, String>(properties.getProperty("topic"),msg);
producer.send(record); producer.close(); } }
KafkaConsumerDemo.java:
package com.test.www.unionpay.consumer; import java.util.Arrays;
import java.util.Properties; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer; public class KafkaConsumerDemo {
private Properties props;
public KafkaConsumerDemo() {
}
public KafkaConsumerDemo(Properties props) {
super();
this.props = props;
} public Properties getProps() {
return props;
} public void setProps(Properties props) {
this.props = props;
} public String receive(){ KafkaConsumer<String,String> consumer = new KafkaConsumer<String,String>(props);
consumer.subscribe(Arrays.asList(props.getProperty("topic"))); String msg = "";
while(true){
ConsumerRecords<String,String> consumerRecords = consumer.poll(100);
for(ConsumerRecord<String, String> consumerRecord:consumerRecords){
msg += consumerRecord.value();
}
consumer.close();
return msg;
}
} }
KafkaController.java:
package com.test.www.web.controller; import java.text.SimpleDateFormat;
import java.util.Date; import javax.annotation.Resource; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import com.test.www.unionpay.consumer.KafkaConsumerDemo;
import com.test.www.unionpay.producer.KafkaProducerDemo; @Controller
public class KafkaController { @Resource(name = "kafkaProducerDemo")
KafkaProducerDemo producer; @Resource(name = "kafkaConsumerDemo")
KafkaConsumerDemo consumer; @RequestMapping(value = "/welcome")
public ModelAndView welcome() {
System.out.println("--------welcome--------");
ModelAndView mv = new ModelAndView();
mv.setViewName("welcome");
return mv;
} @RequestMapping(value = "/sendmessage", method = RequestMethod.GET)
public ModelAndView sendMessage() {
System.out.println("--------sendmessage--------");
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = sdf.format(date); ModelAndView mv = new ModelAndView();
mv.addObject("time", now);
mv.setViewName("kafka_send");
return mv;
} @RequestMapping(value = "/onsend", method = RequestMethod.POST)
public ModelAndView onsend(@RequestParam("message") String msg) {
System.out.println("--------onsend--------");
producer.sendMessage(msg); ModelAndView mv = new ModelAndView();
mv.setViewName("welcome");
return mv;
} @RequestMapping(value = "/receive")
public ModelAndView receive() {
System.out.println("--------receive--------"); String msg = consumer.receive(); ModelAndView mv = new ModelAndView();
mv.addObject("msg", msg);
mv.setViewName("kafka_receive");
return mv;
} }
页面:
welcome.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>welcome</title>
</head>
<body>
<h1>Welcome</h1>
<h2><a href="sendmessage.html">Send a Message</a></h2>
<h2><a href="receive.html">Get a Message</a></h2>
</body>
</html>
kafka_send.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>kafka_send</title>
</head>
<body>
<h1>Send a Message</h1>
<form action="onsend.html" method="post">
MessageText:<textarea name="message">${time}</textarea>
<br>
<input type="submit" value="Submit">
</form> <h2><a href="welcome.html">RETURN HOME</a></h2>
</body>
</html>
kafka_receive.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>kafka_receive</title>
</head>
<body> <h1>Kafka_Reveive!!!</h1>
<h2>Receive Message : ${msg}</h2>
<h2><a href="welcome.html">RETURN HOME</a></h2>
</body>
</html>
效果图:
如图,kafka发送消息、接受消息运行成功。
kafka的使用的更多相关文章
- Spark踩坑记——Spark Streaming+Kafka
[TOC] 前言 在WeTest舆情项目中,需要对每天千万级的游戏评论信息进行词频统计,在生产者一端,我们将数据按照每天的拉取时间存入了Kafka当中,而在消费者一端,我们利用了spark strea ...
- 消息队列 Kafka 的基本知识及 .NET Core 客户端
前言 最新项目中要用到消息队列来做消息的传输,之所以选着 Kafka 是因为要配合其他 java 项目中,所以就对 Kafka 了解了一下,也算是做个笔记吧. 本篇不谈论 Kafka 和其他的一些消息 ...
- kafka学习笔记:知识点整理
一.为什么需要消息系统 1.解耦: 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余: 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险. ...
- .net windows Kafka 安装与使用入门(入门笔记)
完整解决方案请参考: Setting Up and Running Apache Kafka on Windows OS 在环境搭建过程中遇到两个问题,在这里先列出来,以方便查询: 1. \Jav ...
- kafka配置与使用实例
kafka作为消息队列,在与netty.多线程配合使用时,可以达到高效的消息队列
- kafka源码分析之一server启动分析
0. 关键概念 关键概念 Concepts Function Topic 用于划分Message的逻辑概念,一个Topic可以分布在多个Broker上. Partition 是Kafka中横向扩展和一 ...
- Kafka副本管理—— 为何去掉replica.lag.max.messages参数
今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...
- Kafka:主要参数详解(转)
原文地址:http://kafka.apache.org/documentation.html ############################# System ############### ...
- kafka
2016-11-13 20:48:43 简单说明什么是kafka? Apache kafka是消息中间件的一种,我发现很多人不知道消息中间件是什么,在开始学习之前,我这边就先简单的解释一下什么是消息 ...
- Spark Streaming+Kafka
Spark Streaming+Kafka 前言 在WeTest舆情项目中,需要对每天千万级的游戏评论信息进行词频统计,在生产者一端,我们将数据按照每天的拉取时间存入了Kafka当中,而在消费者一端, ...
随机推荐
- oracle 索引优化之distinct
11G R2环境: --DISTINCT测试前的准备drop table t purge;create table t as select * from dba_objects;update t se ...
- Spring《二》 Bean的生命周期
Bean初始化 1.bean中实现public void init():方法,config.xml中增加init-method="init" 属性. 2.bean实现接口Initi ...
- SQL Server 汉字转拼音字母
/* 汉字转拼音首字母 */ create function fun_getPY(@str nvarchar(4000)) returns nvarchar(4000) as begin declar ...
- thinkphp连接数据库,会有大量的sleep连接
show processlist; 说明各列的含义和用途, id列:一个标识,你要kill 一个语句的时候很有用. user列: 显示当前用户,如果不是root,这个命令就只显示你权限范围内的sql语 ...
- 12 个最佳 GNOME(GTK)主题
作者: Phillip Prado 译者: LCTT 郑 | 2019-04-14 09:45 评论: 1 收藏: 2 让我们来看一些漂亮的 GTK 主题,你不仅可以用在 Ubuntu 上,也可以 ...
- java读取文件流和写入
package jsoup;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStre ...
- SQL中Group By的使用(转)
1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...
- PHP SOAP 使用示例
soap_client.php <?php try { $client = new SoapClient( null, array('location' =>"http://lo ...
- Eclipse项目启动不了
当你的Eclipse项目启动不了多半是[eclipse工程jdk版本]的问题 在eclipse中项目jdk版本不匹配的时候需要修改项目工程的jdk版本,但是网上的一些版本修改不是很完全,经过一些摸索之 ...
- Android开发进度07
1,今日:目标:完成记账功能 2,昨天:账单的增删改查方法 3,收获:无 4,问题:SQLite表单出现问题,提交后软件直接退出