Skip to content

Commit fbd526e

Browse files
author
Emile Joubert
committed
Rebase bug22942 on bug22772
1 parent 7596a9f commit fbd526e

File tree

4 files changed

+192
-49
lines changed

4 files changed

+192
-49
lines changed

projects/client/RabbitMQ.Client/src/client/api/IModel.cs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,11 @@ public interface IModel: IDisposable
169169
void ExchangeDeclare(string exchange, string type);
170170

171171
///<summary>(Spec method) Declare an exchange.</summary>
172-
void ExchangeDeclare(string exchange,
173-
string type,
174-
bool passive,
175-
bool durable,
176-
[AmqpFieldMapping("RabbitMQ.Client.Framing.v0_9_1", "reserved2")]
177-
bool autoDelete,
178-
[AmqpFieldMapping("RabbitMQ.Client.Framing.v0_9_1", "reserved3")]
179-
bool @internal,
180-
[AmqpNowaitArgument(null)]
181-
bool nowait,
182-
IDictionary arguments);
172+
///<remarks>
173+
/// The exchange is declared passive.
174+
/// </remarks>
175+
[AmqpMethodDoNotImplement(null)]
176+
void ExchangeDeclarePassive(string exchange);
183177

184178
///<summary>(Spec method) Delete an exchange.</summary>
185179
void ExchangeDelete(string exchange,
@@ -205,6 +199,9 @@ void ExchangeDelete(string exchange,
205199
[AmqpMethodDoNotImplement(null)]
206200
string QueueDeclare(string queue);
207201

202+
[AmqpMethodDoNotImplement(null)]
203+
string QueueDeclarePassive(string queue);
204+
208205
///<summary>(Spec method) Declare a queue.</summary>
209206
///<remarks>
210207
///The queue is declared non-passive, non-exclusive, and
@@ -215,18 +212,9 @@ string QueueDeclare(string queue,
215212
bool durable);
216213

217214
///<summary>(Spec method) Declare a queue.</summary>
218-
///<remarks>
219-
///Returns the name of the queue that was declared.
220-
///</remarks>
221-
[return: AmqpFieldMapping(null, "queue")]
222-
string QueueDeclare(string queue,
223-
bool passive,
224-
bool durable,
225-
bool exclusive,
226-
bool autoDelete,
227-
[AmqpNowaitArgument(null)]
228-
bool nowait,
229-
IDictionary arguments);
215+
[AmqpMethodDoNotImplement(null)]
216+
string QueueDeclare(string queue, bool durable, bool exclusive,
217+
bool autoDelete, IDictionary arguments);
230218

231219
///<summary>(Spec method) Bind a queue to an exchange.</summary>
232220
void QueueBind(string queue,
@@ -524,6 +512,35 @@ namespace RabbitMQ.Client.Impl
524512
///<see cref="RabbitMQ.Client.Framing.Impl.v0_9.Model"/>
525513
public interface IFullModel : RabbitMQ.Client.IModel
526514
{
515+
///<summary>Used to send a Exchange.Declare method. Called by the
516+
///public declare method.
517+
///</summary>
518+
[AmqpMethodMapping(null, "exchange", "declare")]
519+
void _Private_ExchangeDeclare(string exchange,
520+
string type,
521+
bool passive,
522+
bool durable,
523+
[AmqpFieldMapping("RabbitMQ.Client.Framing.v0_9_1", "reserved2")]
524+
bool autoDelete,
525+
[AmqpFieldMapping("RabbitMQ.Client.Framing.v0_9_1", "reserved3")]
526+
bool @internal,
527+
[AmqpNowaitArgument(null)]
528+
bool nowait,
529+
IDictionary arguments);
530+
531+
///<summary>Used to send a Queue.Declare method. Called by the
532+
///public declare method.</summary>
533+
[AmqpMethodMapping(null, "queue", "declare")]
534+
[return: AmqpFieldMapping(null, "queue")]
535+
string _Private_QueueDeclare(string queue,
536+
bool passive,
537+
bool durable,
538+
bool exclusive,
539+
bool autoDelete,
540+
[AmqpNowaitArgument(null)]
541+
bool nowait,
542+
IDictionary arguments);
543+
527544
///<summary>Used to send a Basic.Publish method. Called by the
528545
///public publish method after potential null-reference issues
529546
///have been rectified.</summary>

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public event CallbackExceptionEventHandler CallbackException
146146
m_callbackException -= value;
147147
}
148148
}
149-
}
150-
149+
}
150+
151151
public IBasicConsumer DefaultConsumer { get; set; }
152152

153153
public ISession m_session;
@@ -499,25 +499,35 @@ public void FinishClose()
499499
public abstract IStreamProperties CreateStreamProperties();
500500

501501
public abstract void ChannelFlow(bool active);
502-
502+
503+
public void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, IDictionary arguments)
504+
{
505+
_Private_ExchangeDeclare(exchange, type, false, durable, autoDelete, false, false, arguments);
506+
}
507+
503508
public void ExchangeDeclare(string exchange, string type, bool durable)
504509
{
505-
ExchangeDeclare(exchange, type, false, durable, false, false, false, null);
510+
ExchangeDeclare(exchange, type, durable, false, null);
506511
}
507512

508513
public void ExchangeDeclare(string exchange, string type)
509514
{
510-
ExchangeDeclare(exchange, type, false, false, false, false, false, null);
515+
ExchangeDeclare(exchange, type, false);
516+
}
517+
518+
public void ExchangeDeclarePassive(string exchange)
519+
{
520+
_Private_ExchangeDeclare(exchange, "", true, false, false, false, false, null);
511521
}
512522

513-
public abstract void ExchangeDeclare(string exchange,
514-
string type,
515-
bool passive,
516-
bool durable,
517-
bool autoDelete,
518-
bool @internal,
519-
bool nowait,
520-
IDictionary arguments);
523+
public abstract void _Private_ExchangeDeclare(string exchange,
524+
string type,
525+
bool passive,
526+
bool durable,
527+
bool autoDelete,
528+
bool @internal,
529+
bool nowait,
530+
IDictionary arguments);
521531

522532
public abstract void ExchangeDelete(string exchange,
523533
bool ifUnused,
@@ -527,26 +537,37 @@ public abstract void ExchangeDelete(string exchange,
527537
// of dealing with missing parameters.
528538
public string QueueDeclare()
529539
{
530-
return QueueDeclare("", false, false, true, true, false, null);
540+
return _Private_QueueDeclare("", false, false, true, true, false, null);
531541
}
532542

533543
public string QueueDeclare(string queue)
534544
{
535-
return QueueDeclare(queue, false);
545+
return _Private_QueueDeclare(queue, true, false, false, false, false, null);
546+
}
547+
548+
public string QueueDeclarePassive(string queue)
549+
{
550+
return _Private_QueueDeclare(queue, true, false, false, false, false, null);
536551
}
537552

538553
public string QueueDeclare(string queue, bool durable)
539554
{
540-
return QueueDeclare(queue, false, durable, false, false, false, null);
555+
return _Private_QueueDeclare(queue, false, durable, false, false, false, null);
556+
}
557+
558+
public string QueueDeclare(string queue, bool durable, bool exclusive,
559+
bool autoDelete, IDictionary arguments)
560+
{
561+
return _Private_QueueDeclare(queue, false, durable, exclusive, autoDelete, false, arguments);
541562
}
542563

543-
public abstract string QueueDeclare(string queue,
544-
bool passive,
545-
bool durable,
546-
bool exclusive,
547-
bool autoDelete,
548-
bool nowait,
549-
IDictionary arguments);
564+
public abstract string _Private_QueueDeclare(string queue,
565+
bool passive,
566+
bool durable,
567+
bool exclusive,
568+
bool autoDelete,
569+
bool nowait,
570+
IDictionary arguments);
550571

551572
public abstract void QueueBind(string queue,
552573
string exchange,
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2010 LShift Ltd., Cohesive Financial
8+
// Technologies LLC., and Rabbit Technologies Ltd.
9+
//
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at
13+
//
14+
// http://www.Apache.Org/licenses/LICENSE-2.0
15+
//
16+
// Unless required by applicable law or agreed to in writing, software
17+
// distributed under the License is distributed on an "AS IS" BASIS,
18+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
// See the License for the specific language governing permissions and
20+
// limitations under the License.
21+
//---------------------------------------------------------------------------
22+
//
23+
// The MPL v1.1:
24+
//
25+
//---------------------------------------------------------------------------
26+
// The contents of this file are subject to the Mozilla Public License
27+
// Version 1.1 (the "License"); you may not use this file except in
28+
// compliance with the License. You may obtain a copy of the License at
29+
// http://www.Rabbitmq.Com/mpl.Html
30+
//
31+
// Software distributed under the License is distributed on an "AS IS"
32+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
33+
// License for the specific language governing rights and limitations
34+
// under the License.
35+
//
36+
// The Original Code is The RabbitMQ .NET Client.
37+
//
38+
// The Initial Developers of the Original Code are LShift Ltd,
39+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
40+
//
41+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
42+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
43+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
44+
// Technologies LLC, and Rabbit Technologies Ltd.
45+
//
46+
// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift
47+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
48+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
49+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
50+
// (C) 2007-2010 Rabbit Technologies Ltd.
51+
//
52+
// All Rights Reserved.
53+
//
54+
// Contributor(s): ______________________________________.
55+
//
56+
//---------------------------------------------------------------------------
57+
using NUnit.Framework;
58+
using RabbitMQ.Client;
59+
using RabbitMQ.Client.Exceptions;
60+
61+
namespace RabbitMQ.Client.Unit
62+
{
63+
64+
[TestFixture]
65+
public class TestPassiveDeclare
66+
{
67+
IConnection connection;
68+
IModel ch;
69+
70+
[SetUp]
71+
public void Connect()
72+
{
73+
connection = new ConnectionFactory().CreateConnection();
74+
ch = connection.CreateModel();
75+
}
76+
77+
[TearDown]
78+
public void Disconnect()
79+
{
80+
ch.Close();
81+
connection.Close();
82+
}
83+
84+
[Test]
85+
public void TestExchangePassiveDeclare()
86+
{
87+
try
88+
{
89+
ch.ExchangeDeclarePassive("non-existent-exchange");
90+
Assert.Fail("Passive declare of an unknown exchange should fail");
91+
}
92+
catch (OperationInterruptedException) { }
93+
}
94+
95+
[Test]
96+
public void TestQueuePassiveDeclare()
97+
{
98+
try
99+
{
100+
ch.QueueDeclarePassive("non-existent-queue");
101+
Assert.Fail("Passive declare of an unknown queue should fail");
102+
}
103+
catch (OperationInterruptedException) { }
104+
}
105+
}
106+
}

projects/examples/client/DeclareQueue/src/examples/DeclareQueue.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ public static int Main(string[] args) {
106106
{
107107
using (IModel ch = conn.CreateModel()) {
108108

109-
string finalName = ch.QueueDeclare(inputQueueName, false,
110-
durable, false, false,
111-
false, arguments);
109+
string finalName = ch.QueueDeclare(inputQueueName, durable,
110+
false, false, arguments);
112111
Console.WriteLine("{0}\t{1}", finalName, durable);
113112

114113
while ((optionIndex + 1) < args.Length) {

0 commit comments

Comments
 (0)