Browse Source

Enable nullable annotations for Volo.Abp.RabbitMQ

pull/17109/head
liangshiwei 3 years ago
parent
commit
182607b710
  1. 2
      framework/src/Volo.Abp.RabbitMQ/Volo.Abp.RabbitMQ.csproj
  2. 4
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ChannelPool.cs
  3. 2
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs
  4. 2
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IChannelPool.cs
  5. 2
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IConnectionPool.cs
  6. 2
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IRabbitMqMessageConsumerFactory.cs
  7. 16
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs
  8. 2
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumerFactory.cs

2
framework/src/Volo.Abp.RabbitMQ/Volo.Abp.RabbitMQ.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.RabbitMQ</AssemblyName>
<PackageId>Volo.Abp.RabbitMQ</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

4
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ChannelPool.cs

@ -29,7 +29,7 @@ public class ChannelPool : IChannelPool, ISingletonDependency
Logger = NullLogger<ChannelPool>.Instance;
}
public virtual IChannelAccessor Acquire(string channelName = null, string connectionName = null)
public virtual IChannelAccessor Acquire(string? channelName = null, string? connectionName = null)
{
CheckDisposed();
@ -49,7 +49,7 @@ public class ChannelPool : IChannelPool, ISingletonDependency
);
}
protected virtual IModel CreateChannel(string channelName, string connectionName)
protected virtual IModel CreateChannel(string channelName, string? connectionName)
{
return ConnectionPool
.Get(connectionName)

2
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs

@ -21,7 +21,7 @@ public class ConnectionPool : IConnectionPool, ISingletonDependency
Connections = new ConcurrentDictionary<string, Lazy<IConnection>>();
}
public virtual IConnection Get(string connectionName = null)
public virtual IConnection Get(string? connectionName = null)
{
connectionName ??= RabbitMqConnections.DefaultConnectionName;

2
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IChannelPool.cs

@ -4,5 +4,5 @@ namespace Volo.Abp.RabbitMQ;
public interface IChannelPool : IDisposable
{
IChannelAccessor Acquire(string channelName = null, string connectionName = null);
IChannelAccessor Acquire(string? channelName = null, string? connectionName = null);
}

2
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IConnectionPool.cs

@ -5,5 +5,5 @@ namespace Volo.Abp.RabbitMQ;
public interface IConnectionPool : IDisposable
{
IConnection Get(string connectionName = null);
IConnection Get(string? connectionName = null);
}

2
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/IRabbitMqMessageConsumerFactory.cs

@ -14,6 +14,6 @@ public interface IRabbitMqMessageConsumerFactory
IRabbitMqMessageConsumer Create(
ExchangeDeclareConfiguration exchange,
QueueDeclareConfiguration queue,
string connectionName = null
string? connectionName = null
);
}

16
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs

@ -23,15 +23,15 @@ public class RabbitMqMessageConsumer : IRabbitMqMessageConsumer, ITransientDepen
protected AbpAsyncTimer Timer { get; }
protected ExchangeDeclareConfiguration Exchange { get; private set; }
protected ExchangeDeclareConfiguration Exchange { get; private set; } = default!;
protected QueueDeclareConfiguration Queue { get; private set; }
protected QueueDeclareConfiguration Queue { get; private set; } = default!;
protected string ConnectionName { get; private set; }
protected string? ConnectionName { get; private set; }
protected ConcurrentBag<Func<IModel, BasicDeliverEventArgs, Task>> Callbacks { get; }
protected IModel Channel { get; private set; }
protected IModel? Channel { get; private set; }
protected ConcurrentQueue<QueueBindCommand> QueueBindCommands { get; }
@ -58,7 +58,7 @@ public class RabbitMqMessageConsumer : IRabbitMqMessageConsumer, ITransientDepen
public void Initialize(
[NotNull] ExchangeDeclareConfiguration exchange,
[NotNull] QueueDeclareConfiguration queue,
string connectionName = null)
string? connectionName = null)
{
Exchange = Check.NotNull(exchange, nameof(exchange));
Queue = Check.NotNull(queue, nameof(queue));
@ -192,16 +192,16 @@ public class RabbitMqMessageConsumer : IRabbitMqMessageConsumer, ITransientDepen
{
foreach (var callback in Callbacks)
{
await callback(Channel, basicDeliverEventArgs);
await callback(Channel!, basicDeliverEventArgs);
}
Channel.BasicAck(basicDeliverEventArgs.DeliveryTag, multiple: false);
Channel?.BasicAck(basicDeliverEventArgs.DeliveryTag, multiple: false);
}
catch (Exception ex)
{
try
{
Channel.BasicNack(
Channel?.BasicNack(
basicDeliverEventArgs.DeliveryTag,
multiple: false,
requeue: true

2
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumerFactory.cs

@ -16,7 +16,7 @@ public class RabbitMqMessageConsumerFactory : IRabbitMqMessageConsumerFactory, I
public IRabbitMqMessageConsumer Create(
ExchangeDeclareConfiguration exchange,
QueueDeclareConfiguration queue,
string connectionName = null)
string? connectionName = null)
{
var consumer = ServiceScope.ServiceProvider.GetRequiredService<RabbitMqMessageConsumer>();
consumer.Initialize(exchange, queue, connectionName);

Loading…
Cancel
Save