Skip to content

Commit

Permalink
Merge pull request #10 from t-h-e/fix/purge-queue
Browse files Browse the repository at this point in the history
Purge queue in `sample` rather than `testEnded`
  • Loading branch information
aliesbelik authored May 21, 2022
2 parents a7180a7 + 0619ca8 commit acec348
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/main/java/com/zeroclue/jmeter/protocol/amqp/AMQPConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public SampleResult sample(Entry entry) {

try {
initChannel();

if (purgeQueue()) {
doPurgeQueue();
}

// only do this once per thread, otherwise it slows down the consumption by appx 50%
if (consumer == null) {
log.info("Creating consumer");
Expand Down Expand Up @@ -140,7 +145,6 @@ public SampleResult sample(Entry entry) {
/*
* Set up the sample result details
*/

result.setResponseMessage("OK");
result.setDataType(SampleResult.TEXT);
result.setResponseHeaders(delivery != null ? formatHeaders(delivery) : null);
Expand Down Expand Up @@ -193,6 +197,15 @@ public boolean purgeQueue() {
return Boolean.parseBoolean(getPurgeQueue());
}

private void doPurgeQueue() {
log.info("Purging queue {}", getQueue());
try {
channel.queuePurge(getQueue());
} catch (IOException e) {
log.error("Failed to purge queue " + getQueue(), e);
}
}

/**
* @return the whether or not to auto ack
*/
Expand Down Expand Up @@ -287,15 +300,6 @@ public boolean interrupt() {
@Override
public void testEnded() {

if (purgeQueue()) {
log.info("Purging queue {}", getQueue());

try {
channel.queuePurge(getQueue());
} catch (IOException e) {
log.error("Failed to purge queue " + getQueue(), e);
}
}
}

@Override
Expand Down

0 comments on commit acec348

Please # to comment.