Skip to content

Commit 3cf26e5

Browse files
author
Jerry Kuch
committed
Set up exchanges, queues and bindings for internal exchange test.
1 parent 83656b3 commit 3cf26e5

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.rabbitmq.client.AMQP.Tx;
4040
import com.rabbitmq.client.AMQP.Basic;
4141
import com.rabbitmq.client.AMQP.Channel.FlowOk;
42+
import com.rabbitmq.client.impl.AMQImpl;
4243

4344
/**
4445
* Public API: Interface to an AMQ channel. See the <a href="http://www.amqp.org/">spec</a> for details.
@@ -272,6 +273,29 @@ void basicPublish(String exchange, String routingKey, boolean mandatory, boolean
272273
Exchange.DeclareOk exchangeDeclare(String exchange, String type, boolean durable, boolean autoDelete,
273274
Map<String, Object> arguments) throws IOException;
274275

276+
/**
277+
* Declare an exchange, via an interface that allows the complete set of
278+
* arguments.
279+
* @see com.rabbitmq.client.AMQP.Exchange.Declare
280+
* @see com.rabbitmq.client.AMQP.Exchange.DeclareOk
281+
* @param exchange the name of the exchange
282+
* @param type the exchange type
283+
* @param durable true if we are declaring a durable exchange (the exchange will survive a server restart)
284+
* @param autoDelete true if the server should delete the exchange when it is no longer in use
285+
* @param internal true if the exchange is internal, i.e. can't be directly
286+
* published to by a client.
287+
* @param arguments other properties (construction arguments) for the exchange
288+
* @return a declaration-confirm method to indicate the exchange was successfully declared
289+
* @throws java.io.IOException if an error is encountered
290+
*/
291+
public AMQImpl.Exchange.DeclareOk exchangeDeclare(String exchange,
292+
String type,
293+
boolean durable,
294+
boolean autoDelete,
295+
boolean internal,
296+
Map<String, Object> arguments)
297+
throws IOException;
298+
275299
/**
276300
* Declare an exchange passively; that is, check if the named exchange exists.
277301
* @param name check the existence of an exchange named this

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,22 @@ public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
484484
false, false, arguments)).getMethod();
485485
}
486486

487+
/** Public API - {@inheritDoc} */
488+
public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
489+
boolean durable,
490+
boolean autoDelete,
491+
boolean internal,
492+
Map<String, Object> arguments)
493+
throws IOException
494+
{
495+
return (Exchange.DeclareOk)
496+
exnWrappingRpc(new Exchange.Declare(TICKET, exchange, type,
497+
false, durable, autoDelete,
498+
internal, false,
499+
arguments)).getMethod();
500+
}
501+
502+
487503
/** Public API - {@inheritDoc} */
488504
public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
489505
boolean durable)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2010 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.test.functional;
33+
34+
import com.rabbitmq.client.QueueingConsumer;
35+
import com.rabbitmq.client.test.BrokerTestCase;
36+
37+
import java.io.IOException;
38+
import java.util.Arrays;
39+
40+
41+
//
42+
// Functional test demonstrating use of an internal exchange in an exchange to
43+
// exchange routing scenario. The routing topology is:
44+
//
45+
// ------- -------
46+
// -/ \- -/ \-
47+
// / \ / \ +-------------+
48+
// | e0 +------| e1 +-----------+ q1 |
49+
// \ / \ / +-------------+
50+
// -\ /- -\ /-
51+
// ------- -------
52+
// (internal)
53+
//
54+
public class InternalExchangeTest extends BrokerTestCase
55+
{
56+
private final String[] queues = new String[] { "q1" };
57+
private final String[] exchanges = new String[] { "e0", "e1" };
58+
59+
private QueueingConsumer[] consumers =
60+
new QueueingConsumer[] { null, null, null };
61+
62+
protected void createResources() throws IOException
63+
{
64+
for (String q : queues)
65+
{
66+
channel.queueDeclare(q, false, false, false, null);
67+
}
68+
69+
// First exchange will be an 'internal' one.
70+
for ( String e : exchanges )
71+
{
72+
channel.exchangeDeclare(e, "direct",
73+
false, false,
74+
e.equals("e0") ? false : true,
75+
null);
76+
}
77+
78+
channel.exchangeBind("e1", "e0", "");
79+
channel.queueBind("q1", "e1", "");
80+
81+
}
82+
83+
@Override
84+
protected void releaseResources() throws IOException
85+
{
86+
for (String q : queues)
87+
{
88+
channel.queueDelete(q);
89+
}
90+
for (String e : exchanges)
91+
{
92+
channel.exchangeDelete(e);
93+
}
94+
}
95+
96+
97+
public void testOhForFucksSake() throws IOException, InterruptedException
98+
{
99+
System.out.println("Yes, there is a test here.");
100+
101+
// Create a simple consumer to try to catch stuff we've published...
102+
if(false)
103+
{
104+
QueueingConsumer consumer = new QueueingConsumer(channel);
105+
channel.basicConsume("q1", false, consumer);
106+
107+
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
108+
// process delivery
109+
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)