🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

Is it safe to reuse messages without calling Reset()?

allmhhuran
allmhhuran Member Posts: 47 ✭✭✭
edited August 2020 in PubSub+ Event Broker #1

Suppose I have a Publisher class which encapsulates the details of the solace broker. For any given application, it will receive an instance of a Publisher for a given topic to which it wants to send guaranteed messages.

This means that the IMessage properties Destination and DeliveryMode are guaranteed to be constant for the lifetime of a particular Publisher instance, and certain other default settings will also be constant (such as TimeToLive).

In the Solace PubSub+ docs I have seen advice that messages be reused. I take this to refer to the allocation and garbage collection advantage of not wrapping every individualISession.Send() in a using var message = ContextFactory.Instance.CreateMessage() block.

Is it safe to maintain a single instance of an IMesssage, and only change message specific properties between Send() operations (ie, obviously the BinaryAttachment, and things like ApplicationMessageID) without calling Reset() on the message?

This is more for code brevity than performance, since assigning the topic and delivery mode for each message are of course operations likely to take essentially no time. It would just eliminate a few apparently redundant assignments in the publisher code.

Tagged:

Comments

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    Hey hey! @allmhhuran . I'm back from vacation, and I got an answer back from our Support team. Then I did a bit of back-and-forth with them. Anyhow, short answer is: yes, it is safe to use. Calling reset() is more of a convenience feature to allow the resetting of the message state back to default/uninitialized.

    The only thing I can think of is that if you get a NACK when publishing a Guaranteed message, and you've "overwritten" (essentially) the message, then you'll have to reconstruct it or something if you want to try resending.

  • allmhhuran
    allmhhuran Member Posts: 47 ✭✭✭

    Great, thanks for investigating that!

This Week's Leaders