}
public void publishOneInOneOutReceive(int backlogSize, int bodySize, int repeatCount, int sampleGranularity) throws IOException, InterruptedException {
String q = "test";
BasicProperties props = MessageProperties.MINIMAL_PERSISTENT_BASIC;
Connection conn = newConnection();
Channel chan = conn.createChannel();
byte[] body = new byte[bodySize];
List<Long> plateauSampleTimes = new ArrayList<Long>(repeatCount);
List<Double> plateauSampleDeltas = new ArrayList<Double>(repeatCount);
trace("Declaring and purging queue " + q);
chan.queueDeclare(q, true, false, false, null);
chan.queuePurge(q);
chan.basicQos(1);
trace("Building backlog out to " + backlogSize + " messages, each " + bodySize + " bytes long");
for (int i = 0; i < backlogSize; i++) {
chan.basicPublish("", q, props, body);
}
redeclare(q, chan);
trace("Beginning plateau of " + repeatCount + " repeats, sampling every " + sampleGranularity + " messages");
QueueingConsumer consumer = new QueueingConsumer(chan);
chan.basicConsume(q, consumer);
long startTime = System.currentTimeMillis();
for (int i = 0; i < repeatCount; i++) {
if (((i % sampleGranularity) == 0) && (i > 0)) {
long now = System.currentTimeMillis();
double delta = 1000 * (now - startTime) / (double) sampleGranularity;
plateauSampleTimes.add(now);
plateauSampleDeltas.add(delta);
System.out.print(String.format("# %3d%%; %012d --> %g microseconds/roundtrip \r",
(100 * i / repeatCount),
now,
delta));
startTime = System.currentTimeMillis();
}
chan.basicPublish("", q, props, body);
QueueingConsumer.Delivery d = consumer.nextDelivery();
chan.basicAck(d.getEnvelope().getDeliveryTag(), false);
}
System.out.println();
trace("Switching QOS to unlimited");
chan.basicQos(0);
trace("Draining backlog");
for (int i = 0; i < backlogSize; i++) {
QueueingConsumer.Delivery d = consumer.nextDelivery();
chan.basicAck(d.getEnvelope().getDeliveryTag(), false);
}
redeclare(q, chan);
trace("Closing connection");
chan.close();
conn.close();
trace("Sample results (timestamp in milliseconds since epoch; microseconds/roundtrip)");
System.out.println("(See log file for results; final sample was " +
plateauSampleDeltas.get(plateauSampleDeltas.size() - 1) + ")");
for (int i = 0; i < plateauSampleTimes.size(); i++) {