0

I'm using NSB version6.2 and RabbitMQ version 4. I'm using RabbitMQTransport. My RabbitMQ server is in a virtual machine in Azure. when I send messages, sometimes I'm losing messages without any error.

this is my NService Bus configuration.

            EndpointConfiguration config = null;
        string endpointName = ConfigurationManager.AppSettings.Get("NServiceBus.EndpointName");
        config = configEndPoint.IsNullOrDefault() ? new EndpointConfiguration(endpointName) : configEndPoint;
        int maximumConcurrencyLevel = ConfigurationManager.AppSettings.Get("NServiceBus.TransportConfig.MaximumConcurrencyLevel").ToInt();
        config.LimitMessageProcessingConcurrencyTo(maximumConcurrencyLevel);
        int numberOfRetries = ConfigurationManager.AppSettings.Get("NServiceBus.TransportConfig.NumberOfRetries").ToInt();
        var recoverability = config.Recoverability();
        recoverability.Immediate(
            customizations: immediate =>
            {
                immediate.NumberOfRetries(numberOfRetries);
            });

        DefaultFactory defaultFactory = LogManager.Use<DefaultFactory>();
        defaultFactory.Directory(this.DatabusDirectory);
        defaultFactory.Level(LogLevel.Error);

        config.IdealinkJsonSerializer();
        config.UsePersistence<InMemoryPersistence>();

        config.SendFailedMessagesTo("error");
        config.AuditProcessedMessagesTo("audit");

        // configure transport
        config.UseTransport<RabbitMQTransport>().Transactions(TransportTransactionMode.ReceiveOnly);
         var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
Fereshteh Rabet
  • 191
  • 2
  • 18
  • What specific version of RabbitMQ transport, client, and server do you use? Could you also elaborate on the scenario in which you're observing message loss? If you have a specific handler that you can repro it with, could you share that code/handler code? – Sean Feldman Oct 18 '17 at 16:44
  • we are using NServiceBus.Transports.RabbitMQ version 4.0.0.0. I'm trying to add points after commenting. so every time that I comment we will send a message to the service bus. then we will send a local message to add a point. this is a code for sending local message context.SendLocal(message); and my context is IMessageHandlerContext – Fereshteh Rabet Oct 18 '17 at 16:58
  • I've noticed that you're using InMemoryPersistence. If you have a message failing and going into delayed retries, timeouts won't survive endpoint restarts as they will be stored in memory. You should change InMemoryPersistence to a production grade persistence. Also, try using the latest version of the transport (4.4.0 curently), which has timeouts implemented natively. – Sean Feldman Oct 18 '17 at 17:33
  • (check your log file for exceptions to see if retries are indeed involved or not). – Sean Feldman Oct 18 '17 at 17:36
  • What is a production grade persistence? – Fereshteh Rabet Oct 18 '17 at 18:39
  • Persistence that is not volatile. https://docs.particular.net/persistence/ – Sean Feldman Oct 18 '17 at 19:17

1 Answers1

4

Configuration of your endpoint looks fine with an exception of persistence. Persistence is used for features that are not supported by the underlying transport natively. For RabbitMQ, there is not native mechanism to send delayed messages. Until version 4.3 persistence was used to store timeouts. If you use InMemoryPersistence, none of the information will be retained after endpoint restarts. Timeouts are needed for Recoverability feature, specifically delayed retries. From version 4.3 and above, persistence is not required for timeouts, but InMemoryPersistence should still not be used. You can chose other persistences based on technology and scenario at hand.

Please note that version 4.0.0 is not under supported versions. You should update to 4.3.x or 4.4.x and verify the behavior to see if you notice a message loss or not. In case you still losing messages, I suggest providing more details such as log file and handler code. If you can't share that publicly, submit a support case.

Hope that helps.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • I used SqlPersistence instead of InMemoryPersistence, now I have an error when I'm trying to send a message, "The given key (NServiceBus.PipelineConfiguration) was not present in the dictionary." my configuration code is var persistence = config.UsePersistence(); persistence.SqlVariant(SqlVariant.MsSqlServer); persistence.ConnectionBuilder(connectionBuilder: () =>{new SqlConnection(ConfigurationManager.ConnectionStrings["Idealink"].ConnectionString);} – Fereshteh Rabet Oct 19 '17 at 16:49
  • @FereshtehRabet this goes beyond a question and answer, more looking as a support case. Perhaps raising a [support issue](https://particular.net/support#modal_support_form) to get help would be more efficient. – Sean Feldman Oct 19 '17 at 21:01