rebus-org / Rebus.RabbitMq

:bus: RabbitMQ transport for Rebus
https://mookid.dk/category/rebus
Other
62 stars 44 forks source link

Message body messed up (sometimes) #85

Closed epgeroy closed 2 years ago

epgeroy commented 2 years ago

I have a really weird error in a rebus + rabbitmq project

While deserializing using this really simple implementation

public class SomeSerializer : ISerializer
    {
        public Task<Message> Deserialize(TransportMessage transportMessage)
        {
            Dictionary<string, string> headers = transportMessage.Headers.Clone();

            headers.TryAdd(
                "rbs2-content-type",
                "application/json; charset=utf-8"
            );

            string json = Encoding.UTF8.GetString(
                transportMessage
                    .Body
            );

            return Task.FromResult(
                new Message(
                    headers,
                    JsonConvert.DeserializeObject<List<SomeDto>>(
                        json
                    )
                )
            );
        }

        public Task<TransportMessage> Serialize(Message message)
        {
            throw new NotImplementedException();
        }
    }
}  // it feels like this could be improved, drop a hint in the comments if you think so.

I checked all the pulled messages and they were properly formatted, encoded, and valid JSONs, they even worked after several attempts. I also set the parallelization to 1 in case there were any relation and for debugging purposes

This is my configuration in case that is relevant

Bus = Rebus.Config.Configure.With(_activator)
                .Logging(
                    logging => logging.ColoredConsole(LogLevel.Debug)
                ).Transport(
                    transport =>
                    {
                        transport
                            .UseRabbitMq(_connectionString, queueName)
                            .Ssl(
                                new Rebus.RabbitMq.SslSettings(true, "*.somerabbitmqserver.com")
                                {
                                    Version = SslProtocols.Tls12
                                }
                            ).SetMaxPollingTimeout(TimeSpan.FromSeconds(5));
                    }
                ).Options(
                    options =>
                    {
                        options.SetMaxParallelism(1);
                        options.SetBackoffTimes(
                            TimeSpan.FromMilliseconds(100),
                            TimeSpan.FromMilliseconds(1000),
                            TimeSpan.FromSeconds(3)
                        );
                    }
                ).Serialization(
                    serialization => serialization
                        .Register(context => serializer))
                .Start();

The only thing I can think of is that the content of the message is too long. I'll update this issue tomorrow with my findings reducing the length of the message body.

Any ideas on what is going on? Thanks in advance

mookid8000 commented 2 years ago

Which version of Rebus.RabbitMq are you using?

epgeroy commented 2 years ago

Which version of Rebus.RabbitMq are you using?

I'm using 7.3.1-b9

epgeroy commented 2 years ago

Update. Is not related to the length of the message and is not a competing consumers problem also.

mookid8000 commented 2 years ago

I think you'll need to update to 7.3.1-b11

and I realize now that NuGet might not understand that b11 comes after b9, as it'll probably treat the prerelease portion of the version number as a string...

So.... for now, update to 7.3.1-b11 by going

update-package rebus.rabbitmq -version 7.3.1-b11
mookid8000 commented 2 years ago

OK I've just published version 7.3.2-b01 which will sort properly, and thus if you

update-package rebus.rabbitmq -pre

you'll end up with it.

It has had a bug fixed, which should result in no more mangled message bodies. The problem seemed to be that the RabbitMQ driver would reuse byte arrays (probably from an internal object pool of some kind) too early, and so the Rebus transport needed to clone the data before that happened.

Sorry about any inconvenience this might have caused. 😐

epgeroy commented 2 years ago

Thank you so much, this was fast. I end up downgrading to 7.3.0 and everything was working. I'll update to the latest version