|
28 | 28 | import com.rabbitmq.client.AMQP; |
29 | 29 | import com.rabbitmq.client.Channel; |
30 | 30 | import com.rabbitmq.client.ConnectionFactory; |
| 31 | +import com.rabbitmq.client.ConnectionParameters; |
31 | 32 | import com.rabbitmq.client.Connection; |
32 | 33 | import com.rabbitmq.client.QueueingConsumer; |
33 | 34 |
|
34 | 35 | public class ManyConnections { |
35 | 36 | public static double rate; |
36 | 37 | public static int connectionCount; |
37 | 38 | public static int channelPerConnectionCount; |
| 39 | + public static int heartbeatInterval; |
38 | 40 |
|
39 | 41 | public static int totalCount() { |
40 | 42 | return connectionCount * channelPerConnectionCount; |
41 | 43 | } |
42 | 44 |
|
43 | 45 | public static void main(String[] args) { |
44 | 46 | try { |
45 | | - if (args.length < 3) { |
46 | | - System.err.println("Usage: ManyConnections hostName connCount chanPerConnCount [rate [port]]"); |
| 47 | + if (args.length < 4) { |
| 48 | + System.err.println("Usage: ManyConnections hostName connCount chanPerConnCount heartbeatInterval [rate [port]]"); |
47 | 49 | System.exit(2); |
48 | 50 | } |
49 | 51 |
|
50 | 52 | String hostName = args[0]; |
51 | 53 | connectionCount = Integer.parseInt(args[1]); |
52 | 54 | channelPerConnectionCount = Integer.parseInt(args[2]); |
53 | | - rate = (args.length > 3) ? Double.parseDouble(args[3]) : 1.0; |
54 | | - int portNumber = (args.length > 4) ? Integer.parseInt(args[4]) : AMQP.PROTOCOL.PORT; |
| 55 | + heartbeatInterval = Integer.parseInt(args[3]); |
| 56 | + rate = (args.length > 4) ? Double.parseDouble(args[4]) : 1.0; |
| 57 | + int portNumber = (args.length > 5) ? Integer.parseInt(args[5]) : AMQP.PROTOCOL.PORT; |
55 | 58 |
|
| 59 | + ConnectionParameters params = new ConnectionParameters(); |
| 60 | + params.setRequestedHeartbeat(heartbeatInterval); |
56 | 61 | for (int i = 0; i < connectionCount; i++) { |
57 | | - final Connection conn = new ConnectionFactory().newConnection(hostName, portNumber); |
| 62 | + System.out.println("Starting connection "+i); |
| 63 | + final Connection conn = new ConnectionFactory(params).newConnection(hostName, portNumber); |
58 | 64 |
|
59 | 65 | for (int j = 0; j < channelPerConnectionCount; j++) { |
60 | 66 | final Channel ch = conn.createChannel(); |
|
0 commit comments