PHPackages                             tourze/json-rpc-async-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tourze/json-rpc-async-bundle

ActiveSymfony-bundle[API Development](/categories/api)

tourze/json-rpc-async-bundle
============================

JsonRPC异步实现

0.1.5(5mo ago)037MITPHPCI passing

Since Apr 13Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/json-rpc-async-bundle)[ Packagist](https://packagist.org/packages/tourze/json-rpc-async-bundle)[ RSS](/packages/tourze-json-rpc-async-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (36)Versions (13)Used By (0)

JsonRPC Async Bundle
====================

[](#jsonrpc-async-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![PHP Version](https://camo.githubusercontent.com/7f5ae6ef0e1cfcd163dee1414b4a8058209fd4f03907a55dd4e94bb19dc158c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/json-rpc-async-bundle)[![License](https://camo.githubusercontent.com/24aa2184063894fd82fddc4f8226dcc2c2211dc5be4321f9ffe96a389eb8a74e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/json-rpc-async-bundle)[![Latest Version](https://camo.githubusercontent.com/a70b0e63aca26c4b52dea2445d5b972e3cb2e28df92bcfadac265222ff84fd32/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/json-rpc-async-bundle)[![Build Status](https://camo.githubusercontent.com/8ef1e617124ff8e123ad8df934be6eae2132db45dc1ac8ccfa1f26ffc8386c22/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tourze/json-rpc-async-bundle)[![Quality Score](https://camo.githubusercontent.com/d6add56eccb84efad9d3fa3eba84994c15d5b9b8d46c971c2e1c010daa333da4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/json-rpc-async-bundle)[![Code Coverage](https://camo.githubusercontent.com/2cffd29ccdeeb5ff769c6d692efd21b136d6dfac7a65e37f808952c0460f74f4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/json-rpc-async-bundle)[![Total Downloads](https://camo.githubusercontent.com/c921b9f384c21b0a63776d2219cf565759ccad0ea726e9f1376540c1d87f88d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f6a736f6e2d7270632d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/json-rpc-async-bundle)

A Symfony bundle for handling asynchronous JSON-RPC requests and results, allowing heavy or long-running JSON-RPC calls to be processed asynchronously and their results to be queried later.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Advanced Usage](#advanced-usage)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)
- [Changelog](#changelog)

Features
--------

[](#features)

- Asynchronous execution for JSON-RPC methods
- Task ID based result query
- Result persistence with Doctrine ORM
- Cache-first result retrieval
- Integration with Symfony Messenger and Snowflake ID
- Automatic cleanup for expired results

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- Doctrine ORM &gt;= 3.0
- Symfony Messenger for async task processing

### Install via Composer

[](#install-via-composer)

```
composer require tourze/json-rpc-async-bundle
```

### Enable the Bundle

[](#enable-the-bundle)

Register the bundle in your `config/bundles.php` if not auto-registered:

```
return [
    Tourze\JsonRPCAsyncBundle\JsonRPCAsyncBundle::class => ['all' => true],
];
```

### Database Setup

[](#database-setup)

Run the database migrations to create the required tables:

```
php bin/console doctrine:migrations:migrate
```

### Configure Symfony Messenger

[](#configure-symfony-messenger)

Ensure your `config/packages/messenger.yaml` has async transport configured:

```
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'Tourze\JsonRPCAsyncBundle\Message\AsyncProcedureMessage': async
```

Quick Start
-----------

[](#quick-start)

1. **Mark a JSON-RPC method as async** using the `AsyncExecute` attribute.
2. **Call the method** from client with a normal JSON-RPC request. If the environment is production and the request has a valid ID, the method is executed asynchronously.
3. **Receive a taskId** in the error response (`code: -799`), indicating the async task has started.
4. **Query the result** by calling the `GetAsyncRequestResult` procedure with the returned `taskId`.

### Example

[](#example)

### 1. Marking a method async

[](#1-marking-a-method-async)

```
use Tourze\JsonRPCAsyncBundle\Attribute\AsyncExecute;

#[AsyncExecute]
class MyAsyncProcedure extends BaseProcedure { ... }
```

### 2. Client requests async method

[](#2-client-requests-async-method)

```
{
  "jsonrpc": "2.0",
  "method": "myAsyncMethod",
  "params": { ... },
  "id": "async_123456"
}
```

### 3. Receive async response

[](#3-receive-async-response)

```
{
  "jsonrpc": "2.0",
  "id": "async_123456",
  "error": {
    "code": -799,
    "message": "Async executing",
    "data": { "taskId": "..." }
  }
}
```

### 4. Query result

[](#4-query-result)

```
{
  "jsonrpc": "2.0",
  "method": "GetAsyncRequestResult",
  "params": { "taskId": "..." },
  "id": "query_1"
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Configuration

[](#custom-configuration)

You can customize the async result persistence duration:

```
# config/packages/framework.yaml
parameters:
    env(ASYNC_RESULT_PERSIST_DAY_NUM): 7  # Keep results for 7 days
```

### Custom Error Handling

[](#custom-error-handling)

Handle async errors in your client application:

```
if ($response['error']['code'] === -799) {
    $taskId = $response['error']['data']['taskId'];
    // Store taskId for later query
}
```

### Cache Configuration

[](#cache-configuration)

Optimize cache settings for better performance:

```
# config/packages/cache.yaml
framework:
    cache:
        pools:
            cache.app:
                adapter: cache.adapter.redis
                default_lifetime: 3600
```

Documentation
-------------

[](#documentation)

### Async Flow

[](#async-flow)

1. **Method Interception**: Methods with `AsyncExecute` attribute are intercepted by `AsyncExecuteSubscriber`
2. **Task Dispatch**: A unique task ID is generated using Snowflake ID generator
3. **Async Processing**: The task is dispatched to Symfony Messenger for async processing
4. **Result Storage**: Results are persisted in database using `AsyncResult` entity
5. **Result Caching**: Results are cached for faster retrieval
6. **Query Results**: Use `GetAsyncRequestResult` procedure to query task results

### Entities

[](#entities)

- **AsyncResult**: Stores taskId, result content, and creation time
    - Uses Snowflake ID for unique identification
    - Includes automatic cleanup via schedule
    - Cached with configurable TTL

### Configuration

[](#configuration)

- **Environment Variables:**
    - `ASYNC_RESULT_PERSIST_DAY_NUM`: How many days to keep async results (default: 1)
    - `MESSENGER_TRANSPORT_DSN`: Symfony Messenger transport configuration

### Error Codes

[](#error-codes)

- `-799`: Task started successfully, check `taskId` in error data
- `-789`: Task not finished yet, try again later

### Performance Considerations

[](#performance-considerations)

- Results are cached to reduce database queries
- Automatic cleanup prevents database bloat
- Uses Symfony Messenger for reliable async processing

Contributing
------------

[](#contributing)

We welcome contributions! Please follow these guidelines:

1. **Issues**: Report bugs or request features via GitHub Issues
2. **Pull Requests**: Fork the repository and create a pull request
3. **Code Style**: Follow PSR-12 coding standards
4. **Tests**: Ensure all tests pass with `./vendor/bin/phpunit`
5. **Static Analysis**: Run `./vendor/bin/phpstan analyse` to check for issues

### Running Tests

[](#running-tests)

```
# Run all tests
./vendor/bin/phpunit packages/json-rpc-async-bundle/tests

# Run static analysis
php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/json-rpc-async-bundle/
```

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md) for version history and breaking changes.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance77

Regular maintenance activity

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~50 days

Total

12

Last Release

173d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-json-rpc-async-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-json-rpc-async-bundle/health.svg)](https://phpackages.com/packages/tourze-json-rpc-async-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
