Skip to content

Commit 7786a40

Browse files
author
Emile Joubert
committed
Make queue declare response more consistent with Java API
1 parent 29be40f commit 7786a40

File tree

6 files changed

+170
-45
lines changed

6 files changed

+170
-45
lines changed

projects/client/ApigenBootstrap/RabbitMQ.Client.ApigenBootstrap.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<Compile Include="..\RabbitMQ.Client\src\client\api\PublicationAddress.cs">
6767
<Link>src\client\api\PublicationAddress.cs</Link>
6868
</Compile>
69-
<Compile Include="..\RabbitMQ.Client\src\client\api\QueueDeclareResult.cs">
70-
<Link>src\client\api\QueueDeclareResult.cs</Link>
69+
<Compile Include="..\RabbitMQ.Client\src\client\api\QueueDeclareOk.cs">
70+
<Link>src\client\api\QueueDeclareOk.cs</Link>
7171
</Compile>
7272
<Compile Include="..\RabbitMQ.Client\src\client\api\ShutdownEventArgs.cs">
7373
<Link>src\client\api\ShutdownEventArgs.cs</Link>

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void ExchangeUnbind(string destination,
242242
///name is the return value of this method.
243243
///</remarks>
244244
[AmqpMethodDoNotImplement(null)]
245-
string QueueDeclare();
245+
QueueDeclareOk QueueDeclare();
246246

247247
///<summary>Declare a queue passively.</summary>
248248
///<remarks>
@@ -251,18 +251,13 @@ void ExchangeUnbind(string destination,
251251
///The queue is declared passively; i.e. only check if it exists.
252252
///</remarks>
253253
[AmqpMethodDoNotImplement(null)]
254-
string QueueDeclarePassive(string queue);
254+
QueueDeclareOk QueueDeclarePassive(string queue);
255255

256256
///<summary>(Spec method) Declare a queue.</summary>
257257
[AmqpMethodDoNotImplement(null)]
258-
string QueueDeclare(string queue, bool durable, bool exclusive,
258+
QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive,
259259
bool autoDelete, IDictionary arguments);
260260

261-
///<summary>(Spec method) Declare a queue.</summary>
262-
[AmqpMethodDoNotImplement(null)]
263-
QueueDeclareResult QueueDeclareFull(string queue, bool passive, bool durable, bool exclusive,
264-
bool autoDelete, bool nowait, IDictionary arguments);
265-
266261
///<summary>(Spec method) Bind a queue to an exchange.</summary>
267262
[AmqpMethodDoNotImplement(null)]
268263
void QueueBind(string queue,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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-2011 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is VMware, Inc.
38+
// Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
namespace RabbitMQ.Client
42+
{
43+
public class QueueDeclareOk {
44+
public string QueueName { get; private set; }
45+
public uint MessageCount { get; private set; }
46+
public uint ConsumerCount { get; private set; }
47+
48+
public QueueDeclareOk(string queueName, uint messageCount, uint consumerCount) {
49+
this.QueueName = queueName;
50+
this.MessageCount = messageCount;
51+
this.ConsumerCount = consumerCount;
52+
}
53+
54+
public static implicit operator string(QueueDeclareOk declareOk)
55+
{
56+
return declareOk.QueueName;
57+
}
58+
}
59+
}

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -851,35 +851,36 @@ public abstract void _Private_ExchangeUnbind(string destination,
851851

852852
//TODO: Mark these as virtual, maybe the model has an optimized way
853853
// of dealing with missing parameters.
854-
public string QueueDeclare()
854+
public QueueDeclareOk QueueDeclare()
855855
{
856856
return QueueDeclare("", false, true, true, null);
857857
}
858858

859-
public string QueueDeclarePassive(string queue)
859+
public QueueDeclareOk QueueDeclarePassive(string queue)
860860
{
861-
return QueueDeclareFull(queue, true, false, false, false, false, null).Queue;
861+
return QueueDeclare(queue, true, false, false, false, null);
862862
}
863863

864-
public string QueueDeclare(string queue, bool durable, bool exclusive,
864+
public QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive,
865865
bool autoDelete, IDictionary arguments)
866866
{
867-
return QueueDeclareFull(queue, false, durable, exclusive, autoDelete, false, arguments).Queue;
867+
return QueueDeclare(queue, false, durable, exclusive, autoDelete, arguments);
868868
}
869869

870870
public class QueueDeclareRpcContinuation : SimpleBlockingRpcContinuation
871871
{
872-
public QueueDeclareResult m_result;
872+
public QueueDeclareOk m_result;
873873
public QueueDeclareRpcContinuation() { }
874874
}
875-
public QueueDeclareResult QueueDeclareFull(string queue, bool passive, bool durable, bool exclusive,
876-
bool autoDelete, bool nowait, IDictionary arguments)
875+
876+
private QueueDeclareOk QueueDeclare(string queue, bool passive, bool durable, bool exclusive,
877+
bool autoDelete, IDictionary arguments)
877878
{
878879
QueueDeclareRpcContinuation k = new QueueDeclareRpcContinuation();
879880
Enqueue(k);
880881
try
881882
{
882-
_Private_QueueDeclare(queue, false, durable, exclusive, autoDelete, false, arguments);
883+
_Private_QueueDeclare(queue, passive, durable, exclusive, autoDelete, false, arguments);
883884
}
884885
catch (AlreadyClosedException)
885886
{
@@ -1497,14 +1498,14 @@ public abstract void _Private_ConnectionClose(ushort replyCode,
14971498

14981499
public abstract void _Private_ConnectionCloseOk();
14991500

1500-
public void HandleQueueDeclareOk(string queue,
1501-
uint messageCount,
1501+
public void HandleQueueDeclareOk(string queue,
1502+
uint messageCount,
15021503
uint consumerCount)
15031504
{
15041505
QueueDeclareRpcContinuation k = (QueueDeclareRpcContinuation)m_continuationQueue.Next();
1505-
k.m_result = new QueueDeclareResult(queue,
1506-
messageCount,
1507-
consumerCount);
1506+
k.m_result = new QueueDeclareOk(queue,
1507+
messageCount,
1508+
consumerCount);
15081509
k.HandleCommand(null); // release the continuation.
15091510
}
15101511

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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-2011 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is VMware, Inc.
38+
// Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using System;
42+
using NUnit.Framework;
43+
using RabbitMQ.Client.Exceptions;
44+
45+
namespace RabbitMQ.Client.Unit
46+
{
47+
[TestFixture]
48+
public class TestComplexResults : IntegrationFixture
49+
{
50+
51+
private readonly String QueueName = "declare-ok-test-queue";
52+
53+
[Test]
54+
public void TestQueueDeclareOk()
55+
{
56+
QueueDeclareOk result;
57+
58+
result = QueueDeclare();
59+
Assert.AreEqual(0, result.MessageCount);
60+
Assert.AreEqual(0, result.ConsumerCount);
61+
Assert.AreEqual(QueueName, result.QueueName);
62+
Model.BasicPublish("", result.QueueName, null, new byte[] { });
63+
64+
result = QueueDeclare();
65+
Assert.AreEqual(1, result.MessageCount);
66+
Assert.AreEqual(0, result.ConsumerCount);
67+
Assert.AreEqual(QueueName, result.QueueName);
68+
69+
QueueingBasicConsumer consumer = new QueueingBasicConsumer(Model);
70+
Model.BasicConsume(QueueName, true, consumer);
71+
consumer.Queue.Dequeue();
72+
73+
result = QueueDeclare();
74+
Assert.AreEqual(0, result.MessageCount);
75+
Assert.AreEqual(1, result.ConsumerCount);
76+
Assert.AreEqual(QueueName, result.QueueName);
77+
}
78+
79+
[Test]
80+
public void TestQueueDeclarePassive()
81+
{
82+
Assert.Throws(Is.TypeOf<OperationInterruptedException>(),
83+
delegate { Model.QueueDeclarePassive(QueueName); });
84+
}
85+
86+
private QueueDeclareOk QueueDeclare()
87+
{
88+
return Model.QueueDeclare(QueueName, false, true, true, null);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)