|
6 | 6 | import com.rabbitmq.client.MessageProperties;
|
7 | 7 | import com.rabbitmq.client.Consumer;
|
8 | 8 | import com.rabbitmq.client.QueueingConsumer;
|
| 9 | +import com.rabbitmq.client.AMQP.Queue; |
9 | 10 |
|
10 | 11 | import java.net.Socket;
|
11 | 12 | import java.io.IOException;
|
|
19 | 20 | */
|
20 | 21 | public class BufferPerformanceMetrics {
|
21 | 22 |
|
22 |
| - public static final String QUEUE = "performance-test-queue"; |
23 |
| - public static final String EXCHANGE = "performance-test-exchange"; |
24 |
| - public static final String ROUTING_KEY = "performance-test-rk"; |
25 | 23 | public static final int MESSAGE_COUNT = 100000;
|
26 | 24 | public static final byte[] MESSAGE = "Hello world".getBytes();
|
27 | 25 | public static final int REPEATS = 1000000;
|
@@ -61,21 +59,20 @@ public void configureSocket(Socket socket)
|
61 | 59 |
|
62 | 60 | Connection connection = factory.newConnection(hostName);
|
63 | 61 | Channel channel = connection.createChannel();
|
64 |
| - channel.exchangeDeclare(EXCHANGE, "direct"); |
65 |
| - channel.queueDeclare(QUEUE); |
66 |
| - channel.queueBind(QUEUE, EXCHANGE, ROUTING_KEY); |
| 62 | + Queue.DeclareOk res = channel.queueDeclare(); |
| 63 | + String queueName = res.getQueue(); |
67 | 64 |
|
68 | 65 | long start;
|
69 | 66 |
|
70 | 67 | start = System.nanoTime();
|
71 | 68 |
|
72 | 69 | for(int i = 0; i < MESSAGE_COUNT; i++) {
|
73 |
| - channel.basicPublish(EXCHANGE, ROUTING_KEY, |
| 70 | + channel.basicPublish("", queueName, |
74 | 71 | MessageProperties.BASIC, MESSAGE);
|
75 | 72 | }
|
76 | 73 |
|
77 | 74 | QueueingConsumer consumer = new QueueingConsumer(channel);
|
78 |
| - channel.basicConsume(QUEUE, true, consumer); |
| 75 | + channel.basicConsume(queueName, true, consumer); |
79 | 76 |
|
80 | 77 | long publishTime = System.nanoTime() - start;
|
81 | 78 |
|
|
0 commit comments