Skip to content

Commit 7c0fc07

Browse files
Merge branch 'bollhals-feature/basicProperties'
2 parents 5f1c4c8 + 166827a commit 7c0fc07

File tree

104 files changed

+1119
-1584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1119
-1584
lines changed

projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AsyncBasicConsumerFake(ManualResetEventSlim autoResetEvent)
1818
_autoResetEvent = autoResetEvent;
1919
}
2020

21-
public Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory<byte> body)
21+
public Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
2222
{
2323
if (Interlocked.Increment(ref _current) == Count)
2424
{
@@ -29,7 +29,7 @@ public Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redel
2929
}
3030

3131
void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
32-
IBasicProperties properties, ReadOnlyMemory<byte> body)
32+
in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
3333
{
3434
if (Interlocked.Increment(ref _current) == Count)
3535
{

projects/Benchmarks/ConsumerDispatching/ConsumerDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ConsumerDispatcherBase
1717
protected readonly ulong _deliveryTag = 500UL;
1818
protected readonly string _exchange = "Exchange";
1919
protected readonly string _routingKey = "RoutingKey";
20-
protected readonly IBasicProperties _properties = new Client.Framing.BasicProperties();
20+
protected readonly ReadOnlyBasicProperties _properties = new ReadOnlyBasicProperties();
2121
protected readonly byte[] _body = new byte[512];
2222
}
2323

projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ namespace Benchmarks.Networking
99
[MemoryDiagnoser]
1010
public class Networking_BasicDeliver_Commons
1111
{
12-
private const int messageCount = 10000;
13-
14-
15-
public static async Task Publish_Hello_World(IConnection connection, uint n, byte[] body)
12+
public static async Task Publish_Hello_World(IConnection connection, uint messageCount, byte[] body)
1613
{
1714
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
1815
using (var model = connection.CreateModel())
@@ -31,7 +28,7 @@ public static async Task Publish_Hello_World(IConnection connection, uint n, byt
3128

3229
for (int i = 0; i < messageCount; i++)
3330
{
34-
model.BasicPublish("", queue.QueueName, null, body);
31+
model.BasicPublish("", queue.QueueName, body);
3532
}
3633

3734
await tcs.Task;

projects/Benchmarks/Networking/Networking_BasicDeliver_LongLivedConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public void GlobalCleanup()
3232
}
3333

3434
[Benchmark(Baseline = true)]
35-
public async Task Publish_Hello_World()
35+
public Task Publish_Hello_World()
3636
{
37-
await Networking_BasicDeliver_Commons.Publish_Hello_World(_connection, messageCount, _body);
37+
return Networking_BasicDeliver_Commons.Publish_Hello_World(_connection, messageCount, _body);
3838
}
3939
}
4040
}

projects/Benchmarks/WireFormatting/MethodFraming.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
using System.Text;
33

44
using BenchmarkDotNet.Attributes;
5-
5+
using RabbitMQ.Client;
6+
using RabbitMQ.Client.client.impl;
67
using RabbitMQ.Client.Framing.Impl;
78
using RabbitMQ.Client.Impl;
89

9-
using BasicProperties = RabbitMQ.Client.Framing.BasicProperties;
10-
1110
namespace RabbitMQ.Benchmarks
1211
{
1312
[Config(typeof(Config))]
@@ -30,8 +29,8 @@ public class MethodFramingBasicPublish
3029
private const string StringValue = "Exchange_OR_RoutingKey";
3130
private BasicPublish _basicPublish = new BasicPublish(StringValue, StringValue, false, false);
3231
private BasicPublishMemory _basicPublishMemory = new BasicPublishMemory(Encoding.UTF8.GetBytes(StringValue), Encoding.UTF8.GetBytes(StringValue), false, false);
33-
private readonly BasicProperties _propertiesEmpty = new BasicProperties();
34-
private readonly BasicProperties _properties = new BasicProperties { AppId = "Application id", MessageId = "Random message id" };
32+
private EmptyBasicProperty _propertiesEmpty = new EmptyBasicProperty();
33+
private BasicProperties _properties = new BasicProperties { AppId = "Application id", MessageId = "Random message id" };
3534
private readonly ReadOnlyMemory<byte> _bodyEmpty = ReadOnlyMemory<byte>.Empty;
3635
private readonly ReadOnlyMemory<byte> _body = new byte[512];
3736

@@ -42,13 +41,13 @@ public class MethodFramingBasicPublish
4241
public int FrameMax { get; set; }
4342

4443
[Benchmark]
45-
public ReadOnlyMemory<byte> BasicPublishWriteNonEmpty() => Framing.SerializeToFrames(ref _basicPublish, _properties, _body, Channel, FrameMax);
44+
public ReadOnlyMemory<byte> BasicPublishWriteNonEmpty() => Framing.SerializeToFrames(ref _basicPublish, ref _properties, _body, Channel, FrameMax);
4645

4746
[Benchmark]
48-
public ReadOnlyMemory<byte> BasicPublishWrite() => Framing.SerializeToFrames(ref _basicPublish, _propertiesEmpty, _bodyEmpty, Channel, FrameMax);
47+
public ReadOnlyMemory<byte> BasicPublishWrite() => Framing.SerializeToFrames(ref _basicPublish, ref _propertiesEmpty, _bodyEmpty, Channel, FrameMax);
4948

5049
[Benchmark]
51-
public ReadOnlyMemory<byte> BasicPublishMemoryWrite() => Framing.SerializeToFrames(ref _basicPublishMemory, _propertiesEmpty, _bodyEmpty, Channel, FrameMax);
50+
public ReadOnlyMemory<byte> BasicPublishMemoryWrite() => Framing.SerializeToFrames(ref _basicPublishMemory, ref _propertiesEmpty, _bodyEmpty, Channel, FrameMax);
5251
}
5352

5453
[Config(typeof(Config))]

projects/Benchmarks/WireFormatting/MethodSerialization.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
using System.Text;
33

44
using BenchmarkDotNet.Attributes;
5-
6-
using RabbitMQ.Client.Framing;
5+
using RabbitMQ.Client;
76
using RabbitMQ.Client.Framing.Impl;
87

98
namespace RabbitMQ.Benchmarks
@@ -21,13 +20,13 @@ public virtual void SetUp() { }
2120
public class MethodBasicAck : MethodSerializationBase
2221
{
2322
private readonly BasicAck _basicAck = new BasicAck(ulong.MaxValue, true);
24-
public override void SetUp() => _basicAck.WriteArgumentsTo(_buffer.Span);
23+
public override void SetUp() => _basicAck.WriteTo(_buffer.Span);
2524

2625
[Benchmark]
2726
public ulong BasicAckRead() => new BasicAck(_buffer.Span)._deliveryTag; // return one property to not box when returning an object instead
2827

2928
[Benchmark]
30-
public int BasicAckWrite() => _basicAck.WriteArgumentsTo(_buffer.Span);
29+
public int BasicAckWrite() => _basicAck.WriteTo(_buffer.Span);
3130
}
3231

3332
public class MethodBasicDeliver : MethodSerializationBase
@@ -38,7 +37,6 @@ public class MethodBasicDeliver : MethodSerializationBase
3837

3938
public override void SetUp()
4039
{
41-
int length = _buffer.Length;
4240
int offset = Client.Impl.WireFormatting.WriteShortstr(ref _buffer.Span.GetStart(), string.Empty);
4341
offset += Client.Impl.WireFormatting.WriteLonglong(ref _buffer.Span.GetOffset(offset), 0);
4442
offset += Client.Impl.WireFormatting.WriteBits(ref _buffer.Span.GetOffset(offset), false);
@@ -50,10 +48,10 @@ public override void SetUp()
5048
public object BasicDeliverRead() => new BasicDeliver(_buffer.Span)._consumerTag; // return one property to not box when returning an object instead
5149

5250
[Benchmark]
53-
public int BasicPublishWrite() => _basicPublish.WriteArgumentsTo(_buffer.Span);
51+
public int BasicPublishWrite() => _basicPublish.WriteTo(_buffer.Span);
5452

5553
[Benchmark]
56-
public int BasicPublishMemoryWrite() => _basicPublishMemory.WriteArgumentsTo(_buffer.Span);
54+
public int BasicPublishMemoryWrite() => _basicPublishMemory.WriteTo(_buffer.Span);
5755

5856
[Benchmark]
5957
public int BasicPublishSize() => _basicPublish.GetRequiredBufferSize();
@@ -66,27 +64,27 @@ public class MethodChannelClose : MethodSerializationBase
6664
{
6765
private readonly ChannelClose _channelClose = new ChannelClose(333, string.Empty, 0099, 2999);
6866

69-
public override void SetUp() => _channelClose.WriteArgumentsTo(_buffer.Span);
67+
public override void SetUp() => _channelClose.WriteTo(_buffer.Span);
7068

7169
[Benchmark]
7270
public object ChannelCloseRead() => new ChannelClose(_buffer.Span)._replyText; // return one property to not box when returning an object instead
7371

7472
[Benchmark]
75-
public int ChannelCloseWrite() => _channelClose.WriteArgumentsTo(_buffer.Span);
73+
public int ChannelCloseWrite() => _channelClose.WriteTo(_buffer.Span);
7674
}
7775

7876
public class MethodBasicProperties : MethodSerializationBase
7977
{
80-
private readonly BasicProperties _basicProperties = new BasicProperties { Persistent = true, AppId = "AppId", ContentEncoding = "content", };
81-
public override void SetUp() => _basicProperties.WritePropertiesTo(_buffer.Span);
78+
private readonly IAmqpWriteable _basicProperties = new BasicProperties { Persistent = true, AppId = "AppId", ContentEncoding = "content", };
79+
public override void SetUp() => _basicProperties.WriteTo(_buffer.Span);
8280

8381
[Benchmark]
84-
public object BasicPropertiesRead() => new BasicProperties(_buffer.Span);
82+
public ReadOnlyBasicProperties BasicPropertiesRead() => new ReadOnlyBasicProperties(_buffer.Span);
8583

8684
[Benchmark]
87-
public int BasicPropertiesWrite() => _basicProperties.WritePropertiesTo(_buffer.Span);
85+
public int BasicPropertiesWrite() => _basicProperties.WriteTo(_buffer.Span);
8886

8987
[Benchmark]
90-
public int BasicDeliverSize() => _basicProperties.GetRequiredPayloadBufferSize();
88+
public int BasicDeliverSize() => _basicProperties.GetRequiredBufferSize();
9189
}
9290
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public virtual Task HandleBasicDeliver(string consumerTag,
112112
bool redelivered,
113113
string exchange,
114114
string routingKey,
115-
IBasicProperties properties,
115+
in ReadOnlyBasicProperties properties,
116116
ReadOnlyMemory<byte> body)
117117
{
118118
// Nothing to do here.
@@ -165,7 +165,7 @@ void IBasicConsumer.HandleBasicConsumeOk(string consumerTag)
165165
throw new InvalidOperationException("Should never be called.");
166166
}
167167

168-
void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory<byte> body)
168+
void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in ReadOnlyBasicProperties properties, ReadOnlyMemory<byte> body)
169169
{
170170
throw new InvalidOperationException("Should never be called.");
171171
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public sealed class BasicGetResult : IDisposable
5353
/// <param name="basicProperties">The Basic-class content header properties for the message.</param>
5454
/// <param name="body">The body</param>
5555
public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, string routingKey,
56-
uint messageCount, IBasicProperties basicProperties, ReadOnlyMemory<byte> body)
56+
uint messageCount, in ReadOnlyBasicProperties basicProperties, ReadOnlyMemory<byte> body)
5757
{
5858
DeliveryTag = deliveryTag;
5959
Redelivered = redelivered;
@@ -76,7 +76,7 @@ public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, stri
7676
/// <param name="body">The body</param>
7777
/// <param name="rentedArray">The rented array which body is part of.</param>
7878
public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, string routingKey,
79-
uint messageCount, IBasicProperties basicProperties, ReadOnlyMemory<byte> body, byte[] rentedArray)
79+
uint messageCount, in ReadOnlyBasicProperties basicProperties, ReadOnlyMemory<byte> body, byte[] rentedArray)
8080
{
8181
DeliveryTag = deliveryTag;
8282
Redelivered = redelivered;
@@ -91,7 +91,7 @@ public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, stri
9191
/// <summary>
9292
/// Retrieves the Basic-class content header properties for this message.
9393
/// </summary>
94-
public IBasicProperties BasicProperties { get; }
94+
public ReadOnlyBasicProperties BasicProperties { get; }
9595

9696
/// <summary>
9797
/// Retrieves the body of this message.
@@ -130,7 +130,7 @@ public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, stri
130130
/// <inheritdoc />
131131
public void Dispose()
132132
{
133-
if (!(_rentedArray is null))
133+
if (_rentedArray is not null)
134134
{
135135
ArrayPool<byte>.Shared.Return(_rentedArray);
136136
}

0 commit comments

Comments
 (0)