Skip to content

Commit

Permalink
AzServiceBusSampler: Support for custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kuniteru committed Mar 6, 2022
1 parent 49a2c33 commit 938e79b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/samplers.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Download jmeter-plugins-azure-servicebus.?.?.?.jar file from [latest release](ht
|Create transaction before sending messages|Create a transaction before sending a messages.|No|
|Variable name for created transaction|The name of the transaction to create, if "Create transaction before sending messages" is turned on.|No|
|Transaction state|Specify whether to commit or rollback, if "Use Defined Transaction" is selected for "Connection/Transaction".<ul><li>\[Continue transaction\]<br />No commit, and no rollback.</li><li>\[Commit transaction after sending messages\]<br />Commits the specified transaction after sending the messages.</li><li>\[Rollback transaction before sending messages\]<br />Sends the messages after the specified transaction is rolled back. (Sending messages are not included in the transaction)</li></ul>|No|
|Messages|List of messages to be sent in batches. Select "String" to send a UTF-8 string, "Base64 encoded binary" to send a Base64 encoded binary, or "File" to send a file as binary.|No|
|Messages|List of messages to be sent in batches. Select "String" to send a UTF-8 string, "Base64 encoded binary" to send a Base64 encoded binary, or "File" to send a file as binary.<br />To also send custom properties (user-defined properties), fill in the "custom properties" column in JSON format. (i.g., {"prop1": "value1", "porp2":2})|No|

<span id="1-servicebus">\*1</span>: If "Create New Connection" is selected for "Connection/Transaction", set these parameters.
<span id="2-servicebus">\*2</span>: If "Shared access signature" is selected for Auth type, set these parameters.
Expand Down
2 changes: 1 addition & 1 deletion plugins/protocol/amqp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>

<name>Azure AMQP Configure</name>
<description>Conigure of AMQP</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public class AzAmqpMessage extends AbstractTestElement {
private static final String MESSAGE_ID = "Message.messageId"; //$NON-NLS$
private static final String GROUP_ID = "Message.groupId"; //$NON-NLS$
private static final String PARTITION_KEY = "Message.partitionKey"; //$NON-NLS$
private static final String CUSTOM_PROPERTIES = "Message.customProperties"; //$NON-NLS$

public AzAmqpMessage() {
}

/**
* Create a new Message with the specified system properties and application properties
* Create a new Message with the specified system properties and custom properties
*
* @param messageType
* type of message
Expand All @@ -50,6 +51,7 @@ public AzAmqpMessage(String messageType) {
setProperty(new StringProperty(PARTITION_KEY, ""));
setProperty(new StringProperty(MESSAGE_ID, ""));
setProperty(new StringProperty(GROUP_ID, ""));
setProperty(new StringProperty(CUSTOM_PROPERTIES, ""));
}

/**
Expand Down Expand Up @@ -147,4 +149,23 @@ public String getPartitionKey() {
return getPropertyAsString(PARTITION_KEY);
}

/**
* Set the custom properties of the Message.
*
* @param newCustomProperties
* the new custom properties
*/
public void setCustomProperties(String newCustomProperties) {
setProperty(new StringProperty(CUSTOM_PROPERTIES, newCustomProperties));
}

/**
* Get the custom properties.
*
* @return the custom properties
*/
public String getCustomProperties() {
return getPropertyAsString(CUSTOM_PROPERTIES);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class AzAmqpMessagesPanel extends AbstractSamplerGui implements ActionLis
COLUMN_NAMES.put("MESSAGE", "message"); //$NON-NLS-1$
COLUMN_NAMES.put("MESSAGE_ID", "message Id"); //$NON-NLS-1$
COLUMN_NAMES.put("GROUP_ID", "group Id"); //$NON-NLS-1$
COLUMN_NAMES.put("CUSTOM_PROPERTIES", "custom properties"); //$NON-NLS-1$
}

public AzAmqpMessagesPanel() {
Expand Down
4 changes: 2 additions & 2 deletions plugins/protocol/eventhubs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-eventhubs</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<name>Azure Event Hubs Sampler</name>
<description>Sample to Azure Event Hubs</description>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>jp.co.pnop</groupId>
Expand Down
4 changes: 2 additions & 2 deletions plugins/protocol/servicebus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-servicebus</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>

<name>Azure Service Bus Sampler</name>
<description>Sample to Azure Service Bus</description>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>jp.co.pnop</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.ConfigTestElement;
Expand All @@ -44,6 +45,9 @@
import org.slf4j.LoggerFactory;

import com.azure.messaging.servicebus.*;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.core.amqp.exception.*;

import jp.co.pnop.jmeter.protocol.amqp.sampler.AzAmqpMessage;
Expand Down Expand Up @@ -272,6 +276,13 @@ public SampleResult sample(Entry e) {
serviceBusMessage.setPartitionKey(partitionKey);
requestBody = requestBody.concat("\n").concat("Partition Key: ").concat(partitionKey);
}

String customProperties = msg.getCustomProperties();
if (!customProperties.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> properties = mapper.readValue(customProperties, new TypeReference<Map<String, Object>>(){});
serviceBusMessage.getApplicationProperties().putAll(properties);
}

batch.tryAddMessage(serviceBusMessage);
bodyBytes += serviceBusMessage.getBody().toBytes().length;
Expand Down Expand Up @@ -334,18 +345,14 @@ public SampleResult sample(Entry e) {
}
responseMessage = responseMessage.concat(ex.getMessage());
res.setResponseData(ex.getMessage(), "UTF-8");
} catch (FileNotFoundException ex) {
} catch (FileNotFoundException | ClassCastException | JsonParseException ex){
log.info("Error calling {} sampler. ", threadName, ex);
res.setResponseData(ex.getMessage(), "UTF-8");
responseMessage = responseMessage.concat(ex.getMessage());
} catch (ServiceBusException ex) {
log.info("Error calling {} sampler. ", threadName, ex);
res.setResponseData(ex.toString(), "UTF-8");
responseMessage = responseMessage.concat(ex.toString());
} catch (ClassCastException ex) {
log.info("Error calling {} sampler. ", threadName, ex);
res.setResponseData(ex.getMessage(), "UTF-8");
responseMessage = responseMessage.concat(ex.getMessage());
} catch (Exception ex) {
log.info("Error calling {} sampler. ", threadName, ex);
res.setResponseData(ex.toString(), "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public AzServiceBusMessagesPanel() {
@Override
protected void initializeTableModel() {
tableModel = new ObjectTableModel(
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key" },
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CUSTOM_PROPERTIES") },
AzAmqpMessage.class,
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey") },
new Class[] { String.class, String.class, String.class, String.class, String.class }
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getCustomProperties") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setCustomProperties") },
new Class[] { String.class, String.class, String.class, String.class, String.class, String.class }
);
}

Expand Down

0 comments on commit 938e79b

Please sign in to comment.