当前位置: 首页> 房产> 建筑 > 帮收款的接单平台_企业信息填报官网_seo网络推广机构_北京百度推广排名优化

帮收款的接单平台_企业信息填报官网_seo网络推广机构_北京百度推广排名优化

时间:2025/7/14 18:53:33来源:https://blog.csdn.net/weixin_39810558/article/details/144561497 浏览次数:0次
帮收款的接单平台_企业信息填报官网_seo网络推广机构_北京百度推广排名优化

1.安装环境

kafka环境

参考Docker搭建kafka环境-CSDN博客

xk6-kafka环境

./xk6 build --with github.com/mostafa/xk6-kafka@latest

查看安装情况

2.编写脚本

test_kafka.js

// Either import the module object
import * as kafka from "k6/x/kafka";// Or individual classes and constants
import {Writer,Reader,Connection,SchemaRegistry,SCHEMA_TYPE_STRING,
} from "k6/x/kafka";// Creates a new Writer object to produce messages to Kafka
const writer = new Writer({// WriterConfig objectbrokers: ["localhost:9092"],topic: "my-topic",
});const reader = new Reader({// ReaderConfig objectbrokers: ["localhost:9092"],topic: "my-topic",
});const connection = new Connection({// ConnectionConfig objectaddress: "localhost:9092",
});const schemaRegistry = new SchemaRegistry();
// Can accept a SchemaRegistryConfig objectif (__VU == 0) {// Create a topic on initialization (before producing messages)connection.createTopic({// TopicConfig objecttopic: "my-topic",});
}export default function () {// Fetch the list of all topicsconst topics = connection.listTopics();console.log(topics); // list of topics// Produces message to Kafkawriter.produce({// ProduceConfig objectmessages: [// Message object(s){key: schemaRegistry.serialize({data: "my-key",schemaType: SCHEMA_TYPE_STRING,}),value: schemaRegistry.serialize({data: "my-value",schemaType: SCHEMA_TYPE_STRING,}),},],});// Consume messages from Kafkalet messages = reader.consume({// ConsumeConfig objectlimit: 10,});// your messagesconsole.log(messages);// You can use checks to verify the contents,// length and other properties of the message(s)// To serialize the data back into a string, you should use// the deserialize method of the Schema Registry client. You// can use it inside a check, as shown in the example scripts.let deserializedValue = schemaRegistry.deserialize({data: messages[0].value,schemaType: SCHEMA_TYPE_STRING,});
}export function teardown(data) {// Delete the topicconnection.deleteTopic("my-topic");// Close all connectionswriter.close();reader.close();connection.close();
}

3.运行测试

运作之前先开启kafka服务,打开终端输入命令

./k6 run test_kafka.js --vus 50 --duration 10s

测试结果

关键字:帮收款的接单平台_企业信息填报官网_seo网络推广机构_北京百度推广排名优化

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: