本文介绍了sonataNotificationBundle,电子邮件被存储到数据库中,但 swiftmailer 消费者没有被触发,也没有电子邮件被发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have integrated sonataNotificationBundle, i configured backend to doctrine, emails are getting stored in database notification__message table but are not getting sent.

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

How do I send emails from database using swiftmailer consumer. Below is the configuration

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

The query in log always search for default type even though I mentioned --type=mailer in backend start command

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

In consumer.yml, I have registered SwiftMailerConsumer as an event listener,

    <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 方法中,default"事件被分派,

In MessageManagerBackend->handle method, "default" event is dispatched,

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

下面是日志

[2013-07-12 19:55:16]doctor.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 = ?限制 10 [0,"默认"] []

[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 中进行配置?

Do I need to write different backend for mailer and configure in config.yml like this ?

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

推荐答案

以下是适用于 swiftmailer 消费者的工作 SonataNotificationBundle 配置.无需更改任何其他文件.

Below is the working sonataNotificationBundle configuration for swiftmailer consumer. No need to make changes to any other files.

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

这篇关于sonataNotificationBundle,电子邮件被存储到数据库中,但 swiftmailer 消费者没有被触发,也没有电子邮件被发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 01:03