sonataNotificationBundle,电子邮件存储到数据库但没有触发swiftmailer消费者,也没有发送电子邮件

时间:2013-07-12 13:02:15

标签: php symfony symfony-sonata

我已经集成了sonataNotificationBundle,我将后端配置为doctrine,电子邮件存储在数据库notification__message表中,但没有被发送。

如何使用swiftmailer consumer从数据库发送电子邮件。以下是配置

sonata_notification:
    backend: sonata.notification.backend.doctrine
    backends:
        doctrine:
            message_manager: sonata.notification.manager.message.default
            max_age:         86400     # max age in second
            pause:           500000    # delay in microseconds
            states:                    # raising errors level
                in_progress: 10
                error:       20
                open:        100
                done:        10000

日志中的查询总是搜索默认类型,即使我在后端启动命令中提到了--type = mailer

在consumer.yml中,我已将SwiftMailerConsumer注册为事件监听器,

    <service id="sonata.notification.consumer.swift_mailer" class="Sonata\NotificationBundle\Consumer\SwiftMailerConsumer">
        <tag name="sonata.notification.consumer" type="mailer" />
        <tag name="sonata.notification.consumer.event_listener" event="default" method="process" />
        <argument type="service" id="mailer" />
    </service>

在MessageManagerBackend-&gt; handle方法中,调度“default”事件,

 $dispatcher->dispatch($message->getType(), $event);

下面是日志

[2013-07-12 19:55:16] doctrine.DEBUG:SELECT t0.type AS type1,t0.body AS body2,t0.state AS state3,t0.restart_count AS restart_count4,t0.created_at AS created_at5, t0.updated_at AS updated_at6,t0.started_at AS started_at7,t0.completed_at AS completed_at8,t0.id AS id9 FROM notification__message t0 WHERE t0.state =? AND t0.type =? LIMIT 10 [0,“default”] []

我是否需要为邮件程序编写不同的后端,并在config.yml中进行配置?

sonata_notification:
    backend: sonata.notification.backend.doctrine
    consumer:
        swift_mailer:
            path:         %kernel.root_dir%/../vendor/swiftmailer
    backends:
        doctrine:
            message_manager: sonata.notification.manager.message.mailer

1 个答案:

答案 0 :(得分:0)

以下是swiftmailer使用者的工作sonataNotificationBundle配置。无需更改任何其他文件。

sonata_notification:
    backend: sonata.notification.backend.doctrine
    queues:
        - { queue: mailer, routing_key: mailer }
        - { queue: catchall, default: true }
    backends:
        doctrine:
            message_manager: sonata.notification.manager.message.default
            max_age:         86400     # max age in second
            pause:           500000    # delay in microseconds
            states:                    # raising errors level
                in_progress: 10
                error:       20
                open:        100
                done:        10000