Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
f15e8e7b
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f15e8e7b
编写于
12月 12, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spring-kafka
上级
2732a8ff
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
75 addition
and
103 deletion
+75
-103
whatsmars-mq/whatsmars-mq-kafka/README.md
whatsmars-mq/whatsmars-mq-kafka/README.md
+6
-1
whatsmars-mq/whatsmars-mq-kafka/pom.xml
whatsmars-mq/whatsmars-mq-kafka/pom.xml
+12
-25
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/Consumer.java
...ka/src/main/java/org/hongxi/whatsmars/kafka/Consumer.java
+18
-0
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaApplication.java
...ain/java/org/hongxi/whatsmars/kafka/KafkaApplication.java
+26
-0
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaConsumer.java
...c/main/java/org/hongxi/whatsmars/kafka/KafkaConsumer.java
+0
-47
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaProducer.java
...c/main/java/org/hongxi/whatsmars/kafka/KafkaProducer.java
+0
-30
whatsmars-mq/whatsmars-mq-kafka/src/main/resources/application.yml
...-mq/whatsmars-mq-kafka/src/main/resources/application.yml
+6
-0
whatsmars-mq/whatsmars-mq-kafka/src/test/java/org/hongxi/whatsmars/kafka/KafkaTests.java
.../src/test/java/org/hongxi/whatsmars/kafka/KafkaTests.java
+7
-0
未找到文件。
whatsmars-mq/whatsmars-mq-kafka/README.md
浏览文件 @
f15e8e7b
[
**Kafka**
](
https://github.com/apache/kafka
)
:
<br>
# [Kafka](https://github.com/apache/kafka):
linux:
<br>
启动zk ./zookeeper-server-start.sh ../config/zookeeper.properties
<br>
启动server ./kafka-server-start.sh ../config/server.properties
<br>
win:
<br>
修改bin/windows/kafka-server-start.bat set KAFKA_HEAP_OPTS=-Xmx512M -Xms512M
<br>
server.properties port=9092
<br>
...
...
whatsmars-mq/whatsmars-mq-kafka/pom.xml
浏览文件 @
f15e8e7b
...
...
@@ -11,40 +11,27 @@
<artifactId>
whatsmars-mq-kafka
</artifactId>
<properties>
<kafka.version>
0.8.0
</kafka.version>
<scala.version>
2.8.2
</scala.version>
<metrics.version>
2.2.0
</metrics.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.kafka
</groupId>
<artifactId>
kafka_2.8.2
</artifactId>
<version>
${kafka.version}
</version>
<exclusions>
<exclusion>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
</exclusion>
</exclusions>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.scala-lang
</groupId>
<artifactId>
scala-library
</artifactId>
<version>
${scala.version}
</version>
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka
</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>
com.yammer.metrics
</groupId>
<artifactId>
metrics-core
</artifactId>
<
version>
${metrics.version}
</version
>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<
scope>
test
</scope
>
</dependency>
<dependency>
<groupId>
com.101tec
</groupId>
<artifactId>
zkclien
t
</artifactId>
<
version>
${zkclient.version}
</version
>
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka-tes
t
</artifactId>
<
scope>
test
</scope
>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/Consumer.java
0 → 100644
浏览文件 @
f15e8e7b
package
org.hongxi.whatsmars.kafka
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.kafka.annotation.KafkaListener
;
import
org.springframework.stereotype.Component
;
/**
* Created by shenhongxi on 2018/12/12.
*/
@Slf4j
@Component
public
class
Consumer
{
@KafkaListener
(
topics
=
"kafkaTest"
)
public
void
onMessage
(
String
message
)
{
log
.
info
(
"receive message:{}"
,
message
);
}
}
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaApplication.java
0 → 100644
浏览文件 @
f15e8e7b
package
org.hongxi.whatsmars.kafka
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.kafka.core.KafkaTemplate
;
/**
* Created by shenhongxi on 2018/12/12.
*/
@SpringBootApplication
public
class
KafkaApplication
implements
CommandLineRunner
{
@Autowired
private
KafkaTemplate
<
Object
,
String
>
kafkaTemplate
;
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
KafkaApplication
.
class
,
args
);
}
@Override
public
void
run
(
String
...
strings
)
throws
Exception
{
kafkaTemplate
.
send
(
"kafkaTest"
,
"hello"
);
}
}
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaConsumer.java
已删除
100644 → 0
浏览文件 @
2732a8ff
package
org.hongxi.whatsmars.kafka
;
import
kafka.consumer.ConsumerConfig
;
import
kafka.consumer.ConsumerIterator
;
import
kafka.consumer.KafkaStream
;
import
kafka.javaapi.consumer.ConsumerConnector
;
import
kafka.serializer.StringDecoder
;
import
kafka.utils.VerifiableProperties
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
public
class
KafkaConsumer
{
public
static
void
main
(
String
[]
args
)
{
Properties
props
=
new
Properties
();
props
.
put
(
"zookeeper.connect"
,
"127.0.0.1:2181"
);
//group 代表一个消费组
props
.
put
(
"group.id"
,
"jd-group"
);
props
.
put
(
"zookeeper.session.timeout.ms"
,
"4000"
);
props
.
put
(
"zookeeper.sync.time.ms"
,
"200"
);
props
.
put
(
"auto.commit.interval.ms"
,
"1000"
);
props
.
put
(
"auto.offset.reset"
,
"smallest"
);
props
.
put
(
"serializer.class"
,
"kafka.serializer.StringEncoder"
);
ConsumerConfig
config
=
new
ConsumerConfig
(
props
);
ConsumerConnector
consumer
=
kafka
.
consumer
.
Consumer
.
createJavaConsumerConnector
(
config
);
Map
<
String
,
Integer
>
topicCountMap
=
new
HashMap
<
String
,
Integer
>();
topicCountMap
.
put
(
"TestTopic"
,
1
);
StringDecoder
keyDecoder
=
new
StringDecoder
(
new
VerifiableProperties
());
StringDecoder
valueDecoder
=
new
StringDecoder
(
new
VerifiableProperties
());
// Map<String, List<KafkaStream<Object, Object>>> consumerMap =
// consumer.createMessageStreams(topicCountMap, keyDecoder, valueDecoder);
// KafkaStream<Object, Object> stream = consumerMap.get("TestTopic").get(0);
// ConsumerIterator<Object, Object> it = stream.iterator();
// while (it.hasNext()) {
// System.out.println(it.next().message());
// }
System
.
out
.
println
(
"finished"
);
}
}
\ No newline at end of file
whatsmars-mq/whatsmars-mq-kafka/src/main/java/org/hongxi/whatsmars/kafka/KafkaProducer.java
已删除
100644 → 0
浏览文件 @
2732a8ff
package
org.hongxi.whatsmars.kafka
;
import
kafka.javaapi.producer.Producer
;
import
kafka.producer.KeyedMessage
;
import
kafka.producer.ProducerConfig
;
import
java.util.Properties
;
public
class
KafkaProducer
{
public
static
void
main
(
String
[]
args
)
{
Properties
props
=
new
Properties
();
props
.
put
(
"metadata.broker.list"
,
"127.0.0.1:9092"
);
props
.
put
(
"serializer.class"
,
"kafka.serializer.StringEncoder"
);
props
.
put
(
"key.serializer.class"
,
"kafka.serializer.StringEncoder"
);
props
.
put
(
"request.required.acks"
,
"-1"
);
Producer
<
String
,
String
>
producer
=
new
Producer
<
String
,
String
>(
new
ProducerConfig
(
props
));
int
messageNo
=
100
;
final
int
COUNT
=
1000
;
while
(
messageNo
<
COUNT
)
{
String
key
=
String
.
valueOf
(
messageNo
);
String
data
=
"hello kafka message "
+
key
;
producer
.
send
(
new
KeyedMessage
<
String
,
String
>(
"TestTopic"
,
key
,
data
));
System
.
out
.
println
(
data
);
messageNo
++;
}
}
}
\ No newline at end of file
whatsmars-mq/whatsmars-mq-kafka/src/main/resources/application.yml
0 → 100644
浏览文件 @
f15e8e7b
spring
:
kafka
:
bootstrap-servers
:
127.0.0.1:9092
consumer
:
group-id
:
testGroup
auto-offset-reset
:
earliest
\ No newline at end of file
whatsmars-mq/whatsmars-mq-kafka/src/test/java/org/hongxi/whatsmars/kafka/KafkaTests.java
0 → 100644
浏览文件 @
f15e8e7b
package
org.hongxi.whatsmars.kafka
;
/**
* Created by shenhongxi on 2018/12/12.
*/
public
class
KafkaTests
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录