dubture / async-bundle
为Symfony2提供易于使用的异步后端工作抽象
0.0.1
2015-04-18 07:30 UTC
Requires
- jms/di-extra-bundle: ~1.5
Requires (Dev)
- bcc/resque-bundle: ~1.1
- doctrine/dbal: <2.5
- doctrine/doctrine-bundle: ~1.2
- doctrine/orm: ~2.2,>=2.2.3,<2.5
- oldsound/rabbitmq-bundle: ~1.6
- phpunit/phpunit: ~4.5
- sensio/framework-extra-bundle: ~3.0,>=3.0.2
- sonata-project/admin-bundle: ~2.3
- sonata-project/notification-bundle: ~2.3
- symfony/browser-kit: ~2.2
- symfony/finder: ~2.2
- symfony/monolog-bundle: ~2.2
- symfony/swiftmailer-bundle: ~2.3
Suggests
- bcc/resque-bundle: Backend implementation using resque
- oldsound/rabbitmq-bundle: Backend implementation using rabbitmq
- sonata-project/notification-bundle: The sonata-notification bundle provides multiple backends to choose from
This package is not auto-updated.
Last update: 2024-09-14 17:37:18 UTC
README
此Symfony扩展提供了一种将昂贵逻辑发送到后台工作进程的高级方法。
配置
- 使用
composer require "dubture/async-bundle"
安装此扩展包 - 将必要的扩展包添加到您的Kernel
// app/AppKernel.php public function registerBundles() { $bundles = array( // register the async bundle new Dubture\AsyncBundle\DubtureAsyncBundle(), // register the dependencies of the async bundle new JMS\DiExtraBundle\JMSDiExtraBundle($this), new JMS\AopBundle\JMSAopBundle(), // your application bundles here... ); return $bundles; }
- 配置要使用的后端
# app/config/config.yml dubture_async: backend: rabbitmq # one of rabbitmq|resque|sonata|runtime
用法
考虑以下服务
<services> <service class="Acme\Bundle\MediaTranscodingService" id="media_transcoder"> </service> </services>
class MediaTranscodingService { public function transcodeFile($sourcePath) { // ... do some heavy-lifting, e.g. media transcoding } }
如果您想将此方法委托给后台工作进程,这需要您做的一切
use Dubture\AsyncBundle\Annotation\Async; class MediaTranscodingService { /** * @Async */ public function transcodeFile($sourcePath) { // ... do some heavy-lifting, e.g. media transcoding } }
现在对 transcodeFile
的任何调用都将被拦截并委托给后台工作进程。
带有 @Async
注解的方法需要遵循以下约定
- 声明异步方法的类必须是服务
- 方法参数必须是可序列化的(无资源,例如,doctrine连接)
- 方法不应该返回任何内容(任何返回值都将丢失)
如果您需要在后台工作进程内部发生某些事情时做出反应,您可以在完成后简单地派发事件。
后台工作进程实现依赖于以下扩展包之一
- https://github.com/michelsalib/BCCResqueBundle (resque)
- https://github.com/videlalvaro/RabbitMqBundle (rabbitmq)
- https://github.com/sonata-project/SonataNotificationBundle (查看sonata扩展包以获取可用后端)
请参阅 Resources/docs
了解特定后端的文档。