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

aaronai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 7cd8cf63 Bugfix: Add constructor to copy message
7cd8cf63 is described below

commit 7cd8cf634bb8ecc918d88fd008f0522461fbdd1c
Author: Aaron Ai <[email protected]>
AuthorDate: Mon Feb 27 12:01:56 2023 +0800

    Bugfix: Add constructor to copy message
---
 csharp/examples/ProducerBenchmark.cs                   |  6 +++---
 csharp/rocketmq-client-csharp/Error/ClientException.cs |  3 ++-
 csharp/rocketmq-client-csharp/Message.cs               | 11 +++++++++++
 csharp/rocketmq-client-csharp/PublishingMessage.cs     |  2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/csharp/examples/ProducerBenchmark.cs 
b/csharp/examples/ProducerBenchmark.cs
index 6f94028e..a114f879 100644
--- a/csharp/examples/ProducerBenchmark.cs
+++ b/csharp/examples/ProducerBenchmark.cs
@@ -29,7 +29,7 @@ namespace examples
     {
         private static readonly Logger Logger = 
MqLogManager.Instance.GetCurrentClassLogger();
 
-        private static readonly SemaphoreSlim _semaphore = new 
SemaphoreSlim(0);
+        private static readonly SemaphoreSlim Semaphore = new(0);
         private static long _counter = 0;
 
         internal static void QuickStart()
@@ -74,7 +74,7 @@ namespace examples
             {
                 while (true)
                 {
-                    _semaphore.Release(tpsLimit);
+                    Semaphore.Release(tpsLimit);
                     await Task.Delay(TimeSpan.FromSeconds(1));
                 }
             });
@@ -91,7 +91,7 @@ namespace examples
             var tasks = new List<Task>();
             while (true)
             {
-                _semaphore.Wait();
+                Semaphore.Wait();
                 Interlocked.Increment(ref _counter);
                 var task = producer.Send(message);
                 tasks.Add(task);
diff --git a/csharp/rocketmq-client-csharp/Error/ClientException.cs 
b/csharp/rocketmq-client-csharp/Error/ClientException.cs
index f5fc4a92..78063531 100644
--- a/csharp/rocketmq-client-csharp/Error/ClientException.cs
+++ b/csharp/rocketmq-client-csharp/Error/ClientException.cs
@@ -37,7 +37,8 @@ namespace Org.Apache.Rocketmq.Error
         {
         }
 
-        protected ClientException(int responseCode, string message) : base()
+        protected ClientException(int responseCode, string message) : base(
+            $"[{ResponseCodeKey}={responseCode}] {message}")
         {
         }
     }
diff --git a/csharp/rocketmq-client-csharp/Message.cs 
b/csharp/rocketmq-client-csharp/Message.cs
index 9993b52f..19e868fc 100644
--- a/csharp/rocketmq-client-csharp/Message.cs
+++ b/csharp/rocketmq-client-csharp/Message.cs
@@ -44,6 +44,17 @@ namespace Org.Apache.Rocketmq
             DeliveryTimestamp = null;
         }
 
+        internal Message(Message message)
+        {
+            Topic = message.Topic;
+            Tag = message.Tag;
+            Keys = message.Keys;
+            Body = message.Body;
+            MessageGroup = message.MessageGroup;
+            UserProperties = message.UserProperties;
+            DeliveryTimestamp = message.DeliveryTimestamp;
+        }
+
         public string Topic { get; set; }
 
         public byte[] Body { get; set; }
diff --git a/csharp/rocketmq-client-csharp/PublishingMessage.cs 
b/csharp/rocketmq-client-csharp/PublishingMessage.cs
index c5b4b22c..efdc568f 100644
--- a/csharp/rocketmq-client-csharp/PublishingMessage.cs
+++ b/csharp/rocketmq-client-csharp/PublishingMessage.cs
@@ -34,7 +34,7 @@ namespace Org.Apache.Rocketmq
         internal string MessageId { get; }
 
         public PublishingMessage(Message message, PublishingSettings 
publishingSettings, bool txEnabled) : base(
-            message.Topic, message.Body)
+            message)
         {
             var maxBodySizeBytes = publishingSettings.GetMaxBodySizeBytes();
             if (message.Body.Length > maxBodySizeBytes)

Reply via email to