_jmeter往kafka发数据">
赞
踩
#将以下代码保存为.jmx文件即可以jmeter打开
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="kafka造数据" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="轨迹模拟车机" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">stopthread</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">10</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="KAFKA_BROKERS" elementType="Argument">
<stringProp name="Argument.name">KAFKA_BROKERS</stringProp>
<stringProp name="Argument.value">ip:9092 </stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">kafka服务器地址</stringProp>
</elementProp>
<elementProp name="KAFKA_TOPIC" elementType="Argument">
<stringProp name="Argument.name">KAFKA_TOPIC</stringProp>
<stringProp name="Argument.value">netvehicle_gps</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">发送的主题名称</stringProp>
</elementProp>
<elementProp name="KAFKA_TOPIC_PARTITIONS" elementType="Argument">
<stringProp name="Argument.name">KAFKA_TOPIC_PARTITIONS</stringProp>
<stringProp name="Argument.value">2</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">发送到哪个分区,没有或不知道就填1</stringProp>
</elementProp>
<elementProp name="KAFKA_KEY" elementType="Argument">
<stringProp name="Argument.name">KAFKA_KEY</stringProp>
<stringProp name="Argument.value"></stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">发送key,没有则为空,不能是空格</stringProp>
</elementProp>
<elementProp name="KAFKA_MESSAGE" elementType="Argument">
<stringProp name="Argument.name">KAFKA_MESSAGE</stringProp>
<stringProp name="Argument.value">{"accuracy":0,"deviceType":200,"enduranceMileage":0,"lat":31.01,"lon":121.99,"mileage":1000,"remainElectric":0,"speed":0.0,"timestamp":1599132376918,"vin":"test1898"}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">要发送的数据</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
<JavaSampler guiclass="JavaTestSamplerGui" testclass="JavaSampler" testname="车载轨迹上报kafka模拟" enabled="true">
<elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="kafka服务地址" elementType="Argument">
<stringProp name="Argument.name">kafka服务地址</stringProp>
<stringProp name="Argument.value">${KAFKA_BROKERS}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka主题" elementType="Argument">
<stringProp name="Argument.name">kafka主题</stringProp>
<stringProp name="Argument.value">${KAFKA_TOPIC}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka分区" elementType="Argument">
<stringProp name="Argument.name">kafka分区</stringProp>
<stringProp name="Argument.value">${KAFKA_TOPIC_PARTITIONS}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka_key" elementType="Argument">
<stringProp name="Argument.name">kafka_key</stringProp>
<stringProp name="Argument.value"> </stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka_message消息" elementType="Argument">
<stringProp name="Argument.name">kafka_message消息</stringProp>
<stringProp name="Argument.value">${KAFKA_MESSAGE}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka_message_serializer" elementType="Argument">
<stringProp name="Argument.name">kafka_message_serializer</stringProp>
<stringProp name="Argument.value">org.apache.kafka.common.serialization.ByteArraySerializer</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="kafka_key_serializer" elementType="Argument">
<stringProp name="Argument.name">kafka_key_serializer</stringProp>
<stringProp name="Argument.value">org.apache.kafka.common.serialization.ByteArraySerializer</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="classname">co.signal.kafkameter.KafkaProducerSampler</stringProp>
</JavaSampler>
<hashTree>
<BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="kafka请求报文组装" enabled="true">
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<boolProp name="resetInterpreter">false</boolProp>
<stringProp name="script">import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
JSONObject json = new JSONObject();
//精度
json.put("accuracy","0");
//
json.put("deviceType","200");
//
json.put("enduranceMileage","0");
//
json.put("remainElectric","0");
//纬度
json.put("lat","31.01");
//经度
json.put("lon","121.99");
//里程
json.put("mileage","1000");
//速度
json.put("speed","${__Random(20,30,)}.${__Random(0,9,)}");
//时间戳
json.put("timestamp","${__time(,)}");
//车辆vin码
// json.put("vin","test1898");
json.put("vin","vinum");
String reqJson=json.toJSONString();
vars.put("KAFKA_MESSAGE",reqJson);</stringProp>
</BeanShellPreProcessor>
<hashTree/>
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="间隔1秒上传" enabled="true">
<stringProp name="ConstantTimer.delay">1000</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。