Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit a95ad9b

Browse files
author
Keith Hill
committed
Fixing breaking changes in RabbitMQ.Client 6.0.0; Bumping version to match RabbitMQ.Client (more clear);
1 parent 3e12b06 commit a95ad9b

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

src/RabbitMQ.Client.Core.DependencyInjection/Configuration/RabbitMqClientOptions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace RabbitMQ.Client.Core.DependencyInjection.Configuration
45
{
@@ -76,11 +77,11 @@ public class RabbitMqClientOptions
7677
/// <summary>
7778
/// Timeout for connection attempts.
7879
/// </summary>
79-
public int RequestedConnectionTimeout { get; set; } = 60000;
80+
public TimeSpan RequestedConnectionTimeout { get; set; } = TimeSpan.FromMilliseconds(60000);
8081

8182
/// <summary>
8283
/// Heartbeat timeout.
8384
/// </summary>
84-
public ushort RequestedHeartbeat { get; set; } = 60;
85+
public TimeSpan RequestedHeartbeat { get; set; } = TimeSpan.FromSeconds(60);
8586
}
8687
}

src/RabbitMQ.Client.Core.DependencyInjection/IProducingService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23

34
namespace RabbitMQ.Client.Core.DependencyInjection
45
{
@@ -77,7 +78,7 @@ public interface IProducingService
7778
/// <param name="properties">Message properties.</param>
7879
/// <param name="exchangeName">Exchange name.</param>
7980
/// <param name="routingKey">Routing key.</param>
80-
void Send(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey);
81+
void Send(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey);
8182

8283
/// <summary>
8384
/// Send a delayed message.
@@ -87,7 +88,7 @@ public interface IProducingService
8788
/// <param name="exchangeName">Exchange name.</param>
8889
/// <param name="routingKey">Routing key.</param>
8990
/// <param name="secondsDelay">Delay time.</param>
90-
void Send(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay);
91+
void Send(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay);
9192

9293
/// <summary>
9394
/// Send a message asynchronously.
@@ -149,7 +150,7 @@ public interface IProducingService
149150
/// <param name="properties">Message properties.</param>
150151
/// <param name="exchangeName">Exchange name.</param>
151152
/// <param name="routingKey">Routing key.</param>
152-
Task SendAsync(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey);
153+
Task SendAsync(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey);
153154

154155
/// <summary>
155156
/// Send a delayed message asynchronously.
@@ -159,6 +160,6 @@ public interface IProducingService
159160
/// <param name="exchangeName">Exchange name.</param>
160161
/// <param name="routingKey">Routing key.</param>
161162
/// <param name="secondsDelay">Delay time.</param>
162-
Task SendAsync(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay);
163+
Task SendAsync(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay);
163164
}
164165
}

src/RabbitMQ.Client.Core.DependencyInjection/MessageHandlingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public MessageHandlingService(
3838
/// <param name="queueService">An instance of the queue service <see cref="IQueueService"/>.</param>
3939
public async Task HandleMessageReceivingEvent(BasicDeliverEventArgs eventArgs, IQueueService queueService)
4040
{
41-
var message = Encoding.UTF8.GetString(eventArgs.Body);
41+
var message = Encoding.UTF8.GetString(eventArgs.Body.ToArray());
4242

4343
_logger.LogInformation($"A new message was received with deliveryTag {eventArgs.DeliveryTag}.");
4444
_logger.LogInformation(message);

src/RabbitMQ.Client.Core.DependencyInjection/QueueService.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace RabbitMQ.Client.Core.DependencyInjection
2020
internal sealed class QueueService : IQueueService, IDisposable
2121
{
2222
public IConnection Connection { get; private set; }
23-
2423
public IModel Channel { get; private set; }
2524

2625
public IConnection ConsumingConnection { get; private set; }
@@ -64,13 +63,19 @@ public void Dispose()
6463
if (Connection != null)
6564
{
6665
Connection.CallbackException -= HandleConnectionCallbackException;
67-
Connection.ConnectionRecoveryError -= HandleConnectionRecoveryError;
66+
if (Connection is IAutorecoveringConnection connection)
67+
{
68+
connection.ConnectionRecoveryError -= HandleConnectionRecoveryError;
69+
}
6870
}
6971

7072
if (ConsumingConnection != null)
7173
{
7274
ConsumingConnection.CallbackException -= HandleConnectionCallbackException;
73-
ConsumingConnection.ConnectionRecoveryError -= HandleConnectionRecoveryError;
75+
if (Connection is IAutorecoveringConnection connection)
76+
{
77+
connection.ConnectionRecoveryError -= HandleConnectionRecoveryError;
78+
}
7479
}
7580

7681
if (Channel != null)
@@ -190,7 +195,7 @@ public void SendString(string message, string exchangeName, string routingKey, i
190195
SendString(message, deadLetterExchange, delayedQueueName);
191196
}
192197

193-
public void Send(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey)
198+
public void Send(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey)
194199
{
195200
EnsureProducingChannelIsNotNull();
196201
ValidateArguments(exchangeName, routingKey);
@@ -203,7 +208,7 @@ public void Send(byte[] bytes, IBasicProperties properties, string exchangeName,
203208
}
204209
}
205210

206-
public void Send(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay)
211+
public void Send(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay)
207212
{
208213
EnsureProducingChannelIsNotNull();
209214
ValidateArguments(exchangeName, routingKey);
@@ -230,10 +235,10 @@ public async Task SendStringAsync(string message, string exchangeName, string ro
230235
public async Task SendStringAsync(string message, string exchangeName, string routingKey, int secondsDelay) =>
231236
await Task.Run(() => SendString(message, exchangeName, routingKey, secondsDelay)).ConfigureAwait(false);
232237

233-
public async Task SendAsync(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey) =>
238+
public async Task SendAsync(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey) =>
234239
await Task.Run(() => Send(bytes, properties, exchangeName, routingKey)).ConfigureAwait(false);
235240

236-
public async Task SendAsync(byte[] bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay) =>
241+
public async Task SendAsync(ReadOnlyMemory<byte> bytes, IBasicProperties properties, string exchangeName, string routingKey, int secondsDelay) =>
237242
await Task.Run(() => Send(bytes, properties, exchangeName, routingKey, secondsDelay)).ConfigureAwait(false);
238243

239244
IBasicProperties CreateProperties()
@@ -299,7 +304,10 @@ void ConfigureConnectionInfrastructure(RabbitMqConnectionOptionsContainer option
299304
if (Connection != null)
300305
{
301306
Connection.CallbackException += HandleConnectionCallbackException;
302-
Connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
307+
if (Connection is IAutorecoveringConnection connection)
308+
{
309+
connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
310+
}
303311
Channel = Connection.CreateModel();
304312
Channel.CallbackException += HandleChannelCallbackException;
305313
Channel.BasicRecoverOk += HandleChannelBasicRecoverOk;
@@ -309,7 +317,10 @@ void ConfigureConnectionInfrastructure(RabbitMqConnectionOptionsContainer option
309317
if (ConsumingConnection != null)
310318
{
311319
ConsumingConnection.CallbackException += HandleConnectionCallbackException;
312-
ConsumingConnection.ConnectionRecoveryError += HandleConnectionRecoveryError;
320+
if (Connection is IAutorecoveringConnection connection)
321+
{
322+
connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
323+
}
313324
ConsumingChannel = ConsumingConnection.CreateModel();
314325
ConsumingChannel.CallbackException += HandleChannelCallbackException;
315326
ConsumingChannel.BasicRecoverOk += HandleChannelBasicRecoverOk;

src/RabbitMQ.Client.Core.DependencyInjection/RabbitMQ.Client.Core.DependencyInjection.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>latest</LangVersion>
6-
<Version>3.2.1</Version>
6+
<Version>6.0.0</Version>
77
<PackageTags>RabbitMQ</PackageTags>
88
<RepositoryUrl>https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection</RepositoryUrl>
99
<Company />
@@ -23,7 +23,7 @@
2323
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
2424
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.3" />
2525
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
26-
<PackageReference Include="RabbitMQ.Client" Version="5.1.2" />
26+
<PackageReference Include="RabbitMQ.Client" Version="6.0.0" />
2727
</ItemGroup>
2828

2929
</Project>

0 commit comments

Comments
 (0)