Request and event handler fallbacks with optional circuit breaker #65
vadikko2
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🚀 Release notes – v4.10.0
Fallbacks for requests and events
This release adds fallback support for request handlers and event handlers, with optional circuit breaker integration. You can now define primary and fallback handlers for commands, queries, streaming handlers, and domain events, and optionally protect them with a shared circuit breaker protocol.
🆕 What's new
📨 Request handler fallbacks
RequestHandlerFallback— wrap a primary and fallback request handler so that when the primary fails (or the circuit is open), the fallback is used.RequestHandler[Req, Res]and streamingStreamingRequestHandler[Req, Res].failure_exceptionsto trigger fallback only for specific exception types (e.g.ConnectionError,TimeoutError).Example:
📢 Event handler fallbacks
EventHandlerFallback— wrap a primary and fallback event handler so that when the primary fails (or the circuit is open), the fallback is used.failure_exceptionsand optional circuit breaker.EventMap).Example:
🔌 Unified circuit breaker protocol
ICircuitBreaker– a single protocol used by:AioBreakerAdapternow implementsICircuitBreaker(and stillISagaStepCircuitBreakerfor backward compatibility).📡 Streaming handlers
RequestHandlerFallbackis supported for streaming handlers: when the primary streaming handler fails, the fallback stream is used from the start (no resume from the same stream).🛠️ Helpers
get_generic_args_for_origin()incqrs.generic_utils– used to validate that primary and fallback handlers handle the same request/event and (for requests) the same response type.should_use_fallback()incqrs.circuit_breaker– central logic to decide whether to run the fallback after a primary failure (circuit open or exception infailure_exceptions, or any exception iffailure_exceptionsis empty).📚 Documentation and examples
examples/request_fallback.py– request handler fallback with optional circuit breakerexamples/cor_request_fallback.py– CoR (chain of responsibility) with fallbackexamples/event_fallback.py– event handler fallbackexamples/streaming_handler_fallback.py– streaming request handler fallbacktest_request_fallback.py,test_event_fallback.py; integration tests for the circuit breaker adapter updated.📋 API summary
cqrs.RequestHandlerFallbackfailure_exceptions, optionalcircuit_breaker).cqrs.EventHandlerFallbackcqrs.ICircuitBreakercall(identifier, func, *args, **kwargs)andis_circuit_breaker_error(exc).cqrs.circuit_breaker.should_use_fallbackcqrs.generic_utils.get_generic_args_for_origin✅ Compatibility
AioBreakerAdapterusage continue to work.AioBreakerAdapternow implementsICircuitBreakerin addition toISagaStepCircuitBreaker.aiobreakerfor circuit breaker support (pip install python-cqrs[aiobreaker]).This discussion was created from the release Request and event handler fallbacks with optional circuit breaker.
Beta Was this translation helpful? Give feedback.
All reactions