Skip to content

Commit

Permalink
Adding support for specifying multiple hosts comma separated
Browse files Browse the repository at this point in the history
  • Loading branch information
chbatey committed Aug 14, 2014
1 parent b63e85e commit cfcf1b1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import java.util.*;
import java.security.*;

import com.rabbitmq.client.*;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

public abstract class AMQPSampler extends AbstractSampler implements ThreadListener {

Expand Down Expand Up @@ -73,7 +69,7 @@ protected boolean initChannel() throws IOException, NoSuchAlgorithmException, Ke
+ " closed unexpectedly: ", channel.getCloseReason());
channel = null; // so we re-open it below
}

if(channel == null) {
channel = createChannel();
setChannel(channel);
Expand Down Expand Up @@ -386,8 +382,6 @@ protected Channel createChannel() throws IOException, NoSuchAlgorithmException,
if (connection == null || !connection.isOpen()) {
factory.setConnectionTimeout(getTimeoutAsInt());
factory.setVirtualHost(getVirtualHost());
factory.setHost(getHost());
factory.setPort(getPortAsInt());
factory.setUsername(getUsername());
factory.setPassword(getPassword());
if (connectionSSL()) {
Expand All @@ -405,7 +399,13 @@ protected Channel createChannel() throws IOException, NoSuchAlgorithmException,
+"\nin " + this
);

connection = factory.newConnection();
String[] hosts = getHost().split(",");
Address[] addresses = new Address[hosts.length];
for (int i = 0; i < hosts.length; i++) {
addresses[i] = new Address(hosts[i], getPortAsInt());
}
log.info("Using hosts: " + Arrays.toString(hosts) + " addresses: " + Arrays.toString(addresses));
connection = factory.newConnection(addresses);
}

Channel channel = connection.createChannel();
Expand Down

0 comments on commit cfcf1b1

Please sign in to comment.