Is it safe to reuse messages without calling Reset()?
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
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
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 individual
ISession.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.