This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new e046776  Updated NuGet packages and subscription properties can be 
added when creating a consumer
e046776 is described below

commit e046776051c0cf85b190d7aae5bde3bddaaf49e0
Author: Daniel Blankensteiner <[email protected]>
AuthorDate: Tue Jan 10 13:01:19 2023 +0100

    Updated NuGet packages and subscription properties can be added when 
creating a consumer
---
 CHANGELOG.md                                   |  6 ++++++
 src/DotPulsar/Abstractions/IConsumerBuilder.cs |  7 ++++++-
 src/DotPulsar/ConsumerOptions.cs               |  9 ++++++++-
 src/DotPulsar/DotPulsar.csproj                 |  6 +++---
 src/DotPulsar/Internal/ConsumerBuilder.cs      | 12 +++++++++++-
 src/DotPulsar/PulsarClient.cs                  |  9 ++++++++-
 tests/DotPulsar.Tests/DotPulsar.Tests.csproj   |  6 +++---
 7 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9f44d8..2a5740e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this 
file.
 
 The format is based on [Keep a 
Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to 
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [Unreleased]
+
+### Added
+
+- Subscription properties can be added when creating a consumer
+
 ## [2.7.0] - 2022-12-08
 
 ### Added
diff --git a/src/DotPulsar/Abstractions/IConsumerBuilder.cs 
b/src/DotPulsar/Abstractions/IConsumerBuilder.cs
index 54d1fbd..c4dc94d 100644
--- a/src/DotPulsar/Abstractions/IConsumerBuilder.cs
+++ b/src/DotPulsar/Abstractions/IConsumerBuilder.cs
@@ -1,4 +1,4 @@
-/*
+/*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -54,6 +54,11 @@ public interface IConsumerBuilder<TMessage>
     /// </summary>
     IConsumerBuilder<TMessage> SubscriptionName(string name);
 
+    /// <summary>
+    /// Add/Set a property key/value on the subscription. This is optional.
+    /// </summary>
+    public IConsumerBuilder<TMessage> SubscriptionProperty(string key, string 
value);
+
     /// <summary>
     /// Set the subscription type for this consumer. The default is 
'Exclusive'.
     /// </summary>
diff --git a/src/DotPulsar/ConsumerOptions.cs b/src/DotPulsar/ConsumerOptions.cs
index 4b30972..3e9d112 100644
--- a/src/DotPulsar/ConsumerOptions.cs
+++ b/src/DotPulsar/ConsumerOptions.cs
@@ -1,4 +1,4 @@
-/*
+/*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -15,6 +15,7 @@
 namespace DotPulsar;
 
 using DotPulsar.Abstractions;
+using System.Collections.Generic;
 
 /// <summary>
 /// The consumer building options.
@@ -56,6 +57,7 @@ public sealed class ConsumerOptions<TMessage>
         MessagePrefetchCount = DefaultMessagePrefetchCount;
         ReadCompacted = DefaultReadCompacted;
         SubscriptionType = DefaultSubscriptionType;
+        SubscriptionProperties = new Dictionary<string, string>();
         SubscriptionName = subscriptionName;
         Topic = topic;
         Schema = schema;
@@ -101,6 +103,11 @@ public sealed class ConsumerOptions<TMessage>
     /// </summary>
     public string SubscriptionName { get; set; }
 
+    /// <summary>
+    /// Add/Set the subscription's properties. This is optional.
+    /// </summary>
+    public Dictionary<string, string> SubscriptionProperties { get; set; }
+
     /// <summary>
     /// Set the subscription type for this consumer. The default is 
'Exclusive'.
     /// </summary>
diff --git a/src/DotPulsar/DotPulsar.csproj b/src/DotPulsar/DotPulsar.csproj
index 4b5853c..588c430 100644
--- a/src/DotPulsar/DotPulsar.csproj
+++ b/src/DotPulsar/DotPulsar.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
@@ -23,9 +23,9 @@
 
   <ItemGroup>    
     <PackageReference Include="HashDepot" Version="2.0.3" />
-    <PackageReference Include="Microsoft.Extensions.ObjectPool" 
Version="7.0.0" />
+    <PackageReference Include="Microsoft.Extensions.ObjectPool" 
Version="7.0.1" />
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" 
PrivateAssets="All" />
-    <PackageReference Include="protobuf-net" Version="3.1.25" />
+    <PackageReference Include="protobuf-net" Version="3.1.26" />
     <PackageReference Include="System.IO.Pipelines" Version="7.0.0" />
   </ItemGroup>
 
diff --git a/src/DotPulsar/Internal/ConsumerBuilder.cs 
b/src/DotPulsar/Internal/ConsumerBuilder.cs
index bac10c2..cf85cc1 100644
--- a/src/DotPulsar/Internal/ConsumerBuilder.cs
+++ b/src/DotPulsar/Internal/ConsumerBuilder.cs
@@ -1,4 +1,4 @@
-/*
+/*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -16,6 +16,7 @@ namespace DotPulsar.Internal;
 
 using DotPulsar.Abstractions;
 using DotPulsar.Exceptions;
+using System.Collections.Generic;
 
 public sealed class ConsumerBuilder<TMessage> : IConsumerBuilder<TMessage>
 {
@@ -27,6 +28,7 @@ public sealed class ConsumerBuilder<TMessage> : 
IConsumerBuilder<TMessage>
     private uint _messagePrefetchCount;
     private bool _readCompacted;
     private string? _subscriptionName;
+    private readonly Dictionary<string, string> _subscriptionProperties;
     private SubscriptionType _subscriptionType;
     private string? _topic;
     private IHandleStateChanged<ConsumerStateChanged>? _stateChangedHandler;
@@ -39,6 +41,7 @@ public sealed class ConsumerBuilder<TMessage> : 
IConsumerBuilder<TMessage>
         _priorityLevel = ConsumerOptions<TMessage>.DefaultPriorityLevel;
         _messagePrefetchCount = 
ConsumerOptions<TMessage>.DefaultMessagePrefetchCount;
         _readCompacted = ConsumerOptions<TMessage>.DefaultReadCompacted;
+        _subscriptionProperties = new Dictionary<string, string>();
         _subscriptionType = ConsumerOptions<TMessage>.DefaultSubscriptionType;
     }
 
@@ -84,6 +87,12 @@ public sealed class ConsumerBuilder<TMessage> : 
IConsumerBuilder<TMessage>
         return this;
     }
 
+    public IConsumerBuilder<TMessage> SubscriptionProperty(string key, string 
value)
+    {
+        _subscriptionProperties[key] = value;
+        return this;
+    }
+
     public IConsumerBuilder<TMessage> SubscriptionType(SubscriptionType type)
     {
         _subscriptionType = type;
@@ -112,6 +121,7 @@ public sealed class ConsumerBuilder<TMessage> : 
IConsumerBuilder<TMessage>
             PriorityLevel = _priorityLevel,
             ReadCompacted = _readCompacted,
             StateChangedHandler = _stateChangedHandler,
+            SubscriptionProperties = _subscriptionProperties,
             SubscriptionType = _subscriptionType
         };
 
diff --git a/src/DotPulsar/PulsarClient.cs b/src/DotPulsar/PulsarClient.cs
index 2767568..27135f3 100644
--- a/src/DotPulsar/PulsarClient.cs
+++ b/src/DotPulsar/PulsarClient.cs
@@ -1,4 +1,4 @@
-/*
+/*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -101,6 +101,13 @@ public sealed class PulsarClient : IPulsarClient
             Topic = options.Topic,
             Type = (CommandSubscribe.SubType) options.SubscriptionType
         };
+
+        foreach (var property in options.SubscriptionProperties)
+        {
+            var keyValue = new KeyValue { Key = property.Key, Value = 
property.Value };
+            subscribe.SubscriptionProperties.Add(keyValue);
+        }
+
         var messagePrefetchCount = options.MessagePrefetchCount;
         var messageFactory = new MessageFactory<TMessage>(options.Schema);
         var batchHandler = new BatchHandler<TMessage>(true, messageFactory);
diff --git a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj 
b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
index 349b2f5..d1640b1 100644
--- a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
+++ b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
@@ -12,9 +12,9 @@
     <PackageReference Include="Ductus.FluentDocker" Version="2.10.57" />
     <PackageReference Include="FluentAssertions" Version="6.8.0" />
     <PackageReference Include="IronSnappy" Version="1.3.0" />
-    <PackageReference Include="K4os.Compression.LZ4" Version="1.2.16" />
+    <PackageReference Include="K4os.Compression.LZ4" Version="1.3.5" />
     <PackageReference Include="NSubstitute" Version="4.4.0" />
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
     <PackageReference Include="xunit" Version="2.4.2" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
       <PrivateAssets>all</PrivateAssets>
@@ -25,7 +25,7 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; 
buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="ZstdNet" Version="1.4.5" />
-    <PackageReference Include="ZstdSharp.Port" Version="0.6.5" />
+    <PackageReference Include="ZstdSharp.Port" Version="0.6.7" />
   </ItemGroup>
 
   <ItemGroup>

Reply via email to