如果jmeter中有HTTP请求,则在请求URL和主体中传递自动递增变量

时间:2019-06-22 07:49:19

标签: jmeter auto-increment

我有一个端点,它接受自动递增的整数id作为路径参数的一部分,并且在请求正文中也有一些键也接受它。

例如端点为[2019-06-21 12:41:13,494] WARN [Producer clientId=console-producer] Got error produce response with correlation id 26 on topic-partition test-0, retrying (2 attempts left). Error: UNKNOWN_TOPIC_OR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,495] WARN [Producer clientId=console-producer] Received unknown topic or partition error in produce request on partition test-0. The topic-partition may not exist or the user may not have Describe access to it (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,597] WARN [Producer clientId=console-producer] Got error produce response with correlation id 28 on topic-partition test-0, retrying (1 attempts left). Error: UNKNOWN_TOPIC_OR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,597] WARN [Producer clientId=console-producer] Received unknown topic or partition error in produce request on partition test-0. The topic-partition may not exist or the user may not have Describe access to it (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,704] WARN [Producer clientId=console-producer] Got error produce response with correlation id 30 on topic-partition test-0, retrying (0 attempts left). Error: UNKNOWN_TOPIC_OR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,704] WARN [Producer clientId=console-producer] Received unknown topic or partition error in produce request on partition test-0. The topic-partition may not exist or the user may not have Describe access to it (org.apache.kafka.clients.producer.internals.Sender) [2019-06-21 12:41:13,808] ERROR Error when sending message to topic test with key: null, value: 0 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback) org.apache.kafka.common.errors.UnknownTopicOrPartitionException: This server does not host this topic-partition. [2019-06-21 12:41:13,809] WARN [Producer clientId=console-producer] Received unknown topic or partition error in produce request on partition test-0. The topic-partition may not exist or the user may not have Describe access to it (org.apache.kafka.clients.producer.internals.Sender)

身体是

http://foo.bar/{id}

我尝试直接使用{ "someid" : someno+{id passed in url}, "some world :"fixed string" + "id passed in url" } 代替我的{id},但是它不起作用,并且在调试时发现它不能代替值,并且只能作为文字输入。

2 个答案:

答案 0 :(得分:2)

添加Counter并在需要的地方调用您定义的参考名称。

  

允许用户创建一个可以在线程组中任何地方引用的计数器

答案 1 :(得分:2)

__counter() function每次被调用时都会生成递增的数字,您可以将其声明放入URL中,例如:

${__counter(FALSE,counter)}

和对请求正文的JMeter Variable引用:

{
 "someid" : someno+${counter},
 "some world :"fixed string" + "id passed in url"
}

enter image description here

这样,您每次通话都会获得一个唯一的递增号码

enter image description here

更多信息:How to Use a Counter in a JMeter Test