Skip to content

Commit 8e7c939

Browse files
author
Marek Majkowski
committed
default merged into bug20570
2 parents 63758e8 + 6fab1d3 commit 8e7c939

File tree

4 files changed

+145
-5
lines changed

4 files changed

+145
-5
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void basicPublish(String exchange, String routingKey, boolean mandatory, boolean
271271
Exchange.DeclareOk exchangeDeclare(String exchange, String type, boolean durable) throws IOException;
272272

273273
/**
274-
* Declare an exchange, via an interface that allows the complete set of arguments.
274+
* Declare an exchange.
275275
* @see com.rabbitmq.client.AMQP.Exchange.Declare
276276
* @see com.rabbitmq.client.AMQP.Exchange.DeclareOk
277277
* @param exchange the name of the exchange
@@ -285,6 +285,28 @@ void basicPublish(String exchange, String routingKey, boolean mandatory, boolean
285285
Exchange.DeclareOk exchangeDeclare(String exchange, String type, boolean durable, boolean autoDelete,
286286
Map<String, Object> arguments) throws IOException;
287287

288+
/**
289+
* Declare an exchange, via an interface that allows the complete set of
290+
* arguments.
291+
* @see com.rabbitmq.client.AMQP.Exchange.Declare
292+
* @see com.rabbitmq.client.AMQP.Exchange.DeclareOk
293+
* @param exchange the name of the exchange
294+
* @param type the exchange type
295+
* @param durable true if we are declaring a durable exchange (the exchange will survive a server restart)
296+
* @param autoDelete true if the server should delete the exchange when it is no longer in use
297+
* @param internal true if the exchange is internal, i.e. can't be directly
298+
* published to by a client.
299+
* @param arguments other properties (construction arguments) for the exchange
300+
* @return a declaration-confirm method to indicate the exchange was successfully declared
301+
* @throws java.io.IOException if an error is encountered
302+
*/
303+
Exchange.DeclareOk exchangeDeclare(String exchange,
304+
String type,
305+
boolean durable,
306+
boolean autoDelete,
307+
boolean internal,
308+
Map<String, Object> arguments) throws IOException;
309+
288310
/**
289311
* Declare an exchange passively; that is, check if the named exchange exists.
290312
* @param name check the existence of an exchange named this

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,25 @@ public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
514514
boolean durable, boolean autoDelete,
515515
Map<String, Object> arguments)
516516
throws IOException
517+
{
518+
return exchangeDeclare(exchange, type,
519+
durable, autoDelete, false,
520+
arguments);
521+
}
522+
523+
/** Public API - {@inheritDoc} */
524+
public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
525+
boolean durable,
526+
boolean autoDelete,
527+
boolean internal,
528+
Map<String, Object> arguments)
529+
throws IOException
517530
{
518531
return (Exchange.DeclareOk)
519-
exnWrappingRpc(new Exchange.Declare(TICKET, exchange, type,
520-
false, durable, autoDelete,
521-
false, false, arguments)).getMethod();
532+
exnWrappingRpc(new Exchange.Declare(TICKET, exchange, type,
533+
false, durable, autoDelete,
534+
internal, false,
535+
arguments)).getMethod();
522536
}
523537

524538
/** Public API - {@inheritDoc} */

test/src/com/rabbitmq/client/test/functional/FunctionalTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static TestSuite suite() {
7272
suite.addTestSuite(PerQueueTTL.class);
7373
suite.addTestSuite(SaslMechanisms.class);
7474
suite.addTestSuite(UserIDHeader.class);
75-
75+
suite.addTestSuite(InternalExchange.class);
7676
return suite;
7777
}
7878
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.AMQP;
35+
import com.rabbitmq.client.DefaultConsumer;
36+
import com.rabbitmq.client.GetResponse;
37+
import com.rabbitmq.client.test.BrokerTestCase;
38+
39+
import java.io.IOException;
40+
import java.util.Arrays;
41+
42+
43+
//
44+
// Functional test demonstrating use of an internal exchange in an exchange to
45+
// exchange routing scenario. The routing topology is:
46+
//
47+
// ------- -------
48+
// -/ \- -/ \-
49+
// / \ / \ +-------------+
50+
// | e0 +------| e1 +-----------+ q1 |
51+
// \ / \ / +-------------+
52+
// -\ /- -\ /-
53+
// ------- -------
54+
// (internal)
55+
//
56+
// Where a non-internal exchange is bound to an internal exchange, which in
57+
// turn is bound to a queue. A client should be able to publish to e0, but
58+
// not to e1, and publications to e0 should be delivered into q1.
59+
//
60+
public class InternalExchange extends BrokerTestCase
61+
{
62+
private final String[] queues = new String[] { "q1" };
63+
private final String[] exchanges = new String[] { "e0", "e1" };
64+
65+
protected void createResources() throws IOException
66+
{
67+
// The queues and exchange we create here are all auto-delete, so we
68+
// don't need to override releaseResources() with their deletions...
69+
for (String q : queues)
70+
{
71+
channel.queueDeclare(q, false, true, true, null);
72+
}
73+
74+
// The second exchange, "e1", will be an 'internal' one.
75+
for ( String e : exchanges )
76+
{
77+
channel.exchangeDeclare(e, "direct",
78+
false, true,
79+
!e.equals("e0"),
80+
null);
81+
}
82+
83+
channel.exchangeBind("e1", "e0", "");
84+
channel.queueBind("q1", "e1", "");
85+
}
86+
87+
88+
public void testTryPublishingToInternalExchange()
89+
throws IOException
90+
{
91+
byte[] testDataBody = "test-data".getBytes();
92+
93+
// We should be able to publish to the non-internal exchange as usual
94+
// and see our message land in the queue...
95+
channel.basicPublish("e0", "", null, testDataBody);
96+
GetResponse r = channel.basicGet("q1", true);
97+
assertTrue(Arrays.equals(r.getBody(), testDataBody));
98+
99+
// Publishing to the internal exchange will not be allowed...
100+
channel.basicPublish("e1", "", null, testDataBody);
101+
102+
expectError(AMQP.ACCESS_REFUSED);
103+
}
104+
}

0 commit comments

Comments
 (0)