Ver a proveniência

Enable #nullable for NATS transport.

master
Savorboard há 2 anos
ascendente
cometimento
3cf141f6aa
4 ficheiros alterados com 15 adições e 20 eliminações
  1. +2
    -2
      src/DotNetCore.CAP.NATS/CAP.NATSOptions.cs
  2. +1
    -2
      src/DotNetCore.CAP.NATS/CAP.Options.Extensions.cs
  3. +1
    -7
      src/DotNetCore.CAP.NATS/DotNetCore.CAP.NATS.csproj
  4. +11
    -9
      src/DotNetCore.CAP.NATS/NATSConsumerClient.cs

+ 2
- 2
src/DotNetCore.CAP.NATS/CAP.NATSOptions.cs Ver ficheiro

@@ -27,9 +27,9 @@ namespace DotNetCore.CAP
/// <summary>
/// Used to setup all NATs client options
/// </summary>
public Options Options { get; set; }
public Options? Options { get; set; }

public Action<StreamConfiguration.StreamConfigurationBuilder> StreamOptions { get; set; }
public Action<StreamConfiguration.StreamConfigurationBuilder>? StreamOptions { get; set; }

public Func<string, string> NormalizeStreamName { get; set; } = origin => origin.Split('.')[0];
}

+ 1
- 2
src/DotNetCore.CAP.NATS/CAP.Options.Extensions.cs Ver ficheiro

@@ -3,7 +3,6 @@

using System;
using DotNetCore.CAP;
using JetBrains.Annotations;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
@@ -15,7 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
/// <param name="options">CAP configuration options</param>
/// <param name="bootstrapServers">NATS bootstrap server urls.</param>
public static CapOptions UseNATS(this CapOptions options, [CanBeNull] string bootstrapServers = null)
public static CapOptions UseNATS(this CapOptions options, string? bootstrapServers = null)
{
return options.UseNATS(opt =>
{


+ 1
- 7
src/DotNetCore.CAP.NATS/DotNetCore.CAP.NATS.csproj Ver ficheiro

@@ -2,16 +2,10 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>DotNetCore.CAP.NATS</AssemblyName>
<Nullable>enable</Nullable>
<PackageTags>$(PackageTags);NATS</PackageTags>
</PropertyGroup>

<PropertyGroup>
<WarningsAsErrors>NU1605;NU1701</WarningsAsErrors>
<NoWarn>NU1701;CS1591</NoWarn>
<DocumentationFile>bin\$(Configuration)\netstandard2.1\DotNetCore.CAP.NATS.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NATS.Client" Version="0.14.1" />
</ItemGroup>


+ 11
- 9
src/DotNetCore.CAP.NATS/NATSConsumerClient.cs Ver ficheiro

@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.NATS
private readonly string _groupId;
private readonly NATSOptions _natsOptions;

private IConnection _consumerClient;
private IConnection? _consumerClient;

public NATSConsumerClient(string groupId, IOptions<NATSOptions> options)
{
@@ -29,15 +29,17 @@ namespace DotNetCore.CAP.NATS
_natsOptions = options.Value ?? throw new ArgumentNullException(nameof(options));
}

public event EventHandler<TransportMessage> OnMessageReceived;
public event EventHandler<TransportMessage>? OnMessageReceived;

public event EventHandler<LogMessageEventArgs> OnLog;
public event EventHandler<LogMessageEventArgs>? OnLog;

public BrokerAddress BrokerAddress => new BrokerAddress("NATS", _natsOptions.Servers);
public BrokerAddress BrokerAddress => new ("NATS", _natsOptions.Servers);

public ICollection<string> FetchTopics(IEnumerable<string> topicNames)
{
var jsm = _consumerClient.CreateJetStreamManagementContext();
Connect();

var jsm = _consumerClient!.CreateJetStreamManagementContext();

var streamGroup = topicNames.GroupBy(x => _natsOptions.NormalizeStreamName(x));

@@ -80,7 +82,7 @@ namespace DotNetCore.CAP.NATS

Connect();

var js = _consumerClient.CreateJetStreamContext();
var js = _consumerClient!.CreateJetStreamContext();

foreach (var subject in topics)
{
@@ -106,7 +108,7 @@ namespace DotNetCore.CAP.NATS

private void Subscription_MessageHandler(object sender, MsgHandlerEventArgs e)
{
var headers = new Dictionary<string, string>();
var headers = new Dictionary<string, string?>();

foreach (string h in e.Message.Header.Keys)
{
@@ -126,7 +128,7 @@ namespace DotNetCore.CAP.NATS
}
}

public void Reject(object sender)
public void Reject(object? sender)
{
if (sender is Msg msg)
{
@@ -153,7 +155,7 @@ namespace DotNetCore.CAP.NATS
if (_consumerClient == null)
{
var opts = _natsOptions.Options ?? ConnectionFactory.GetDefaultOptions();
opts.Url = _natsOptions.Servers ?? opts.Url;
opts.Url ??= _natsOptions.Servers;
opts.ClosedEventHandler = ConnectedEventHandler;
opts.DisconnectedEventHandler = ConnectedEventHandler;
opts.AsyncErrorEventHandler = AsyncErrorEventHandler;


Carregando…
Cancelar
Guardar