0

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

如何使用 swiftmailer 消费者从数据库发送电子邮件。下面是配置

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->handle 方法中,调度“默认”事件,

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

下面是日志

[2013-07-12 19:55:16] 学说.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 = ? 和 t0.type = ? 限制 10 [0,“默认”] []

我是否需要为邮件程序编写不同的后端并像这样在 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
4

1 回答 1

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
于 2013-08-06T12:34:11.470 回答