Skip to content

Conversation

@richardpark-msft
Copy link
Member

This PR makes it so you can call ReceiveMessages after a Receiver (only in ReceiveAndDelete mode) is closed, giving you access to any cached messages that might have arrived after your final ReceiveMessages() call, but before Close().

Fixes #24078

@github-actions
Copy link

github-actions bot commented Jun 28, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

sdk/messaging/azservicebus

@richardpark-msft
Copy link
Member Author

/azp run go - azservicebus

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@richardpark-msft
Copy link
Member Author

/azp run go - azservicebus

@richardpark-msft richardpark-msft marked this pull request as ready for review June 30, 2025 17:12
Copilot AI review requested due to automatic review settings June 30, 2025 17:12
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where messages may be lost in ReceiveAndDelete mode by allowing calls to ReceiveMessages even after the receiver is closed, draining any cached messages.

  • Documentation and comments have been updated to reference new error types and behavior.
  • Caching logic was added to the receiver to store prefetched messages and enable later retrieval.
  • New tests and examples verify the new behavior and document proper usage.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/messaging/azservicebus/session_receiver.go Updated documentation comments to reference new error types and settlement methods
sdk/messaging/azservicebus/sender.go Updated error documentation in sender methods
sdk/messaging/azservicebus/receiver_test.go Added new tests to verify cached message retrieval in ReceiveAndDelete mode
sdk/messaging/azservicebus/receiver.go Introduced caching logic and the receiveFromCache helper to drain cached messages
sdk/messaging/azservicebus/message.go Adjusted newReceivedMessage to safely handle nil receivers
sdk/messaging/azservicebus/internal/amqpLinks.go Updated error handling to use a shared errClosed value and push cached messages after close
sdk/messaging/azservicebus/example_receiver_test.go Added new example demonstrating the ReceiveAndDelete flow post-close
sdk/messaging/azservicebus/client.go Updated documentation in session receiver creation methods
sdk/messaging/azservicebus/CHANGELOG.md Added changelog entry detailing the bug fix

@richardpark-msft
Copy link
Member Author

/azp run go - azservicebus

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…s just get all 2000 and under normal conditions we do.

However, it's not guaranteed so I've added an extra step to drain the queue of any remaining messages and check that we truly haven't lost anything.
@richardpark-msft
Copy link
Member Author

/azp run go - azservicebus

@richardpark-msft
Copy link
Member Author

(Just a note, the test failure was just a problem with my test, not the package code)

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@richardpark-msft
Copy link
Member Author

/azp run go - azservicebus

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@richardpark-msft richardpark-msft merged commit 7315a8e into Azure:main Jul 9, 2025
16 checks passed
@richardpark-msft richardpark-msft deleted the sb-receive-after-close branch July 9, 2025 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[azservicebus] Better ReceiveAndDelete behavior when receiving then closing the link

2 participants