How to reuse the same connection for azure service bus sampler in jmeter - Stack Overflow

I am using an Azure Service Bus Sampler in jmeter and using plugin jmeter-plugins-azure-servicebus-0.3.

I am using an Azure Service Bus Sampler in jmeter and using plugin jmeter-plugins-azure-servicebus-0.3.4.jar. I am using jmeter version 5.6.3. Below is the snapshot for the jmeter sampler I am using,

I am running with a load test and this sampler creates a new connection every time to send the messages. This is causing issues due to a lot of connections being created. is there a way we can use the same connection for further requests ?

There is an option in the sampler itself i.e 'Use defined connection', but how to use this ? How to save a connection to use it again and again ? Can someone please help on this ! Thanks in advance !

I am using an Azure Service Bus Sampler in jmeter and using plugin jmeter-plugins-azure-servicebus-0.3.4.jar. I am using jmeter version 5.6.3. Below is the snapshot for the jmeter sampler I am using,

I am running with a load test and this sampler creates a new connection every time to send the messages. This is causing issues due to a lot of connections being created. is there a way we can use the same connection for further requests ?

There is an option in the sampler itself i.e 'Use defined connection', but how to use this ? How to save a connection to use it again and again ? Can someone please help on this ! Thanks in advance !

Share Improve this question asked Mar 24 at 3:39 KeshavKumarKeshavKumar 255 bronze badges 3
  • Enable Use defined connection, set a unique Connection Name, initialize it once in a Setup Thread Group, and reuse it in all samplers. – Dasari Kamali Commented Mar 24 at 3:54
  • I have tried that as well, but there is no option to 'create a variable name for connection', but it says 'create a variable name for transaction'. I put a variable name in this and define a beanshell assertion to use it in further thread groups but it is throwing error i.e "java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "tempObject" is null" – KeshavKumar Commented Mar 24 at 4:20
  • Try storing the connection in a JSR223 PreProcessor using vars.putObject("serviceBusClient", queueClient) and retrieve it in samplers with vars.getObject("serviceBusClient") to reuse it – Dasari Kamali Commented Mar 24 at 5:25
Add a comment  | 

1 Answer 1

Reset to default 1

is there a way we can use the same connection for further requests ?

You can reuse the same connection for multiple requests in JMeter by storing the connection object in a JMeter variable using vars.putObject and retrieving it with vars.getObject in a JSR223 Sampler to send messages to the Azure Service Bus Topic.

Jmeter :

I have successfully sent messages to the Azure Service Bus Topic using the JSR223 sampler with the below test codes.

sampler-1 :

I have saved the connection using vars.putObject and retrieved it using vars.getObject in the code below, reusing it in other scripts.

import com.azure.messaging.servicebus.*;

if (vars.getObject("azureSenderClient") == null) {
    String connectionString = "<ServiceBusConneString>";
    String topicName = "<TopicName>";  

    ServiceBusSenderClient senderClient = new ServiceBusClientBuilder()
        .connectionString(connectionString)
        .sender()
        .topicName(topicName)
        .buildClient();
    
    vars.putObject("azureSenderClient", senderClient);  
    log.info("Azure Service Bus Connection Created and Stored");
} else {
    log.info("Azure Service Bus Connection Already Exists");
}

sampler-2 :

import com.azure.messaging.servicebus.*;

ServiceBusSenderClient senderClient = vars.getObject("azureSenderClient");
if (senderClient == null) {
    log.error("Service Bus connection not found! Make sure the Setup Thread Group ran first.");
} else {
    ServiceBusMessage message = new ServiceBusMessage("Hello Kamali from JMeter!");
    senderClient.sendMessage(message);
    log.info("Message Sent Successfully to Topic: kamtopic");
}

sampler-3 :

import  com.azure.messaging.servicebus.*;  
  
ServiceBusSenderClient  senderClient  =  vars.getObject("azureSenderClient");  
if  (senderClient  !=  null)  {  
  senderClient.close();  
  vars.remove("azureSenderClient");  
  log.info("Azure Service Bus Connection Closed Successfully");  
}  else  {  
  log.warn("No Service Bus connection found to close.");  
}

Azure Service Bus :

The messages sent successfully to the Azure Service Bus Topic as shown below.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744261725a4565665.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信