Skip to content

Commit

Permalink
Merge pull request #17 from evenex-pkra/feature/amqp-headers
Browse files Browse the repository at this point in the history
Adding support for amqp custom headers.
  • Loading branch information
jlavallee committed Oct 1, 2014
2 parents 073ee2b + 8c45acf commit d745790
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.rabbitmq.client.AMQP;
import java.io.IOException;
import java.security.*;
import java.util.*;

import com.rabbitmq.client.MessageProperties;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.Interruptible;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

Expand Down Expand Up @@ -35,6 +38,7 @@ public class AMQPPublisher extends AMQPSampler implements Interruptible {
private final static String MESSAGE_TYPE = "AMQPPublisher.MessageType";
private final static String REPLY_TO_QUEUE = "AMQPPublisher.ReplyToQueue";
private final static String CORRELATION_ID = "AMQPPublisher.CorrelationId";
private final static String HEADERS = "AMQPPublisher.Headers";

public static boolean DEFAULT_PERSISTENT = false;
private final static String PERSISTENT = "AMQPConsumer.Persistent";
Expand Down Expand Up @@ -78,6 +82,7 @@ public SampleResult sample(Entry e) {
result.sampleStart(); // Start timing
try {
AMQP.BasicProperties messageProperties = getProperties();
messageProperties.setHeaders(prepareHeaders());
byte[] messageBytes = getMessageBytes();

for (int idx = 0; idx < loop; idx++) {
Expand Down Expand Up @@ -176,6 +181,13 @@ public void setCorrelationId(String content) {
setProperty(CORRELATION_ID, content);
}

public Arguments getHeaders() {
return (Arguments) getProperty(HEADERS).getObjectValue();
}

public void setHeaders(Arguments headers) {
setProperty(new TestElementProperty(HEADERS, headers));
}

public Boolean getPersistent() {
return getPropertyAsBoolean(PERSISTENT, DEFAULT_PERSISTENT);
Expand Down Expand Up @@ -232,4 +244,13 @@ protected boolean initChannel() throws IOException, NoSuchAlgorithmException, Ke
}
return ret;
}

private Map<String, Object> prepareHeaders() {
Map<String, Object> result = new HashMap<String, Object>();
Map<String, String> source = getHeaders().getArgumentsAsMap();
for (Map.Entry<String, String> item : source.entrySet()) {
result.put(item.getKey(), item.getValue());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import javax.swing.*;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.gui.ArgumentsPanel;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.gui.JLabeledTextArea;
import org.apache.jorphan.gui.JLabeledTextField;
Expand Down Expand Up @@ -40,6 +42,8 @@ public class AMQPPublisherGui extends AMQPSamplerGui {
private JCheckBox persistent = new JCheckBox("Persistent?", AMQPPublisher.DEFAULT_PERSISTENT);
private JCheckBox useTx = new JCheckBox("Use Transactions?", AMQPPublisher.DEFAULT_USE_TX);

private ArgumentsPanel headers = new ArgumentsPanel("Headers");

public AMQPPublisherGui(){
init();
}
Expand Down Expand Up @@ -74,6 +78,7 @@ public void configure(TestElement element) {
replyToQueue.setText(sampler.getReplyToQueue());
correlationId.setText(sampler.getCorrelationId());
message.setText(sampler.getMessage());
configureHeaders(sampler);
}

/**
Expand Down Expand Up @@ -105,6 +110,7 @@ public void modifyTestElement(TestElement te) {
sampler.setMessageType(messageType.getText());
sampler.setReplyToQueue(replyToQueue.getText());
sampler.setCorrelationId(correlationId.getText());
sampler.setHeaders((Arguments) headers.createTestElement());
}

@Override
Expand Down Expand Up @@ -132,6 +138,7 @@ protected final void init() {
mainPanel.add(messageType);
mainPanel.add(replyToQueue);
mainPanel.add(correlationId);
mainPanel.add(headers);
mainPanel.add(message);
}

Expand All @@ -147,6 +154,17 @@ public void clearGui() {
messageType.setText("");
replyToQueue.setText("");
correlationId.setText("");
headers.clearGui();
message.setText("");
}

private void configureHeaders(AMQPPublisher sampler)
{
Arguments sampleHeaders = sampler.getHeaders();
if (sampleHeaders != null) {
headers.configure(sampleHeaders);
} else {
headers.clearGui();
}
}
}

0 comments on commit d745790

Please sign in to comment.