[WebPubSub] Support invoke_event for webpubsub client - #45450
[WebPubSub] Support invoke_event for webpubsub client#45450Shiying Chen (MoChilia) wants to merge 13 commits into
invoke_event for webpubsub client#45450Conversation
There was a problem hiding this comment.
Pull request overview
Adds a preview invoke_event request/response API to WebPubSubClient (sync + async), enabling upstream-event invocation with correlated invokeResponse handling, plus associated protocol/model updates and unit tests.
Changes:
- Introduces new invoke/cancel/invokeResponse message models and invocation management helpers.
- Adds
invoke_eventimplementation to sync and async clients with correlation and error mapping viaInvocationError. - Updates unit tests/protocol parsing and README documentation for the new preview feature.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/webpubsub/azure-messaging-webpubsubclient/tests/test_unit.py | Adds protocol write/parse coverage for invoke/cancel/invokeResponse frames. |
| sdk/webpubsub/azure-messaging-webpubsubclient/tests/test_invocation_manager.py | Adds sync InvocationManager unit tests. |
| sdk/webpubsub/azure-messaging-webpubsubclient/tests/test_invocation_manager_async.py | Adds async InvocationManagerAsync unit tests. |
| sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/models/_models.py | Adds new invoke-related models, protocol parse/write support, and invocation managers/errors. |
| sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/models/_enums.py | Extends upstream message types to include invoke/cancelInvocation. |
| sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/models/init.py | Exposes new public result/error types and InvocationError. |
| sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/aio/_client.py | Implements async invoke_event, integrates invokeResponse dispatch and disconnect rejection. |
| sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py | Implements sync invoke_event, integrates invokeResponse dispatch and disconnect rejection. |
| sdk/webpubsub/azure-messaging-webpubsubclient/README.md | Documents invoke_event usage (preview). |
|
Hi Shiying Chen (@MoChilia). Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
|
Hi Shiying Chen (@MoChilia). Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
| try: | ||
| await self._send_message(invoke_message, **kwargs) | ||
| except Exception as e: | ||
| invocation_error = ( | ||
| e | ||
| if isinstance(e, InvocationError) | ||
| else InvocationError( | ||
| str(e) if str(e) else "Failed to send invocation message.", | ||
| invocation_id=invocation_id, | ||
| ) | ||
| ) | ||
| self._invocation_map.reject(invocation_id, invocation_error) | ||
| raise invocation_error from e | ||
|
|
||
| try: |
| except Exception as e: # pylint: disable=broad-except | ||
| should_cancel = ( | ||
| entry.result is None and isinstance(e, InvocationError) and e.error_detail is None | ||
| ) |
| return await func() | ||
| except InvocationError: | ||
| raise |
| try: | ||
| return func() | ||
| except InvocationError: | ||
| raise |
| # Release History | ||
|
|
||
| ## 1.1.1 (2024-XX-XX) | ||
| ## 1.2.0 (Unreleased) |
| import threading | ||
| import pytest | ||
| from unittest.mock import patch, MagicMock |
| import asyncio | ||
| import pytest | ||
| from unittest.mock import patch, AsyncMock |
| def test_disconnect_rejects_pending_invocation(self): | ||
| """Pending invocations are rejected when reject_all is called (simulating disconnect).""" | ||
| client = _make_client() | ||
| errors_received = [] |
Description
Adds a preview
invoke_eventAPI to the Web PubSub client SDK, enabling request-response style communication with upstream event handlers. The client sends an invoke request, awaits the correlatedinvokeResponse, and returns the result, or raisesInvocationErroron failure/timeout.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines