kafka-Java-SpringBoot-API測試
測試三個方面,傳送訊息,接收訊息,以及接收訊息時bean的注入.
測試專案GitHub地址:
git@github.com:wudonghua/Java-Kafka-SpringBoot-API-test.git
把剛才的專案打包到本地倉庫:
-Dmaven.home=E:apache-maven-3.2.5 -Dclassworlds.conf=E:apache-maven-3.2.5inm2.conf "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2017.2.6libidea_rt.jar=54786:C:Program FilesJetBrainsIntelliJ IDEA 2017.2.6in" -Dfile.encoding=UTF-8 -classpath E:apache-maven-3.2.5ootplexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2017.2.6 -s E:apache-maven-3.2.5confsettings.xml -Dmaven.repo.local=E:
epo -DskipTests=true install
在測試工程裡面新增jar包:
<dependency>
<groupId>Riven.kafka</groupId>
<artifactId>Java-SpringBoot-Kafka-API</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
傳送訊息:
配置值內容:
Riven:
kafka:
producer:
bootstrapServers: 伺服器列表 #必填
retries: 99
acks: 接受策略
batchSize: 99
lingerMs: 99
bufferMemory: 99
keySerializer: org.apache.kafka.common.serialization.StringSerializer
valueSerializer: org.apache.kafka.common.serialization.StringSerializer
實現類
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @Author dw07-Riven770[wudonghua@gznb.com]
* @Date 2017/12/1417:37
*/
@Component
@EnableScheduling
public class Producer {
@Autowired
private KafkaTemplate kafkaTemplate;
@Scheduled(fixedDelay = 6000)
private void sendMsg(){
kafkaTemplate.send("topic-test", "hello"+ LocalDateTime.now().toString());
}
}
接收訊息及Bean注入
配置內容:
Riven:
kafka:
consumer:
bootstrapServers: 伺服器列表 #必填
enableAutoCommit: true
autoCommitIntervalMs: 99
sessionTimeoutMs: 99
fetchMinBytes: 99
maxPollRecords: 99
groupId: java #必填
autoOffseReset: latest
keySerializer: org.apache.kafka.common.serialization.StringDeserializer
valueSerializer: org.apache.kafka.common.serialization.StringDeserializer
consumerAmount: 99
PollTimeout: 99
topics[0]: test_group #必填
實現類:
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import riven.kafka.api.listener.IKafkaListener;
import java.util.Optional;
/**
* @Author dw07-Riven770[wudonghua@gznb.com]
* @Date 2017/12/1417:37
*/
@Component
public class Consumer implements IKafkaListener{
@Autowired
private TestBean testBean;
@Override
public void listener(ConsumerRecord<?, ?> record) {
Optional<?> value = Optional.ofNullable(record.value());
String s = (String) value.get();
System.out.println("消費者"+s);
testBean.test();
}
}
注入bean:
import org.springframework.stereotype.Component;
/**
* @Author dw07-Riven770[wudonghua@gznb.com]
* @Date 2017/12/1417:37
*/
@Component
public class TestBean {
public void test(){
System.out.println("DoSomeThing....");
}
}
測試報文:
producer:啟動報文
2017-12-15 17:15:31.332 INFO 16904 --- [pool-1-thread-1] o.a.k.clients.producer.ProducerConfig : ProducerConfig values:
acks = -1
batch.size = 4096
block.on.buffer.full = false
bootstrap.servers = [xx.xx.30.205:9092, xx.xx.30.206:9092]
buffer.memory = 40960
client.id = producer-1
compression.type = none
connections.max.idle.ms = 540000
interceptor.classes = null
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 1
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.fetch.timeout.ms = 60000
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
timeout.ms = 30000
value.serializer = class org.apache.kafka.common.serialization.StringSerializer
producer傳送報文:
2017-12-15 17:15:32.794 INFO 16904 --- [ad | producer-1] r.k.api.producer.SimpleProducerListener : 訊息傳送成功!
with key=【key】 and value=【Hello2017-12-15T17:15:31.328】 to topic 【topic-test】 send result: topicPartition【topic-test-1】 offset 【28】
consumer啟動報文:
2017-12-15 17:15:31.299 INFO 16904 --- [ main] o.a.k.clients.consumer.ConsumerConfig : ConsumerConfig values:
auto.commit.interval.ms = 100
auto.offset.reset = latest
bootstrap.servers = [xx.xx.30.205:9092, xx.xx.30.206:9092]
check.crcs = true
client.id = consumer-3
connections.max.idle.ms = 540000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = group_test
heartbeat.interval.ms = 3000
interceptor.classes = null
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 300
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.ms = 50
request.timeout.ms = 305000
retry.backoff.ms = 100
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
session.timeout.ms = 15000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
consumer消費報文:
消費者Hello2017-12-15T17:16:13.581
DoSomeThing....
相關文章
- 測試測試測試測試測試測試
- 測試—測試方法
- 測試測試用
- Flutter 學習之路 - 測試(單元測試,Widget 測試,整合測試)Flutter
- App測試、Web測試和介面測試一般測試流程APPWeb
- 測試面試-測試用例面試
- 介面測試測試流程
- 介面測試,負載測試,併發測試,壓力測試區別負載
- 測試CMS同步測試CMS同步測試CMS同步
- (一)效能測試(壓力測試、負載測試)負載
- 介面測試 - 引數測試
- Jmeter介面測試+效能測試JMeter
- 【軟體測試】——介面測試
- 微服務測試之介面測試和契約測試微服務
- 測試 之Java單元測試、Android單元測試JavaAndroid
- 黑盒測試、白盒測試與灰盒測試方法
- 功能測試、自動化測試、效能測試的區別
- 小白測試系列:介面測試與效能測試的區別
- 軟體測試中的功能測試和非功能測試
- API 測試 | 瞭解 API 介面測試 | API 介面測試指南API
- 測試——水杯的測試用例
- Burpsuite安全測試測試指導UI
- 軟體測試-測試計劃
- 單元測試,只是測試嗎?
- 測試平臺之介面測試
- 測試用例和測試方法
- 測試物件和測試級別物件
- 微服務測試之效能測試微服務
- 去測試化≠測試失業
- 黑盒測試和白盒測試
- 介面測試要測試什麼?
- 效能測試之測試指標指標
- 測試標題測試標題
- API測試:瞭解API介面測試與API介面測試指南API
- 眼圖測試(硬體測試 訊號完整性測試)
- 軟體效能測試常見指標。在哪裡測試測試?指標
- 測試
- 測試- -
- 4大軟體測試策略的特點和區別(單元測試、整合測試、確認測試和系統測試)