Download the PHP package tourze/json-rpc-lock-bundle without Composer
On this page you can find all versions of the php package tourze/json-rpc-lock-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package json-rpc-lock-bundle
JsonRPC Lock Bundle
中文
A Symfony Bundle that provides automatic locking functionality for JsonRPC interfaces to handle concurrent request control and idempotency.
Features
- Automatic concurrency control for JsonRPC requests
- User-based lock resource identification
- Request idempotency handling with caching
- Graceful exception handling and logging
- Support for custom lock resource strategies
- Fallback retry mechanism for lock failures
Dependencies
This bundle requires:
- PHP 8.1 or higher
- Symfony 7.3 or higher
- tourze/json-rpc-core
- tourze/lock-service-bundle
- tourze/backtrace-helper
- Symfony Security Bundle
Installation
Install via Composer:
Configuration
Register the bundle in your Symfony application:
No additional configuration is required. The bundle works out of the box with sensible defaults.
Quick Start
Create a JsonRPC procedure by extending LockableProcedure:
Advanced Usage
Custom Lock Resources
Override the getLockResource method to customize locking behavior:
Idempotency Support
Enable request caching for idempotent operations:
Cached results expire after 60 seconds by default. If a cached result exists, it will be returned immediately without acquiring locks or executing the procedure.
Fallback Retry
Enable automatic retry without locking for non-critical operations:
How It Works
-
Lock Resource Preparation: Based on user identity or procedure name
- Authenticated users: Uses
user.getUserIdentifier() - Anonymous requests: Uses procedure class name
- Custom: Override
getLockResource()method
- Authenticated users: Uses
-
Idempotency Check: Returns cached result if available and cache key is set
-
Lock Acquisition: Acquires distributed lock using
LockService.blockingRun() -
Execution: Runs the actual procedure logic via
parent::__invoke() -
Result Caching: Stores result for 60 seconds (if idempotent cache key is provided)
- Exception Handling:
- Lock conflicts: Returns cached result or throws "你手速太快了,请稍候" message
- General exceptions: Logs error and optionally retries without lock if
fallbackRetry()returns true
Environment Variables
JSON_RPC_RESPONSE_EXCEPTION_MESSAGE: Custom message for lock conflict exceptions (default: "你手速太快了,请稍候")
Testing
Run the test suite:
For static analysis:
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Ensure tests pass (
./vendor/bin/phpunit) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This bundle is released under the MIT License. See the LICENSE file for details.
All versions of json-rpc-lock-bundle with dependencies
symfony/cache-contracts Version ^3
symfony/config Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/framework-bundle Version ^7.4
symfony/http-kernel Version ^7.3
symfony/lock Version ^7.3
symfony/property-access Version ^7.3
symfony/security-bundle Version ^7.3
symfony/security-core Version ^7.3
symfony/service-contracts Version ^3.6
symfony/yaml Version ^7.3
tourze/backtrace-helper Version 1.*
tourze/bundle-dependency Version 1.*
tourze/json-rpc-core Version 2.0.*
tourze/lock-service-bundle Version 1.0.*