Skip to content

Commit 4764491

Browse files
author
Alexandru Scvortov
committed
ConfirmDontLoseMessages: make msgCount a command-line parameter
1 parent fd30317 commit 4764491

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

test/src/com/rabbitmq/examples/ConfirmDontLoseMessages.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,24 @@
4646
import java.io.IOException;
4747

4848
public class ConfirmDontLoseMessages {
49-
final static int MSG_COUNT = 10000;
49+
static int msgCount = 10000;
5050
final static String QUEUE_NAME = "confirm-test";
5151
static ConnectionFactory connectionFactory;
5252

5353
public static void main(String[] args)
5454
throws IOException, InterruptedException
5555
{
56+
if (args.length > 0) {
57+
msgCount = Integer.parseInt(args[0]);
58+
}
59+
60+
System.out.printf("msgCount = %d\n", msgCount);
61+
5662
connectionFactory = new ConnectionFactory();
5763

58-
// Publish MSG_COUNT messages and wait for confirms.
64+
// Publish msgCount messages and wait for confirms.
5965
(new Thread(new Consumer())).start();
60-
// Consume MSG_COUNT messages.
66+
// Consume msgCount messages.
6167
(new Thread(new Publisher())).start();
6268
}
6369

@@ -87,7 +93,7 @@ public void handleAck(long seqNo,
8793
ch.confirmSelect();
8894

8995
// Publish
90-
for (long i = 0; i < MSG_COUNT; ++i) {
96+
for (long i = 0; i < msgCount; ++i) {
9197
ackSet.add(i);
9298
ch.basicPublish("", QUEUE_NAME,
9399
MessageProperties.PERSISTENT_BASIC,
@@ -124,7 +130,7 @@ public void run() {
124130
// Consume
125131
QueueingConsumer qc = new QueueingConsumer(ch);
126132
ch.basicConsume(QUEUE_NAME, true, qc);
127-
for (int i = 0; i < MSG_COUNT; ++i) {
133+
for (int i = 0; i < msgCount; ++i) {
128134
qc.nextDelivery();
129135
}
130136

0 commit comments

Comments
 (0)