Parcourir la source

Add EnableClientLog option for Apache Pulsar transport.

master
Savorboard il y a 3 ans
Parent
révision
9fc0176f54
5 fichiers modifiés avec 20 ajouts et 4 suppressions
  1. +2
    -0
      src/DotNetCore.CAP.Pulsar/CAP.PulsarOptions.cs
  2. +1
    -0
      src/DotNetCore.CAP.Pulsar/DotNetCore.CAP.Pulsar.csproj
  3. +2
    -0
      src/DotNetCore.CAP.Pulsar/IConnectionFactory.Default.cs
  4. +6
    -2
      src/DotNetCore.CAP.Pulsar/PulsarConsumerClient.cs
  5. +9
    -2
      src/DotNetCore.CAP.Pulsar/PulsarConsumerClientFactory.cs

+ 2
- 0
src/DotNetCore.CAP.Pulsar/CAP.PulsarOptions.cs Voir le fichier

@@ -13,6 +13,8 @@ namespace DotNetCore.CAP
{
public string ServiceUrl { get; set; } = default!;

public bool EnableClientLog { get; set; } = false;

public TlsOptions? TlsOptions { get; set; }
}
}


+ 1
- 0
src/DotNetCore.CAP.Pulsar/DotNetCore.CAP.Pulsar.csproj Voir le fichier

@@ -4,6 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<PackageTags>$(PackageTags);Pulsar</PackageTags>
<NoWarn>CS0067</NoWarn>
</PropertyGroup>

<ItemGroup>


+ 2
- 0
src/DotNetCore.CAP.Pulsar/IConnectionFactory.Default.cs Voir le fichier

@@ -13,12 +13,14 @@ namespace DotNetCore.CAP.Pulsar
{
public class ConnectionFactory : IConnectionFactory, IAsyncDisposable
{
private readonly ILogger<ConnectionFactory> _logger;
private PulsarClient? _client;
private readonly PulsarOptions _options;
private readonly ConcurrentDictionary<string, Task<IProducer<byte[]>>> _topicProducers;

public ConnectionFactory(ILogger<ConnectionFactory> logger, IOptions<PulsarOptions> options)
{
_logger = logger;
_options = options.Value;
_topicProducers = new ConcurrentDictionary<string, Task<IProducer<byte[]>>>();



+ 6
- 2
src/DotNetCore.CAP.Pulsar/PulsarConsumerClient.cs Voir le fichier

@@ -7,6 +7,8 @@ using System.Reflection;
using System.Threading;
using DotNetCore.CAP.Messages;
using DotNetCore.CAP.Transport;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Pulsar.Client.Api;
using Pulsar.Client.Common;
@@ -41,7 +43,7 @@ namespace DotNetCore.CAP.Pulsar
}

var serviceName = Assembly.GetEntryAssembly()?.GetName().Name.ToLower();
_consumerClient = _client.NewConsumer()
.Topics(topics)
.SubscriptionName(_groupId)
@@ -87,5 +89,7 @@ namespace DotNetCore.CAP.Pulsar
{
_consumerClient?.DisposeAsync();
}
}

}
}

+ 9
- 2
src/DotNetCore.CAP.Pulsar/PulsarConsumerClientFactory.cs Voir le fichier

@@ -2,7 +2,9 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using DotNetCore.CAP.Transport;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Pulsar.Client.Api;

namespace DotNetCore.CAP.Pulsar
{
@@ -11,10 +13,15 @@ namespace DotNetCore.CAP.Pulsar
private readonly IConnectionFactory _connection;
private readonly IOptions<PulsarOptions> _pulsarOptions;

public PulsarConsumerClientFactory(IConnectionFactory connection, IOptions<PulsarOptions> pulsarOptions)
public PulsarConsumerClientFactory(IConnectionFactory connection, ILoggerFactory loggerFactory, IOptions<PulsarOptions> pulsarOptions)
{
_connection = connection;
_pulsarOptions = pulsarOptions;

if (_pulsarOptions.Value.EnableClientLog)
{
PulsarClient.Logger = loggerFactory.CreateLogger<PulsarClient>();
}
}

public IConsumerClient Create(string groupId)
@@ -22,7 +29,7 @@ namespace DotNetCore.CAP.Pulsar
try
{
var client = _connection.RentClient();
var consumerClient = new PulsarConsumerClient(client,groupId, _pulsarOptions);
var consumerClient = new PulsarConsumerClient(client, groupId, _pulsarOptions);
return consumerClient;
}
catch (System.Exception e)


Chargement…
Annuler
Enregistrer