Skip to content

Commit 496435e

Browse files
author
Simon MacMullen
committed
Merge from default
2 parents 09eb09a + 239c5d6 commit 496435e

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
public 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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,28 @@ 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

538+
524539
/** Public API - {@inheritDoc} */
525540
public Exchange.DeclareOk exchangeDeclare(String exchange, String type,
526541
boolean durable)

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

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

0 commit comments

Comments
 (0)