Skip to content

Commit

Permalink
Add auto-delete property for exchange (see jlavallee#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliesbelik committed Oct 29, 2021
1 parent cd0c224 commit 6bcd436
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
21 changes: 16 additions & 5 deletions src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -33,7 +34,8 @@ public abstract class AMQPSampler extends AbstractSampler implements ThreadListe
"fanout"
};

public static final boolean DEFAULT_EXCHANGE_DURABLE = true;
public static final boolean DEFAULT_EXCHANGE_DURABLE = true;
public static final boolean DEFAULT_EXCHANGE_AUTO_DELETE = true;
public static final boolean DEFAULT_EXCHANGE_REDECLARE = false;
public static final boolean DEFAULT_QUEUE_REDECLARE = false;

Expand All @@ -54,6 +56,7 @@ public abstract class AMQPSampler extends AbstractSampler implements ThreadListe
protected static final String EXCHANGE_TYPE = "AMQPSampler.ExchangeType";
protected static final String EXCHANGE_DURABLE = "AMQPSampler.ExchangeDurable";
protected static final String EXCHANGE_REDECLARE = "AMQPSampler.ExchangeRedeclare";
protected static final String EXCHANGE_AUTO_DELETE = "AMQPSampler.ExchangeAutoDelete";
protected static final String QUEUE = "AMQPSampler.Queue";
protected static final String ROUTING_KEY = "AMQPSampler.RoutingKey";
protected static final String VIRTUAL_HOST = "AMQPSampler.VirtualHost";
Expand Down Expand Up @@ -112,7 +115,7 @@ protected boolean initChannel() throws IOException, NoSuchAlgorithmException, Ke
deleteExchange();
}

AMQP.Exchange.DeclareOk declareExchangeResp = channel.exchangeDeclare(getExchange(), getExchangeType(), getExchangeDurable());
AMQP.Exchange.DeclareOk declareExchangeResp = channel.exchangeDeclare(getExchange(), getExchangeType(), getExchangeDurable(), getExchangeAutoDelete(), Collections.<String, Object>emptyMap());

if (queueConfigured) {
channel.queueBind(getQueue(), getExchange(), getRoutingKey());
Expand Down Expand Up @@ -209,6 +212,14 @@ public String getExchangeType() {
return getPropertyAsString(EXCHANGE_TYPE);
}

public boolean getExchangeAutoDelete() {
return getPropertyAsBoolean(EXCHANGE_AUTO_DELETE);
}

public void setExchangeAutoDelete(boolean autoDelete) {
setProperty(EXCHANGE_AUTO_DELETE, autoDelete);
}

public void setExchangeType(String name) {
setProperty(EXCHANGE_TYPE, name);
}
Expand Down Expand Up @@ -349,7 +360,7 @@ public void setPassword(String name) {
}

/**
* @return the whether or not the queue is durable
* @return the whether the queue is durable
*/
public String getQueueDurable() {
return getPropertyAsString(QUEUE_DURABLE);
Expand All @@ -368,7 +379,7 @@ public boolean queueDurable() {
}

/**
* @return the whether or not the queue is exclusive
* @return the whether the queue is exclusive
*/
public String getQueueExclusive() {
return getPropertyAsString(QUEUE_EXCLUSIVE);
Expand All @@ -387,7 +398,7 @@ public boolean queueExclusive() {
}

/**
* @return the whether or not the queue should auto delete
* @return the whether the queue should auto delete
*/
public String getQueueAutoDelete() {
return getPropertyAsString(QUEUE_AUTO_DELETE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public abstract class AMQPSamplerGui extends AbstractSamplerGui {

private final JLabeledTextField exchange = new JLabeledTextField(" Exchange");
private final JLabeledChoice exchangeType = new JLabeledChoice(" Type ", AMQPSampler.EXCHANGE_TYPES, false, false);
private final JCheckBox exchangeRedeclare = new JCheckBox("Redeclare", AMQPSampler.DEFAULT_EXCHANGE_REDECLARE);
private final JCheckBox exchangeDurable = new JCheckBox("Durable", AMQPSampler.DEFAULT_EXCHANGE_DURABLE);
private final JCheckBox exchangeDurable = new JCheckBox("Durable", AMQPSampler.DEFAULT_EXCHANGE_DURABLE);
private final JCheckBox exchangeRedeclare = new JCheckBox("Redeclare", AMQPSampler.DEFAULT_EXCHANGE_REDECLARE);
private final JCheckBox exchangeAutoDelete = new JCheckBox("Auto Delete", AMQPSampler.DEFAULT_EXCHANGE_AUTO_DELETE);

protected JLabeledTextField queue = new JLabeledTextField(" Queue");
protected JLabeledTextField routingKey = new JLabeledTextField(" Routing Key");
Expand Down Expand Up @@ -60,6 +61,7 @@ public void configure(TestElement element) {
exchangeType.setText(sampler.getExchangeType());
exchangeDurable.setSelected(sampler.getExchangeDurable());
exchangeRedeclare.setSelected(sampler.getExchangeRedeclare());
exchangeAutoDelete.setSelected(sampler.getExchangeAutoDelete());

queue.setText(sampler.getQueue());
routingKey.setText(sampler.getRoutingKey());
Expand All @@ -68,9 +70,9 @@ public void configure(TestElement element) {
maxPriority.setText(sampler.getMaxPriority());

queueDurable.setSelected(sampler.queueDurable());
queueExclusive.setSelected(sampler.queueExclusive());
queueAutoDelete.setSelected(sampler.queueAutoDelete());
queueRedeclare.setSelected(sampler.getQueueRedeclare());
queueAutoDelete.setSelected(sampler.queueAutoDelete());
queueExclusive.setSelected(sampler.queueExclusive());

virtualHost.setText(sampler.getVirtualHost());
host.setText(sampler.getHost());
Expand All @@ -94,6 +96,7 @@ public void clearGui() {
exchangeType.setSelectedIndex(0);
exchangeDurable.setSelected(AMQPSampler.DEFAULT_EXCHANGE_DURABLE);
exchangeRedeclare.setSelected(AMQPSampler.DEFAULT_EXCHANGE_REDECLARE);
exchangeAutoDelete.setSelected(AMQPSampler.DEFAULT_EXCHANGE_AUTO_DELETE);

queue.setText("jmeterQueue");
routingKey.setText("jmeterRoutingKey");
Expand All @@ -102,9 +105,9 @@ public void clearGui() {
maxPriority.setText("");

queueDurable.setSelected(true);
queueExclusive.setSelected(false);
queueAutoDelete.setSelected(false);
queueRedeclare.setSelected(AMQPSampler.DEFAULT_QUEUE_REDECLARE);
queueAutoDelete.setSelected(false);
queueExclusive.setSelected(false);

virtualHost.setText("/");
host.setText("localhost");
Expand All @@ -127,9 +130,10 @@ public void modifyTestElement(TestElement element) {
configureTestElement(sampler);

sampler.setExchange(exchange.getText());
sampler.setExchangeType(exchangeType.getText());
sampler.setExchangeType(exchangeType.getText());
sampler.setExchangeDurable(exchangeDurable.isSelected());
sampler.setExchangeRedeclare(exchangeRedeclare.isSelected());
sampler.setExchangeAutoDelete(exchangeAutoDelete.isSelected());

sampler.setQueue(queue.getText());
sampler.setRoutingKey(routingKey.getText());
Expand All @@ -138,9 +142,9 @@ public void modifyTestElement(TestElement element) {
sampler.setMaxPriority(maxPriority.getText());

sampler.setQueueDurable(queueDurable.isSelected());
sampler.setQueueExclusive(queueExclusive.isSelected());
sampler.setQueueAutoDelete(queueAutoDelete.isSelected());
sampler.setQueueRedeclare(queueRedeclare.isSelected());
sampler.setQueueAutoDelete(queueAutoDelete.isSelected());
sampler.setQueueExclusive(queueExclusive.isSelected());

sampler.setVirtualHost(virtualHost.getText());
sampler.setHost(host.getText());
Expand Down Expand Up @@ -207,6 +211,10 @@ private Component makeCommonPanel() {
gridBagConstraints.gridy = 1;
exchangeSettings.add(exchangeRedeclare, gridBagConstraints);

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
exchangeSettings.add(exchangeAutoDelete, gridBagConstraints);

exchangeType.setPreferredSize(exchange.getPreferredSize());
exchangeSettings.validate();
//exchangeSettings.repaint();
Expand Down Expand Up @@ -241,15 +249,15 @@ private Component makeCommonPanel() {

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
queueSettings.add(queueExclusive, gridBagConstraints);
queueSettings.add(queueRedeclare, gridBagConstraints);

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
queueSettings.add(queueAutoDelete, gridBagConstraints);

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
queueSettings.add(queueRedeclare, gridBagConstraints);
queueSettings.add(queueExclusive, gridBagConstraints);

gridBagConstraintsCommon.gridx = 0;
gridBagConstraintsCommon.gridy = 0;
Expand Down

0 comments on commit 6bcd436

Please sign in to comment.