|
16 | 16 |
|
17 | 17 | package com.rabbitmq.examples;
|
18 | 18 |
|
19 |
| -import java.util.Arrays; |
20 |
| -import java.util.List; |
21 |
| - |
22 |
| -import com.rabbitmq.examples.perf.MulticastParams; |
23 |
| -import com.rabbitmq.examples.perf.MulticastSet; |
24 |
| -import com.rabbitmq.examples.perf.Stats; |
25 |
| -import org.apache.commons.cli.CommandLine; |
26 |
| -import org.apache.commons.cli.CommandLineParser; |
27 |
| -import org.apache.commons.cli.GnuParser; |
28 |
| -import org.apache.commons.cli.HelpFormatter; |
29 |
| -import org.apache.commons.cli.Option; |
30 |
| -import org.apache.commons.cli.Options; |
31 |
| -import org.apache.commons.cli.ParseException; |
32 |
| - |
33 |
| -import com.rabbitmq.client.ConnectionFactory; |
34 |
| - |
35 |
| - |
| 19 | +/** |
| 20 | + * TODO: delete this after a suitable time has passed |
| 21 | + */ |
36 | 22 | public class MulticastMain {
|
37 | 23 | public static void main(String[] args) {
|
38 |
| - Options options = getOptions(); |
39 |
| - CommandLineParser parser = new GnuParser(); |
40 |
| - try { |
41 |
| - CommandLine cmd = parser.parse(options, args); |
42 |
| - |
43 |
| - if (cmd.hasOption('?')) { |
44 |
| - usage(options); |
45 |
| - System.exit(0); |
46 |
| - } |
47 |
| - |
48 |
| - String exchangeType = strArg(cmd, 't', "direct"); |
49 |
| - String exchangeName = strArg(cmd, 'e', exchangeType); |
50 |
| - String queueName = strArg(cmd, 'u', ""); |
51 |
| - String routingKey = strArg(cmd, 'k', null); |
52 |
| - int samplingInterval = intArg(cmd, 'i', 1); |
53 |
| - float rateLimit = floatArg(cmd, 'r', 0.0f); |
54 |
| - int producerCount = intArg(cmd, 'x', 1); |
55 |
| - int consumerCount = intArg(cmd, 'y', 1); |
56 |
| - int producerTxSize = intArg(cmd, 'm', 0); |
57 |
| - int consumerTxSize = intArg(cmd, 'n', 0); |
58 |
| - long confirm = intArg(cmd, 'c', -1); |
59 |
| - boolean autoAck = cmd.hasOption('a'); |
60 |
| - int multiAckEvery = intArg(cmd, 'A', 0); |
61 |
| - int prefetchCount = intArg(cmd, 'q', 0); |
62 |
| - int minMsgSize = intArg(cmd, 's', 0); |
63 |
| - int timeLimit = intArg(cmd, 'z', 0); |
64 |
| - int producerMsgCount = intArg(cmd, 'C', 0); |
65 |
| - int consumerMsgCount = intArg(cmd, 'D', 0); |
66 |
| - List<?> flags = lstArg(cmd, 'f'); |
67 |
| - int frameMax = intArg(cmd, 'M', 0); |
68 |
| - int heartbeat = intArg(cmd, 'b', 0); |
69 |
| - boolean predeclared = cmd.hasOption('p'); |
70 |
| - |
71 |
| - String uri = strArg(cmd, 'h', "amqp://localhost"); |
72 |
| - |
73 |
| - boolean exclusive = "".equals(queueName); |
74 |
| - |
75 |
| - //setup |
76 |
| - PrintlnStats stats = new PrintlnStats(1000L * samplingInterval, |
77 |
| - producerCount > 0, |
78 |
| - consumerCount > 0, |
79 |
| - (flags.contains("mandatory") || |
80 |
| - flags.contains("immediate")), |
81 |
| - confirm != -1); |
82 |
| - |
83 |
| - ConnectionFactory factory = new ConnectionFactory(); |
84 |
| - factory.setUri(uri); |
85 |
| - factory.setRequestedFrameMax(frameMax); |
86 |
| - factory.setRequestedHeartbeat(heartbeat); |
87 |
| - |
88 |
| - |
89 |
| - MulticastParams p = new MulticastParams(); |
90 |
| - p.setAutoAck( autoAck); |
91 |
| - p.setAutoDelete( !exclusive); |
92 |
| - p.setConfirm( confirm); |
93 |
| - p.setConsumerCount( consumerCount); |
94 |
| - p.setConsumerMsgCount( consumerMsgCount); |
95 |
| - p.setConsumerTxSize( consumerTxSize); |
96 |
| - p.setExchangeName( exchangeName); |
97 |
| - p.setExchangeType( exchangeType); |
98 |
| - p.setExclusive( exclusive); |
99 |
| - p.setFlags( flags); |
100 |
| - p.setMultiAckEvery( multiAckEvery); |
101 |
| - p.setMinMsgSize( minMsgSize); |
102 |
| - p.setPredeclared( predeclared); |
103 |
| - p.setPrefetchCount( prefetchCount); |
104 |
| - p.setProducerCount( producerCount); |
105 |
| - p.setProducerMsgCount( producerMsgCount); |
106 |
| - p.setProducerTxSize( producerTxSize); |
107 |
| - p.setQueueName( queueName); |
108 |
| - p.setRoutingKey( routingKey); |
109 |
| - p.setRateLimit( rateLimit); |
110 |
| - p.setTimeLimit( timeLimit); |
111 |
| - |
112 |
| - MulticastSet set = new MulticastSet(stats, factory, p); |
113 |
| - set.run(true); |
114 |
| - |
115 |
| - stats.printFinal(); |
116 |
| - } |
117 |
| - catch( ParseException exp ) { |
118 |
| - System.err.println("Parsing failed. Reason: " + exp.getMessage()); |
119 |
| - usage(options); |
120 |
| - } catch (Exception e) { |
121 |
| - System.err.println("Main thread caught exception: " + e); |
122 |
| - e.printStackTrace(); |
123 |
| - System.exit(1); |
124 |
| - } |
125 |
| - } |
126 |
| - |
127 |
| - private static void usage(Options options) { |
128 |
| - HelpFormatter formatter = new HelpFormatter(); |
129 |
| - formatter.printHelp("<program>", options); |
130 |
| - } |
131 |
| - |
132 |
| - private static Options getOptions() { |
133 |
| - Options options = new Options(); |
134 |
| - options.addOption(new Option("?", "help", false,"show usage")); |
135 |
| - options.addOption(new Option("h", "uri", true, "AMQP URI")); |
136 |
| - options.addOption(new Option("t", "type", true, "exchange type")); |
137 |
| - options.addOption(new Option("e", "exchange", true, "exchange name")); |
138 |
| - options.addOption(new Option("u", "queue", true, "queue name")); |
139 |
| - options.addOption(new Option("k", "routingKey", true, "routing key")); |
140 |
| - options.addOption(new Option("i", "interval", true, "sampling interval")); |
141 |
| - options.addOption(new Option("r", "rate", true, "rate limit")); |
142 |
| - options.addOption(new Option("x", "producers", true, "producer count")); |
143 |
| - options.addOption(new Option("y", "consumers", true, "consumer count")); |
144 |
| - options.addOption(new Option("m", "ptxsize", true, "producer tx size")); |
145 |
| - options.addOption(new Option("n", "ctxsize", true, "consumer tx size")); |
146 |
| - options.addOption(new Option("c", "confirm", true, "max unconfirmed publishes")); |
147 |
| - options.addOption(new Option("a", "autoack", false,"auto ack")); |
148 |
| - options.addOption(new Option("A", "multiAckEvery", true, "multi ack every")); |
149 |
| - options.addOption(new Option("q", "qos", true, "qos prefetch count")); |
150 |
| - options.addOption(new Option("s", "size", true, "message size")); |
151 |
| - options.addOption(new Option("z", "time", true, "time limit")); |
152 |
| - options.addOption(new Option("C", "pmessages", true, "producer message count")); |
153 |
| - options.addOption(new Option("D", "cmessages", true, "consumer message count")); |
154 |
| - Option flag = new Option("f", "flag", true, "message flag"); |
155 |
| - flag.setArgs(Option.UNLIMITED_VALUES); |
156 |
| - options.addOption(flag); |
157 |
| - options.addOption(new Option("M", "framemax", true, "frame max")); |
158 |
| - options.addOption(new Option("b", "heartbeat", true, "heartbeat interval")); |
159 |
| - options.addOption(new Option("p", "predeclared", false,"allow use of predeclared objects")); |
160 |
| - return options; |
161 |
| - } |
162 |
| - |
163 |
| - private static String strArg(CommandLine cmd, char opt, String def) { |
164 |
| - return cmd.getOptionValue(opt, def); |
165 |
| - } |
166 |
| - |
167 |
| - private static int intArg(CommandLine cmd, char opt, int def) { |
168 |
| - return Integer.parseInt(cmd.getOptionValue(opt, Integer.toString(def))); |
169 |
| - } |
170 |
| - |
171 |
| - private static float floatArg(CommandLine cmd, char opt, float def) { |
172 |
| - return Float.parseFloat(cmd.getOptionValue(opt, Float.toString(def))); |
173 |
| - } |
174 |
| - |
175 |
| - private static List<?> lstArg(CommandLine cmd, char opt) { |
176 |
| - String[] vals = cmd.getOptionValues('f'); |
177 |
| - if (vals == null) { |
178 |
| - vals = new String[] {}; |
179 |
| - } |
180 |
| - return Arrays.asList(vals); |
181 |
| - } |
182 |
| - |
183 |
| - private static class PrintlnStats extends Stats { |
184 |
| - private boolean sendStatsEnabled; |
185 |
| - private boolean recvStatsEnabled; |
186 |
| - private boolean returnStatsEnabled; |
187 |
| - private boolean confirmStatsEnabled; |
188 |
| - |
189 |
| - public PrintlnStats(long interval, |
190 |
| - boolean sendStatsEnabled, boolean recvStatsEnabled, |
191 |
| - boolean returnStatsEnabled, boolean confirmStatsEnabled) { |
192 |
| - super(interval); |
193 |
| - this.sendStatsEnabled = sendStatsEnabled; |
194 |
| - this.recvStatsEnabled = recvStatsEnabled; |
195 |
| - this.returnStatsEnabled = returnStatsEnabled; |
196 |
| - this.confirmStatsEnabled = confirmStatsEnabled; |
197 |
| - } |
198 |
| - |
199 |
| - @Override |
200 |
| - protected void report(long now) { |
201 |
| - System.out.print("time: " + String.format("%.3f", (now - startTime)/1000.0) + "s"); |
202 |
| - |
203 |
| - showRate("sent", sendCountInterval, sendStatsEnabled, elapsedInterval); |
204 |
| - showRate("returned", returnCountInterval, sendStatsEnabled && returnStatsEnabled, elapsedInterval); |
205 |
| - showRate("confirmed", confirmCountInterval, sendStatsEnabled && confirmStatsEnabled, elapsedInterval); |
206 |
| - showRate("nacked", nackCountInterval, sendStatsEnabled && confirmStatsEnabled, elapsedInterval); |
207 |
| - showRate("received", recvCountInterval, recvStatsEnabled, elapsedInterval); |
208 |
| - |
209 |
| - System.out.print((latencyCountInterval > 0 ? |
210 |
| - ", min/avg/max latency: " + |
211 |
| - minLatency/1000L + "/" + |
212 |
| - cumulativeLatencyInterval / (1000L * latencyCountInterval) + "/" + |
213 |
| - maxLatency/1000L + " microseconds" : |
214 |
| - "")); |
215 |
| - |
216 |
| - System.out.println(); |
217 |
| - } |
218 |
| - |
219 |
| - private void showRate(String descr, long count, boolean display, |
220 |
| - long elapsed) { |
221 |
| - if (display) { |
222 |
| - System.out.print(", " + descr + ": " + formatRate(1000.0 * count / elapsed) + " msg/s"); |
223 |
| - } |
224 |
| - } |
225 |
| - |
226 |
| - public void printFinal() { |
227 |
| - long now = System.currentTimeMillis(); |
228 |
| - |
229 |
| - System.out.println("sending rate avg: " + |
230 |
| - formatRate(sendCountTotal * 1000.0 / (now - startTime)) + |
231 |
| - " msg/s"); |
232 |
| - |
233 |
| - long elapsed = now - startTime; |
234 |
| - if (elapsed > 0) { |
235 |
| - System.out.println("recving rate avg: " + |
236 |
| - formatRate(recvCountTotal * 1000.0 / elapsed) + |
237 |
| - " msg/s"); |
238 |
| - } |
239 |
| - } |
240 |
| - |
241 |
| - private static String formatRate(double rate) { |
242 |
| - if (rate == 0.0) return String.format("%d", (long)rate); |
243 |
| - else if (rate < 1) return String.format("%1.2f", rate); |
244 |
| - else if (rate < 10) return String.format("%1.1f", rate); |
245 |
| - else return String.format("%d", (long)rate); |
246 |
| - } |
| 24 | + System.out.println(); |
| 25 | + System.out.println("********************************************************"); |
| 26 | + System.out.println("* NOTE: *"); |
| 27 | + System.out.println("* com.rabbitmq.examples.MulticastMain is now known as *"); |
| 28 | + System.out.println("* com.rabbitmq.examples.PerfTest *"); |
| 29 | + System.out.println("* *"); |
| 30 | + System.out.println("********************************************************"); |
| 31 | + System.out.println(); |
| 32 | + System.exit(1); |
247 | 33 | }
|
248 | 34 | }
|
0 commit comments