关于Jmeter如何调用python脚本,请参考我上一篇文章,链接:Jmeter5.1.1调用Python3脚本
本文章,分享python向rabbit发送数据的代码
from datetime import datetime
import pika
import json
# send mq message
class MQMessage():
def __init__(self):
username = 'xxxx'
password = 'xxxx'
host = 'xxx.xxx.xxx.xxx' # MQ服务的IP地址
credentials = pika.PlainCredentials(username, password)
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=host, credentials=credentials, port=5672))
# 获取MQ管道
self.channel = self.connection.channel()
def send_message(self):
time_fm = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
time_fm1 = datetime.now().strftime("%Y%m%d%H%M%S")
# 定义发送的数据字典
data =