PHPackages                             tourze/async-service-call-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. tourze/async-service-call-bundle

ActiveSymfony-bundle

tourze/async-service-call-bundle
================================

Symfony 异步服务调用执行包

v1.0.3(5mo ago)04.2k1MITPHPCI passing

Since Jun 9Pushed 4mo agoCompare

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

READMEChangelog (5)Dependencies (26)Versions (6)Used By (1)

Async Service Call Bundle
=========================

[](#async-service-call-bundle)

[![PHP Version](https://camo.githubusercontent.com/f870cee2a2e2a442c6b62c8bf79f45ec0ce794dc5af13834902518c9107230f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d626c75652e737667)](https://www.php.net)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/4bcd9d6c47aeff7f8ccdf224728fe7ad3c8167d412698f7b702d58ad3c85cd8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f43492f6d6173746572)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/83f9bb21cdd80cfba1e605e63af9b92ee389ca4e847866e98494d2721727c718/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f6d6173746572)](https://codecov.io/gh/tourze/php-monorepo)

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

An asynchronous service call bundle built on Symfony Messenger, supporting complex object parameter serialization and retry mechanisms.

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

[](#table-of-contents)

- [Dependencies](#dependencies)
    - [Package Dependencies](#package-dependencies)
- [Installation](#installation)
- [Quick Start](#quick-start)
    - [1. Register Bundle](#1-register-bundle)
    - [2. Configure Messenger](#2-configure-messenger)
    - [3. Create Service Call Message](#3-create-service-call-message)
- [Features](#features)
    - [Complex Object Parameter Serialization](#complex-object-parameter-serialization)
    - [Retry Mechanism](#retry-mechanism)
    - [Error Handling](#error-handling)
- [Usage Examples](#usage-examples)
    - [Basic Usage](#basic-usage)
    - [Complex Object Parameters](#complex-object-parameters)
    - [Enum Parameters](#enum-parameters)
- [Advanced Usage](#advanced-usage)
    - [Custom Service Call Handler](#custom-service-call-handler)
    - [Advanced Serialization](#advanced-serialization)
    - [Error Handling Strategies](#error-handling-strategies)
- [Configuration Options](#configuration-options)
    - [Service Configuration](#service-configuration)
    - [Custom Serializer](#custom-serializer)
- [Notes](#notes)
- [License](#license)

Dependencies
------------

[](#dependencies)

This package requires:

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- Symfony Messenger component

### Package Dependencies

[](#package-dependencies)

- `tourze/async-contracts`: Provides interface contracts for async operations
- `tourze/doctrine-helper`: Helper utilities for Doctrine integration

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

[](#installation)

```
composer require tourze/async-service-call-bundle
```

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

[](#quick-start)

### 1. Register Bundle

[](#1-register-bundle)

Register in `config/bundles.php`:

```
return [
    // ...
    Tourze\AsyncServiceCallBundle\AsyncServiceCallBundle::class => ['all' => true],
];
```

### 2. Configure Messenger

[](#2-configure-messenger)

Configure in `config/packages/messenger.yaml`:

```
framework:
    messenger:
        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage: async
```

### 3. Create Service Call Message

[](#3-create-service-call-message)

```
use Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage;

$message = new ServiceCallMessage();
$message->setServiceId('my.service.id');
$message->setMethod('processData');
$message->setParams(['param1', 'param2']);
$message->setMaxRetryCount(3);
$message->setRetryCount(3);

// Dispatch to message queue
$messageBus->dispatch($message);
```

Features
--------

[](#features)

### Complex Object Parameter Serialization

[](#complex-object-parameter-serialization)

The bundle includes an advanced serializer that supports:

- Basic data types (string, int, float, bool, array)
- Objects (including Doctrine entities)
- Enum types (BackedEnum)
- DateTime objects

### Retry Mechanism

[](#retry-mechanism)

- Support for setting maximum retry count
- Exponential backoff delay (maximum 1 hour)
- Complete error logging

### Error Handling

[](#error-handling)

- Detailed error logging
- Exception retry support
- Graceful degradation

Usage Examples
--------------

[](#usage-examples)

### Basic Usage

[](#basic-usage)

```
use Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage;
use Symfony\Component\Messenger\MessageBusInterface;

class MyController
{
    public function __construct(
        private MessageBusInterface $messageBus
    ) {}

    public function sendAsyncCall(): void
    {
        $message = new ServiceCallMessage();
        $message->setServiceId('email.service');
        $message->setMethod('sendEmail');
        $message->setParams(['user@example.com', 'Subject', 'Body']);
        $message->setMaxRetryCount(5);
        $message->setRetryCount(5);

        $this->messageBus->dispatch($message);
    }
}
```

### Complex Object Parameters

[](#complex-object-parameters)

```
use Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage;

// Pass entity objects
$user = $entityManager->find(User::class, 1);
$message = new ServiceCallMessage();
$message->setServiceId('user.service');
$message->setMethod('updateProfile');
$message->setParams([$user, ['name' => 'New Name']]);

$this->messageBus->dispatch($message);
```

### Enum Parameters

[](#enum-parameters)

```
enum Status: string
{
    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
}

$message = new ServiceCallMessage();
$message->setServiceId('status.service');
$message->setMethod('updateStatus');
$message->setParams([Status::ACTIVE]);

$this->messageBus->dispatch($message);
```

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

[](#advanced-usage)

### Custom Service Call Handler

[](#custom-service-call-handler)

You can extend the default handler to add custom logic:

```
use Tourze\AsyncServiceCallBundle\MessageHandler\ServiceCallHandler;
use Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage;

class CustomServiceCallHandler extends ServiceCallHandler
{
    public function __invoke(ServiceCallMessage $message): void
    {
        // Custom pre-processing
        $this->logger->info('Processing custom service call');

        // Call parent handler
        parent::__invoke($message);

        // Custom post-processing
        $this->logger->info('Custom service call completed');
    }
}
```

### Advanced Serialization

[](#advanced-serialization)

The bundle provides a custom `ObjectNormalizer` that implements `NormalizerInterface` and `DenormalizerInterface` to handle entity serialization. It automatically converts entities to their IDs during serialization and loads them back during deserialization.

For complex custom objects, you can create your own normalizers:

```
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

class CustomObjectNormalizer implements NormalizerInterface, DenormalizerInterface
{
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
    {
        if ($object instanceof MyCustomObject) {
            return [
                'id' => $object->getId(),
                'data' => $object->serialize(),
            ];
        }

        throw new \InvalidArgumentException('Unsupported object type');
    }

    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
    {
        return $data instanceof MyCustomObject;
    }

    // Implement denormalization methods...
}
```

### Error Handling Strategies

[](#error-handling-strategies)

Configure custom error handling for specific services:

```
use Tourze\AsyncServiceCallBundle\Exception\InvalidParameterException;

try {
    $message = new ServiceCallMessage();
    $message->setParams(['invalid' => new \stdClass()]);
    $messageBus->dispatch($message);
} catch (InvalidParameterException $e) {
    // Handle serialization errors
    $logger->error('Serialization failed', ['error' => $e->getMessage()]);
}
```

Configuration Options
---------------------

[](#configuration-options)

### Service Configuration

[](#service-configuration)

The bundle automatically registers the following services:

- `Tourze\AsyncServiceCallBundle\MessageHandler\ServiceCallHandler`
- `Tourze\AsyncServiceCallBundle\Service\Serializer`

### Custom Serializer

[](#custom-serializer)

If you need custom serialization behavior, you can extend the `Serializer` class:

```
use Tourze\AsyncServiceCallBundle\Service\Serializer;

class MyCustomSerializer extends Serializer
{
    // Custom serialization logic
}
```

Notes
-----

[](#notes)

1. **Parameter Limitations**: Does not support array parameters containing objects
2. **Dependency Injection**: Ensure target services are properly registered in the container
3. **Error Handling**: Configure appropriate log levels for debugging
4. **Performance Considerations**: Complex object serialization may impact performance

License
-------

[](#license)

MIT License

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance72

Regular maintenance activity

Popularity17

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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 ~39 days

Total

5

Last Release

178d ago

Major Versions

0.0.1 → 1.0.02025-11-01

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

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

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

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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