Skip to content

Commit 490d6db

Browse files
Merge branch 'danielmarbach-batch-readonlymemory'
2 parents a654b1e + c17a222 commit 490d6db

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

projects/RabbitMQ.Client/client/api/IBasicPublishBatch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737
// The Initial Developer of the Original Code is Pivotal Software, Inc.
3838
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
40+
4041
using System;
4142

4243
namespace RabbitMQ.Client
4344
{
4445
public interface IBasicPublishBatch
4546
{
47+
[Obsolete("Use Add(string exchange, string routingKey, bool mandatory, IBasicProperties properties, ReadOnlyMemory<byte> body) instead. Will be replaced in version 7.0", false)]
4648
void Add(string exchange, string routingKey, bool mandatory, IBasicProperties properties, byte[] body);
4749
void Publish();
4850
}

projects/RabbitMQ.Client/client/impl/BasicPublishBatch.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41+
using System;
4142
using System.Collections.Generic;
4243

4344
using RabbitMQ.Client.Framing.Impl;
@@ -62,6 +63,12 @@ internal BasicPublishBatch (ModelBase model, int sizeHint)
6263
}
6364

6465
public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body)
66+
{
67+
ReadOnlyMemory<byte> bodyAsMemory = body;
68+
Add(exchange, routingKey, mandatory, basicProperties, bodyAsMemory);
69+
}
70+
71+
public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory<byte> body)
6572
{
6673
var method = new BasicPublish
6774
{
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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-2020 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+
// https://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 https://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 Pivotal Software, Inc.
38+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using System;
42+
using RabbitMQ.Client.Impl;
43+
44+
namespace RabbitMQ.Client
45+
{
46+
public static class BasicPublishBatchExtensions
47+
{
48+
public static void Add(this IBasicPublishBatch batch, string exchange, string routingKey, bool mandatory, IBasicProperties properties, ReadOnlyMemory<byte> body)
49+
{
50+
if (batch is BasicPublishBatch batchInternal)
51+
{
52+
batchInternal.Add(exchange, routingKey, mandatory, properties, body);
53+
return;
54+
}
55+
56+
#pragma warning disable 618
57+
batch.Add(exchange, routingKey, mandatory, properties, body.ToArray());
58+
#pragma warning restore 618
59+
}
60+
}
61+
}

projects/Unit/APIApproval.Approve.verified.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ namespace RabbitMQ.Client
5656
public bool Redelivered { get; }
5757
public string RoutingKey { get; }
5858
}
59+
public static class BasicPublishBatchExtensions
60+
{
61+
public static void Add(this RabbitMQ.Client.IBasicPublishBatch batch, string exchange, string routingKey, bool mandatory, RabbitMQ.Client.IBasicProperties properties, System.ReadOnlyMemory<byte> body) { }
62+
}
5963
public class BinaryTableValue
6064
{
6165
public BinaryTableValue() { }
@@ -291,6 +295,8 @@ namespace RabbitMQ.Client
291295
}
292296
public interface IBasicPublishBatch
293297
{
298+
[System.Obsolete("Use Add(string exchange, string routingKey, bool mandatory, IBasicProperties prop" +
299+
"erties, ReadOnlyMemory<byte> body) instead. Will be replaced in version 7.0", false)]
294300
void Add(string exchange, string routingKey, bool mandatory, RabbitMQ.Client.IBasicProperties properties, byte[] body);
295301
void Publish();
296302
}

projects/Unit/TestBasicPublishBatch.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public void TestBasicPublishBatchSend()
5353
Model.QueueDeclare(queue: "test-message-batch-a", durable: false);
5454
Model.QueueDeclare(queue: "test-message-batch-b", durable: false);
5555
IBasicPublishBatch batch = Model.CreateBasicPublishBatch();
56-
batch.Add("", "test-message-batch-a", false, null, new byte [] {});
57-
batch.Add("", "test-message-batch-b", false, null, new byte [] {});
56+
batch.Add("", "test-message-batch-a", false, null, new ReadOnlyMemory<byte>());
57+
batch.Add("", "test-message-batch-b", false, null, new ReadOnlyMemory<byte>());
5858
batch.Publish();
5959
Model.WaitForConfirmsOrDie(TimeSpan.FromSeconds(15));
6060
BasicGetResult resultA = Model.BasicGet("test-message-batch-a", true);
@@ -70,8 +70,9 @@ public void TestBasicPublishBatchSendWithSizeHint()
7070
Model.QueueDeclare(queue: "test-message-batch-a", durable: false);
7171
Model.QueueDeclare(queue: "test-message-batch-b", durable: false);
7272
IBasicPublishBatch batch = Model.CreateBasicPublishBatch(2);
73-
batch.Add("", "test-message-batch-a", false, null, new byte [] {});
74-
batch.Add("", "test-message-batch-b", false, null, new byte [] {});
73+
ReadOnlyMemory<byte> bodyAsMemory = new byte [] {};
74+
batch.Add("", "test-message-batch-a", false, null, bodyAsMemory);
75+
batch.Add("", "test-message-batch-b", false, null, bodyAsMemory);
7576
batch.Publish();
7677
Model.WaitForConfirmsOrDie(TimeSpan.FromSeconds(15));
7778
BasicGetResult resultA = Model.BasicGet("test-message-batch-a", true);
@@ -87,8 +88,9 @@ public void TestBasicPublishBatchSendWithWrongSizeHint()
8788
Model.QueueDeclare(queue: "test-message-batch-a", durable: false);
8889
Model.QueueDeclare(queue: "test-message-batch-b", durable: false);
8990
IBasicPublishBatch batch = Model.CreateBasicPublishBatch(1);
90-
batch.Add("", "test-message-batch-a", false, null, new byte [] {});
91-
batch.Add("", "test-message-batch-b", false, null, new byte [] {});
91+
ReadOnlyMemory<byte> bodyAsMemory = new byte [] {};
92+
batch.Add("", "test-message-batch-a", false, null, bodyAsMemory);
93+
batch.Add("", "test-message-batch-b", false, null, bodyAsMemory);
9294
batch.Publish();
9395
Model.WaitForConfirmsOrDie(TimeSpan.FromSeconds(15));
9496
BasicGetResult resultA = Model.BasicGet("test-message-batch-a", true);

0 commit comments

Comments
 (0)