This article is contributed. See the original author and article here.
Service Bus (SB) client app fails with QuotaExceededException when sending messages to Session Enabled SB Queue, Subscription…
The exception will look something like this:
QuotaExceededException: The maximum entity size has been reached or exceeded for Queue: <SB Queue Name>. Size of entity in bytes:<Current Entity Size>, Max entity size in bytes: <Max Entity Size>.
QuotaExceededException is thrown when the message quota has been exceeded. The exception message further clarifies that the entity size has reachedexceeded the Max Limit.
You check Active, Dead lettered, Scheduled, Deferred, etc. messages in the entity. The size of all the messages is zero (or so small that it cannot add up to the max size of the entity).
You start wondering, what is causing the SB entity to fill up!
The root cause of the SB entity filling up could be that SB client applications are not cleaning up the Session States. Session state remains as long as it isn’t cleared up (returning null), even if all messages in a session are consumed. The previously set session state can be cleared by passing null to the SetState method on the receiver.
The session state held in a queue or in a subscription counts towards that entity’s storage quota. When the application is finished with a session, it is therefore recommended for the application to clean up its retained state
Please Refer: Service Bus message sessions
- You will see this scenario only with Session Enabled SB Entities i.e., Queue and Subscription.
- Make sure that Active, Dead lettered, Scheduled, etc., messages are not filling the entity.
Note: Do not try to second guess the size of an entity by the count of messages. You may have enabled Large Message Support
- Using Service Bus Explorer Tool, you can peek into the entities to understand the message distribution. If this is your test environment, you can Receive and Delete all the messages, including Dead lettered messages, OR purge the messages, and see if the entity size significantly decreases.
The above checks indicate the unused session state is not being cleared. So please review the receiver application code to check Session State is cleared or not.
Mitigation & Resolution:
A proper solution to the Session State leak, filling entity, is to clean up the Session State by calling SetState using a null parameter.
There are times when customers may not be able to do these code changes immediately. In such a case they can temporarily increase the entity size, OR Delete the entity and recreate the entity with the same name. This mitigation should always be followed by the above-suggested code fix.
Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.