From 389e51d3fe45045e07d96f48891e1ceac24c6614 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 13 Jul 2023 16:29:15 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.BackgroundJobsRabbitMQ --- .../Volo.Abp.BackgroundJobs.RabbitMQ.csproj | 2 ++ .../Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs | 2 +- .../Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs | 16 ++++++++-------- .../RabbitMQ/JobQueueConfiguration.cs | 4 ++-- .../RabbitMQ/RabbitMqBackgroundJobManager.cs | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj index 40f87898ba..c4675f6039 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.BackgroundJobs.RabbitMQ Volo.Abp.BackgroundJobs.RabbitMQ $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs index b244707f04..b285f598cc 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ; public interface IJobQueue : IRunnable, IDisposable { - Task EnqueueAsync( + Task EnqueueAsync( TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs index 9c3bf26e62..621f181beb 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs @@ -21,8 +21,8 @@ public class JobQueue : IJobQueue protected BackgroundJobConfiguration JobConfiguration { get; } protected JobQueueConfiguration QueueConfiguration { get; } - protected IChannelAccessor ChannelAccessor { get; private set; } - protected AsyncEventingBasicConsumer Consumer { get; private set; } + protected IChannelAccessor? ChannelAccessor { get; private set; } + protected AsyncEventingBasicConsumer? Consumer { get; private set; } public ILogger> Logger { get; set; } @@ -71,7 +71,7 @@ public class JobQueue : IJobQueue ); } - public virtual async Task EnqueueAsync( + public virtual async Task EnqueueAsync( TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) @@ -176,7 +176,7 @@ public class JobQueue : IJobQueue basicProperties.Expiration = delay.Value.TotalMilliseconds.ToString(); } - ChannelAccessor.Channel.BasicPublish( + ChannelAccessor!.Channel.BasicPublish( exchange: "", routingKey: routingKey, basicProperties: basicProperties, @@ -188,7 +188,7 @@ public class JobQueue : IJobQueue protected virtual IBasicProperties CreateBasicPropertiesToPublish() { - var properties = ChannelAccessor.Channel.CreateBasicProperties(); + var properties = ChannelAccessor!.Channel.CreateBasicProperties(); properties.Persistent = true; return properties; } @@ -206,17 +206,17 @@ public class JobQueue : IJobQueue try { await JobExecuter.ExecuteAsync(context); - ChannelAccessor.Channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); + ChannelAccessor!.Channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); } catch (BackgroundJobExecutionException) { //TODO: Reject like that? - ChannelAccessor.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: true); + ChannelAccessor!.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: true); } catch (Exception) { //TODO: Reject like that? - ChannelAccessor.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: false); + ChannelAccessor!.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: false); } } } diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs index ee706ab864..9425cd0604 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs @@ -9,7 +9,7 @@ public class JobQueueConfiguration : QueueDeclareConfiguration { public Type JobArgsType { get; } - public string ConnectionName { get; set; } + public string? ConnectionName { get; set; } public string DelayedQueueName { get; set; } @@ -17,7 +17,7 @@ public class JobQueueConfiguration : QueueDeclareConfiguration Type jobArgsType, string queueName, string delayedQueueName, - string connectionName = null, + string? connectionName = null, bool durable = true, bool exclusive = false, bool autoDelete = false, diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs index ae550077e0..d81b2758b0 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs @@ -20,6 +20,6 @@ public class RabbitMqBackgroundJobManager : IBackgroundJobManager, ITransientDep TimeSpan? delay = null) { var jobQueue = await _jobQueueManager.GetAsync(); - return await jobQueue.EnqueueAsync(args, priority, delay); + return (await jobQueue.EnqueueAsync(args, priority, delay))!; } }