DeliveryCount error

Options

Hello,

I have a .net application which subscribe to a Solace queue and I’m able to get the messages and to acknowledge them. After the acknowledge (with success) I receive an error:

C#

SolaceSystems.Solclient.Messaging.OperationErrorException: Failed to get Delivery Count
   at SolaceSystems.Solclient.Utils.Types.Utilities.GuardAgainstNotOk(ReturnCode returnCode, String message, Boolean includeSdkError, ISolLogger logger)
   at SolaceSystems.Solclient.Messaging.Native.BasicMessageImpl.get_DeliveryCount()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at Serilog.Capturing.PropertyValueConverter.GetProperties(Object value)+MoveNext()

Does anyone how to configure the configure DeliveryCount in .net in order to avoid automatically call when step into the next message?

Answers

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 491 admin
    Options

    Hey @cristianpaun - looking at the dotnet Solace API reference docs I can see that an OperationErrorException is thrown when delivery count is not supported on the message.


    Can you confirm how the messages are published to the queue that you are binding to from your dotnet consumer?

  • cristianpaun
    cristianpaun Member Posts: 2
    edited February 2023 #3
    Options

    on my understanding this is a configuration related to the queue: Configuring Queues (solace.com). My problem is that I'm not trying to access this property on the message (DeliveryCount) it is done automatically when I subscribe to a queue and try to consume the message. Please see below my subscribe function and HandleMessage (with no get call for DeliveryCount):

       public void Subscribe(string topicName, EventHandler<MessageEventArgs> handleMessage)
       {
           var sessionProps = new SessionProperties
           {
               Host = Host,
               VPNName = VPNName,
               UserName = UserName,
               Password = Password,
               ReconnectRetries = DefaultReconnectRetries,
               SSLValidateCertificate = false,
               GdWithWebTransport = true,
           };
           try
           {
               Session = Context.CreateSession(sessionProps, null, null);
    
               var returnCode = Session.Connect();
               if (returnCode == ReturnCode.SOLCLIENT_OK)
               {
                   EndpointProperties endpointProps = new EndpointProperties()
                   {
                       Permission = EndpointProperties.EndpointPermission.Consume,
                       AccessType = EndpointProperties.EndpointAccessType.Exclusive
                   };
                   Queue = ContextFactory.Instance.CreateQueue(topicName);
    
                   Flow = Session.CreateFlow(new FlowProperties
                       {
                           AckMode = MessageAckMode.ClientAck
                       },
                       Queue, null, handleMessage, FlowEventHandler);
                   Flow.Start();
                   WaitEventWaitHandle.WaitOne();
                   Flow = Session.CreateFlow(new FlowProperties
                       {
                           AckMode = MessageAckMode.ClientAck
                       },
                       Queue, null, handleMessage, FlowEventHandler);
                   Flow.Start();
                   WaitEventWaitHandle.WaitOne();*/
               }
               else
               {
                   throw new Exception($"Cannot connect to topic {topicName}");
               }
           }
           catch (Exception e)
           {
               WaitEventWaitHandle.Set();
               throw;
           }
       } 
    
    private void HandleMessage(object? sender, MessageEventArgs messageEventArgs)
       {
           try
           {
               using var message = messageEventArgs.Message;
               _logger.LogInformation("Message received {@message}", message);
               _subscriberClient.AckMessage(message.ADMessageId);
               message.Dispose();
           }
           catch (Exception e)
           {
               _logger.LogInformation("Error {@Err}", e.Message);
           }
       }
    
  • nicholasdgoodman
    nicholasdgoodman Member, Employee Posts: 33 Solace Employee
    Options

    Hello there, @cristianpaun!

    I have a couple of questions regarding the sample code you have provided:

    Where is the exception being thrown? The provided stack trace does not show whether the exception is thrown from within the HandleMessage method or the Subscribe method.

    Where is the WaitEventtHandle being set (besides the catch block)? In the standard .NET samples, this AutoResetEvent is set within the HandleMessage handler.

    Why are there two separate flows being created on the same queue, and when are they being disposed? In a typical Solace app that reads from a Queue, the flow lives for the duration of the session and the HandleMessage handler will be invoked once for each message received.

    Otherwise, I have so far been unable to reproduce the issue you are seeing but have suspicions it may have to with re-assignment of the class property Flow between individual message events.