From ebeec4d78ea43e973d284f34b8859caade328eac Mon Sep 17 00:00:00 2001
From: Aliaksandr Belik <1752374+aliesbelik@users.noreply.github.com>
Date: Sun, 2 Oct 2022 03:36:29 +0300
Subject: [PATCH] Add app_id to AMQP publisher (see jlavallee#37) (#29)
---
CHANGELOG.md | 4 ++++
docs/examples/rabbitmq-amqp-test.jmx | 1 +
.../zeroclue/jmeter/protocol/amqp/AMQPConsumer.java | 8 ++++++++
.../jmeter/protocol/amqp/AMQPPublisher.java | 13 +++++++++++++
.../jmeter/protocol/amqp/gui/AMQPPublisherGui.java | 5 +++++
5 files changed, 31 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a6f300..c5f31f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+
+* App_id message property for AMQP Publisher (see [jlavallee#37](https://github.com/jlavallee/JMeter-Rabbit-AMQP/issues/37)).
+
### Dependency Updates
* Up amqp-client version to 5.16.0.
diff --git a/docs/examples/rabbitmq-amqp-test.jmx b/docs/examples/rabbitmq-amqp-test.jmx
index ce15e8d..8a9fa41 100644
--- a/docs/examples/rabbitmq-amqp-test.jmx
+++ b/docs/examples/rabbitmq-amqp-test.jmx
@@ -81,6 +81,7 @@
application/json
utf-8
+
diff --git a/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPConsumer.java b/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPConsumer.java
index 8710e1a..f94ef5d 100644
--- a/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPConsumer.java
+++ b/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPConsumer.java
@@ -48,6 +48,7 @@ public class AMQPConsumer extends AMQPSampler implements Interruptible, TestStat
public static final String EXCHANGE_PARAMETER = "Exchange";
public static final String ROUTING_KEY_PARAMETER = "Routing Key";
public static final String DELIVERY_TAG_PARAMETER = "Delivery Tag";
+ public static final String APP_ID_PARAMETER = "Application ID";
public static final boolean DEFAULT_PURGE_QUEUE = false;
public static final boolean DEFAULT_AUTO_ACK = true;
@@ -381,6 +382,13 @@ private String formatHeaders(Delivery delivery) {
.append(delivery.getEnvelope().getDeliveryTag())
.append("\n");
+ if (delivery.getProperties().getAppId() != null) {
+ sb.append(APP_ID_PARAMETER)
+ .append(": ")
+ .append(delivery.getProperties().getAppId())
+ .append("\n");
+ }
+
if (headers != null) {
for (Map.Entry entry : headers.entrySet()) {
sb.append(entry.getKey())
diff --git a/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java b/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
index f5c1601..f321ccd 100644
--- a/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
+++ b/src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
@@ -50,6 +50,7 @@ public class AMQPPublisher extends AMQPSampler implements Interruptible {
private static final String HEADERS = "AMQPPublisher.Headers";
private static final String PERSISTENT = "AMQPPublisher.Persistent";
private static final String USE_TX = "AMQPPublisher.UseTx";
+ private static final String APP_ID = "AMQPPublisher.AppId";
public static final boolean DEFAULT_PERSISTENT = false;
public static final boolean DEFAULT_USE_TX = false;
@@ -264,6 +265,14 @@ public void setUseTx(Boolean tx) {
setProperty(USE_TX, tx);
}
+ public String getAppId() {
+ return getPropertyAsString(APP_ID);
+ }
+
+ public void setAppId(String appId) {
+ setProperty(APP_ID, appId);
+ }
+
@Override
public boolean interrupt() {
cleanup();
@@ -303,6 +312,10 @@ protected AMQP.BasicProperties getProperties() {
builder.priority(DEFAULT_MESSAGE_PRIORITY);
}
+ if (getAppId() != null && !getAppId().isEmpty()) {
+ builder.appId(getAppId());
+ }
+
return builder.build();
}
diff --git a/src/main/java/com/zeroclue/jmeter/protocol/amqp/gui/AMQPPublisherGui.java b/src/main/java/com/zeroclue/jmeter/protocol/amqp/gui/AMQPPublisherGui.java
index 6e24331..4d1d6b3 100644
--- a/src/main/java/com/zeroclue/jmeter/protocol/amqp/gui/AMQPPublisherGui.java
+++ b/src/main/java/com/zeroclue/jmeter/protocol/amqp/gui/AMQPPublisherGui.java
@@ -32,6 +32,7 @@ public class AMQPPublisherGui extends AMQPSamplerGui {
private final JLabeledTextField messagePriority = new JLabeledTextField(" Message Priority");
private final JLabeledTextField contentType = new JLabeledTextField(" Content-Type");
private final JLabeledTextField contentEncoding = new JLabeledTextField("Content Encoding");
+ private final JLabeledTextField appId = new JLabeledTextField(" Application ID");
private final JCheckBox persistent = new JCheckBox("Persistent", AMQPPublisher.DEFAULT_PERSISTENT);
private final JCheckBox useTx = new JCheckBox("Use Transactions", AMQPPublisher.DEFAULT_USE_TX);
@@ -83,6 +84,7 @@ public void configure(TestElement element) {
messagePriority.setText(sampler.getMessagePriority());
messageId.setText(sampler.getMessageId());
message.setText(sampler.getMessage());
+ appId.setText(sampler.getAppId());
configureHeaders(sampler);
}
@@ -121,6 +123,7 @@ public void modifyTestElement(TestElement te) {
sampler.setContentType(contentType.getText());
sampler.setContentEncoding(contentEncoding.getText());
sampler.setMessageId(messageId.getText());
+ sampler.setAppId(appId.getText());
sampler.setHeaders((Arguments) headers.createTestElement());
}
@@ -183,6 +186,7 @@ private JPanel initMessagePropertyPanel() {
propertyPanel.add(correlationId, constraints);
propertyPanel.add(messageId, constraints);
propertyPanel.add(messagePriority, constraints);
+ propertyPanel.add(appId, constraints);
propertyPanel.add(contentType, constraints);
propertyPanel.add(contentEncoding, constraints);
@@ -206,6 +210,7 @@ public void clearGui() {
contentEncoding.setText(AMQPPublisher.DEFAULT_ENCODING);
messageId.setText("");
message.setText("");
+ appId.setText("");
headers.clearGui();
}