Skip to content

Commit

Permalink
Add app_id to AMQP publisher (see jlavallee#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliesbelik committed Oct 2, 2022
1 parent 53b63bc commit 308bc5f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/examples/rabbitmq-amqp-test.jmx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<stringProp name="AMQPPublisher.ContentType">application/json</stringProp>
<stringProp name="AMQPPublisher.ContentEncoding">utf-8</stringProp>
<stringProp name="AMQPPublisher.MessageId"></stringProp>
<stringProp name="AMQPPublisher.AppId"></stringProp>
<elementProp name="AMQPPublisher.Headers" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="cc" elementType="Argument">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String,Object> entry : headers.entrySet()) {
sb.append(entry.getKey())
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -303,6 +312,10 @@ protected AMQP.BasicProperties getProperties() {
builder.priority(DEFAULT_MESSAGE_PRIORITY);
}

if (getAppId() != null && !getAppId().isEmpty()) {
builder.appId(getAppId());
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);

Expand All @@ -206,6 +210,7 @@ public void clearGui() {
contentEncoding.setText(AMQPPublisher.DEFAULT_ENCODING);
messageId.setText("");
message.setText("");
appId.setText("");
headers.clearGui();
}

Expand Down

0 comments on commit 308bc5f

Please sign in to comment.