Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app_id to AMQP publisher #29

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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