Skip to content

Commit 1ae8142

Browse files
committed
ARTEMIS-6034 Close the connection factory when the CLI perf client command ends
1 parent 012e63b commit 1ae8142

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/PerfClientCommand.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.netty.channel.EventLoop;
3232
import org.apache.activemq.artemis.cli.commands.ActionContext;
3333
import org.apache.activemq.artemis.cli.commands.messages.ConnectionProtocol;
34+
import org.apache.activemq.artemis.cli.factory.ConnectionFactoryClosable;
3435
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
3536
import picocli.CommandLine.Command;
3637
import picocli.CommandLine.Option;
@@ -98,7 +99,6 @@ public class PerfClientCommand extends PerfCommand {
9899
protected void onExecuteBenchmark(final ConnectionFactory producerConnectionFactory, final Destination[] jmsDestinations, final ActionContext context) throws Exception {
99100
final ConnectionProtocol listenerProtocol = Objects.requireNonNullElse(this.consumerProtocol, protocol);
100101
final String listenerUrl = Objects.requireNonNullElse(this.consumerUrl, brokerURL);
101-
final ConnectionFactory consumerConnectionFactory = createConnectionFactory(listenerUrl, user, password, null, listenerProtocol);
102102
if (consumerConnections == 0) {
103103
if (sharedSubscription > 0) {
104104
if (getClientID() == null) {
@@ -122,17 +122,18 @@ protected void onExecuteBenchmark(final ConnectionFactory producerConnectionFact
122122
boolean warmingUp = warmup != 0;
123123
final LiveStatistics statistics;
124124
final StringBuilder skratchBuffer = new StringBuilder();
125-
try (MessageListenerBenchmark consumerBenchmark = new MessageListenerBenchmarkBuilder()
126-
.setClientID(getClientID())
127-
.setDestinations(consumerProtocol != null ? lookupDestinations(consumerConnectionFactory) : jmsDestinations)
128-
.setFactory(consumerConnectionFactory)
129-
.setTransacted(transaction)
130-
.setConsumers(consumersPerDestination)
131-
.setConnections(consumerConnections)
132-
.setTimeProvider(() -> TimeUnit.NANOSECONDS.toMicros(System.nanoTime()))
133-
.setCanDelayMessageCount(true)
134-
.setSharedSubscription(sharedSubscription)
135-
.setDurableSubscription(durableSubscription)
125+
try (ConnectionFactoryClosable consumerConnectionFactory = createConnectionFactory(listenerUrl, user, password, null, listenerProtocol);
126+
MessageListenerBenchmark consumerBenchmark = new MessageListenerBenchmarkBuilder()
127+
.setClientID(getClientID())
128+
.setDestinations(consumerProtocol != null ? lookupDestinations(consumerConnectionFactory) : jmsDestinations)
129+
.setFactory(consumerConnectionFactory)
130+
.setTransacted(transaction)
131+
.setConsumers(consumersPerDestination)
132+
.setConnections(consumerConnections)
133+
.setTimeProvider(() -> TimeUnit.NANOSECONDS.toMicros(System.nanoTime()))
134+
.setCanDelayMessageCount(true)
135+
.setSharedSubscription(sharedSubscription)
136+
.setDurableSubscription(durableSubscription)
136137
.createMessageListenerBenchmark()) {
137138

138139
final DefaultEventLoopGroup eventLoopGroup = new DefaultEventLoopGroup(threads) {

0 commit comments

Comments
 (0)