savan-rangrej commented on issue #208:
URL:
https://github.com/apache/pulsar-dotpulsar/issues/208#issuecomment-2022626500
Hello Everyone,
Even I'm facing the same issue.
Lets say, If I have 10 parallel threads and trying to receive the messages
in parallel, Im getting index out of range exception.
Please find the below code, I have created sample console program to
reproduce the issue.
**System.IndexOutOfRangeException: Index was outside the bounds of the array.
at DotPulsar.Internal.Consumer`1.Receive(CancellationToken
cancellationToken)
at DotPulsar.Internal.Consumer`1.<Receive>d__34.MoveNext()**
`
internal class Program
{
private static
ConcurrentQueue<ValueTask<IMessage<ReadOnlySequence<byte>>>>
_messageConcurrentQueue = new();
static async Task Main(string[] args)
{
var client = PulsarClient.Builder().ServiceUrl(new
Uri("pulsar://X.X.X.X:6650/")).Build();
string topic = $"persistent://Mytenant/MySubscription/MyTopic";
var consumer = client.NewConsumer()
.Topic(topic)
.SubscriptionName("AutomationSubscription")
.SubscriptionType(SubscriptionType.Shared)
.Create();
while (true)
{
if (_messageConcurrentQueue.Count() < 10)
{
_messageConcurrentQueue.Enqueue(consumer.Receive());
}
if (_messageConcurrentQueue.Count() > 0)
{
_messageConcurrentQueue.TryDequeue(out var MessageResult);
if (MessageResult.IsCompleted)
{
if (!MessageResult.IsCanceled &&
!MessageResult.IsFaulted)
{
var Result = MessageResult.Result;
if (Result != null && Result.Data.Length > 0)
{
await consumer.Acknowledge(Result);
System.Console.WriteLine(
Encoding.UTF8.GetString(Result.Data.ToArray()));
}
}
else
{
if (MessageResult.IsFaulted)
{
System.Console.WriteLine(MessageResult.AsTask().Exception?.InnerException);
}
}
}
else
_messageConcurrentQueue.Enqueue(MessageResult);
}
}
}
}
`
Regards
Savan Rangrej
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]