Skip to content

Commit 80588e8

Browse files
author
Simon MacMullen
committed
Merge default into bug 22889.
2 parents b96d58a + b996275 commit 80588e8

29 files changed

+747
-194
lines changed

README-EXAMPLES

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Overview
2+
========
3+
4+
A number of examples are packaged with the source distribution and
5+
with the tests jar in the binary distribution. These examples vary in
6+
complexity from simple clients and servers through to complex test
7+
harnesses that are used for testing the RabbitMQ server.
8+
9+
The source code for the examples can be found in the
10+
test/src/com/rabbitmq/examples directory of the source distribution.
11+
12+
13+
Running the Examples
14+
====================
15+
16+
The script runjava.sh or runjava.bat can be found in the top level
17+
directory of the binary distribution or in the scripts directory of
18+
the source distribution.
19+
20+
This script can be used to run the examples. For instance, if you are
21+
using the binary distribution and if you have a RabbitMQ broker
22+
running and you open two shell or console windows you can test basic
23+
connectivity like this:
24+
25+
shell-1$ ./runjava.sh com.rabbitmq.examples.SimpleConsumer
26+
27+
shell-2$ ./runjava.sh com.rabbitmq.examples.SimpleProducer
28+
29+
shell-1$ ./runjava.sh com.rabbitmq.examples.SimpleConsumer
30+
Message: the time is Fri Feb 26 08:28:58 GMT 2010
31+
32+
Running the examples from the source distribution requries two more
33+
preliminary steps:
34+
35+
shell-1$ ant dist
36+
37+
shell-1$ cd build/dist/
38+
39+
Now, the examples can be run exactly as detailed above.
40+
41+
The more complex examples will require additional command line
42+
arguments and it is best to examine the source of the examples to
43+
determine what arguments are available.
44+
45+
All examples live in the com.rabbitmq.examples package, so just add
46+
that package name to the examples described below to produce the full
47+
classname that is required as the first argument to the runjava
48+
script.
49+
50+
51+
Simple Examples
52+
===============
53+
54+
SimpleProducer - Sends a message to an exchange.
55+
SimpleConsumer - Reads a message from a queue.
56+
SimpleTopicProducer - Sends a message to a topic exchange.
57+
SimpleTopicConsumer - Reads a message from a topic queue.
58+
SendString - Send a string to an exchange.
59+
FileProducer - Sends a file to an exchange.
60+
FileConsumer - Reads a file from a queue.
61+
HelloClient - Performs a simple RPC call over AMQP.
62+
HelloServer - Acts as an RPC server over AMQP.
63+
HelloJsonClient - Performs a simple JSON-RPC call over AMQP.
64+
HelloJsonServer - Acts as a JSON-RPC server over AMQP.
65+
LogTail - Tails the server logs.
66+
SendString - Sends a user supplied message over AMQP.
67+
68+
69+
More Complex Examples
70+
=====================
71+
72+
Most of these examples are used in testing and tuning the RabbitMQ
73+
server.
74+
75+
BufferPerformanceMetrics - Tests buffer sizing.
76+
ChannelCreationPerformance - Test different Channel creation strategies.
77+
ConsumerMain - Measures performance of Consumers.
78+
ManyConnections - Tests many connections.
79+
MulticastMain - Measures performance of multiple consumers and producers.
80+
ProducerMain - Measures performance of Producers.
81+
SpammyTopicProducer - Sends lots of different topic messages over AMQP.
82+
StressPersister - Stress test for persister.
83+
TestMain - RabbitMQ server regression tests.
84+
TracerConcurrencyTest - Tests correct concurrency behaviour of RabbitMQ tracer.

README-TESTS

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Overview
2+
========
3+
4+
There are multiple test suites in the RabbitMQ Java client library;
5+
the source for all of the suites can be found in the test/src
6+
directory.
7+
8+
The suites are:
9+
10+
Client tests
11+
Functional tests
12+
Server tests
13+
SSL tests
14+
15+
All the tests require a conforming server listening on localhost:5672
16+
(the default settings). For details on running specific tests, see
17+
below.
18+
19+
All the test suites can be run with the command ant test-suite. To run
20+
specific test suites see the instructions below.
21+
22+
23+
Running a Specific Test Suite
24+
=============================
25+
26+
To run a specific test suite, but not the others, you should execute
27+
one of the following in the top-level directory of the source tree:
28+
29+
ant test-client
30+
ant test-functional
31+
ant test-server
32+
ant test-ssl
33+
34+
Note that to run the SSL tests, the RabbitMQ server should be
35+
configured to use SSL as per the SSL with RabbitMQ guide.
36+
37+
The server tests are meant to test a RabbitMQ broker. Broadly, they
38+
require a running RabbitMQ broker on the default host/port, the source
39+
code for rabbitmq-server in ../rabbitmq-server, and a test directory
40+
../rabbitmq-test. Running them manually is a tricky business.
41+
42+
For example, to run the client tests:
43+
44+
----------------- Example shell session -------------------------------------
45+
rabbitmq-java-client$ ant test-client
46+
Buildfile: build.xml
47+
48+
test-prepare:
49+
50+
test-build:
51+
52+
amqp-generate-check:
53+
54+
amqp-generate:
55+
56+
build:
57+
58+
test-build-param:
59+
60+
test-client:
61+
[junit] Running com.rabbitmq.client.test.ClientTests
62+
[junit] Tests run: 31, Failures: 0, Errors: 0, Time elapsed: 2.388 sec
63+
64+
BUILD SUCCESSFUL
65+
-----------------------------------------------------------------------------
66+
67+
If any tests are broken details can be found by viewing this file:
68+
build/TEST-com.rabbitmq.client.test.ClientTests.txt

build.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</fail>
7878
</target>
7979

80-
<target name="build" depends="amqp-generate">
80+
<target name="build" depends="amqp-generate" description="Build the client library.">
8181
<mkdir dir="${javac.out}"/>
8282
<copy file="src/com/rabbitmq/client/impl/ClientVersion.java.in"
8383
tofile="${src.generated}/com/rabbitmq/client/impl/ClientVersion.java">
@@ -116,6 +116,10 @@
116116
<property name="SSL_P12_PASSWORD" value="${env.PASSWORD}"/>
117117
</target>
118118

119+
<target name="detect-umbrella">
120+
<available property="UMBRELLA_AVAILABLE" file="../rabbitmq-test"/>
121+
</target>
122+
119123
<target name="detect-tmpdir">
120124
<property environment="env"/>
121125
<condition property="TMPDIR" value="${env.TMPDIR}" else="/tmp">
@@ -317,7 +321,7 @@
317321
<property name="haltOnFailureJava" value="false" />
318322
</target>
319323

320-
<target name="test-suite" depends="test-suite-prepare, test-suite-run">
324+
<target name="test-suite" depends="test-suite-prepare, test-suite-run" description="Run all test suites.">
321325
<fail message="Errors occured in tests">
322326
<condition>
323327
<not>
@@ -329,7 +333,7 @@
329333

330334
<target name="test-suite-run" depends="test-client, test-ssl, test-server, test-functional, test-main-silent"/>
331335

332-
<target name="test-client" depends="test-build">
336+
<target name="test-client" depends="test-build" description="Run the client test suites.">
333337
<junit printSummary="withOutAndErr"
334338
haltOnFailure="${haltOnFailureJunit}"
335339
failureproperty="test.failure"
@@ -362,7 +366,7 @@
362366
<antcall target="remove-client-keystore"/>
363367
</target>
364368

365-
<target name="test-functional" depends="test-build">
369+
<target name="test-functional" depends="test-build" description="Run the functional test suite.">
366370
<junit printSummary="withOutAndErr"
367371
haltOnFailure="${haltOnFailureJunit}"
368372
failureproperty="test.failure"
@@ -375,7 +379,7 @@
375379
</junit>
376380
</target>
377381

378-
<target name="test-server" depends="test-build">
382+
<target name="test-server" depends="detect-umbrella, test-build" if="UMBRELLA_AVAILABLE">
379383
<junit printSummary="withOutAndErr"
380384
haltOnFailure="${haltOnFailureJunit}"
381385
failureproperty="test.failure"

src/com/rabbitmq/client/Connection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
*
4141
* <pre>
4242
* ConnectionFactory factory = new ConnectionFactory();
43-
* factory.setHostName(hostName);
43+
* factory.setHost(hostName);
44+
* factory.setPort(portNumber);
4445
* factory.setVirtualHost(virtualHost);
4546
* factory.setUsername(username);
4647
* factory.setPassword(password);

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public int getPort() {
135135
}
136136

137137
/**
138-
* @return the default port to use for connections
138+
* Set the target port.
139+
* @param port the default port to use for connections
139140
*/
140141
public void setPort(int port) {
141142
this.port = port;
@@ -244,7 +245,7 @@ public void setRequestedHeartbeat(int requestedHeartbeat) {
244245
* table. Such changes will take effect when the next new
245246
* connection is started using this factory.
246247
* @return the map of client properties
247-
* @see setClientProperties()
248+
* @see #setClientProperties
248249
*/
249250
public Map<String, Object> getClientProperties() {
250251
return _clientProperties;
@@ -254,7 +255,7 @@ public Map<String, Object> getClientProperties() {
254255
* Replace the table of client properties that will be sent to the
255256
* server during subsequent connection startups.
256257
* @param clientProperties the map of extra client properties
257-
* @see getClientProperties()
258+
* @see #getClientProperties
258259
*/
259260
public void setClientProperties(Map<String, Object> clientProperties) {
260261
_clientProperties = clientProperties;
@@ -345,13 +346,13 @@ protected FrameHandler createFrameHandler(Socket sock)
345346
}
346347

347348
/**
348-
* Provides a hook to insert custom configuration of the sockets used
349-
* to connect to an AMQP server before they connect.
349+
* Provides a hook to insert custom configuration of the sockets
350+
* used to connect to an AMQP server before they connect.
350351
*
351-
* The default behaviour of this method is to disable Nagle's algorithm to get
352-
* more consistently low latency.
353-
* However it may be overridden freely and there is no requirement to retain
354-
* this behaviour.
352+
* The default behaviour of this method is to disable Nagle's
353+
* algorithm to get more consistently low latency. However it
354+
* may be overridden freely and there is no requirement to retain
355+
* this behaviour.
355356
*
356357
* @param socket The socket that is to be used for the Connection
357358
*/

src/com/rabbitmq/client/QueueingConsumer.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,37 @@
4040
import com.rabbitmq.utility.Utility;
4141

4242
/**
43-
* Convenience class: an implementation of {@link Consumer} with straightforward blocking semantics
43+
* Convenience class: an implementation of {@link Consumer} with
44+
* straightforward blocking semantics.
45+
*
46+
* The general pattern for using QueueingConsumer is as follows:
47+
*
48+
* <pre>
49+
* // Create connection and channel.
50+
* {@link ConnectionFactory} factory = new ConnectionFactory();
51+
* Connection conn = factory.newConnection();
52+
* {@link Channel} ch1 = conn.createChannel();
53+
*
54+
* // Declare a queue and bind it to an exchange.
55+
* String queueName = ch1.queueDeclare().{@link AMQP.Queue.DeclareOk#getQueue getQueue}();
56+
* ch1.{@link Channel#queueBind queueBind}(queueName, exchangeName, queueName);
57+
*
58+
* // Create the QueueingConsumer and have it consume from the queue
59+
* QueueingConsumer consumer = new {@link QueueingConsumer#QueueingConsumer QueueingConsumer}(ch1);
60+
* ch1.{@link Channel#basicConsume basicConsume}(queueName, false, consumer);
61+
*
62+
* // Process deliveries
63+
* while (/* some condition * /) {
64+
* {@link QueueingConsumer.Delivery} delivery = consumer.{@link QueueingConsumer#nextDelivery nextDelivery}();
65+
* // process delivery
66+
* ch1.{@link Channel#basicAck basicAck}(delivery.{@link QueueingConsumer.Delivery#getEnvelope getEnvelope}().{@link Envelope#getDeliveryTag getDeliveryTag}(), false);
67+
* }
68+
* </pre>
69+
*
70+
* <p>For a more detailed explanation, see <a href="http://www.rabbitmq.com/api-guide.html#consuming">the java api guide</a>.</p>
71+
*
72+
* <p>For a more complete example, see LogTail in the test/src/com/rabbitmq/examples
73+
* directory of the source distribution.</p>
4474
*/
4575
public class QueueingConsumer extends DefaultConsumer {
4676
private final BlockingQueue<Delivery> _queue;

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,8 @@
5454
/**
5555
* Concrete class representing and managing an AMQP connection to a broker.
5656
* <p>
57-
* To connect to a broker,
58-
*
59-
* <pre>
60-
* AMQConnection conn = new AMQConnection(hostName, portNumber);
61-
* conn.open(username, portNumber, virtualHost);
62-
* </pre>
63-
*
64-
* <pre>
65-
* ChannelN ch1 = conn.createChannel(1);
66-
* ch1.open(&quot;&quot;);
67-
* </pre>
57+
* To create a broker connection, use {@link ConnectionFactory}. See {@link Connection}
58+
* for an example.
6859
*/
6960
public class AMQConnection extends ShutdownNotifierComponent implements Connection {
7061
/** Timeout used while waiting for AMQP handshaking to complete (milliseconds) */
@@ -79,7 +70,7 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti
7970
* method is called when each new ConnectionFactory instance is
8071
* constructed.
8172
* @return a map of client properties
82-
* @see Connection.getClientProperties()
73+
* @see Connection#getClientProperties
8374
*/
8475
public static Map<String, Object> defaultClientProperties() {
8576
return Frame.buildTable(new Object[] {
@@ -134,7 +125,7 @@ public static Map<String, Object> defaultClientProperties() {
134125

135126
/**
136127
* Protected API - respond, in the driver thread, to a ShutdownSignal.
137-
* @param channelNumber the number of the channel to disconnect
128+
* @param channel the channel to disconnect
138129
*/
139130
public final void disconnectChannel(ChannelN channel) {
140131
_channelManager.disconnectChannel(channel);

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
* To open a channel,
6565
* <pre>
6666
* {@link Connection} conn = ...;
67-
* {@link ChannelN} ch1 = conn.{@link Connection#createChannel createChannel}(1);
68-
* ch1.{@link ChannelN#open open}("");
67+
* {@link ChannelN} ch1 = conn.{@link Connection#createChannel createChannel}();
68+
* ch1.{@link ChannelN#open open}();
6969
* </pre>
7070
*/
7171
public class ChannelN extends AMQChannel implements com.rabbitmq.client.Channel {

0 commit comments

Comments
 (0)