sonataNotificationBundle, emails getting stored to database but swiftmailer consumer is not triggered and no emails are sent

倖福魔咒の 提交于 2020-01-03 04:58:06

问题


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

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

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

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>

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

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

below is the log

[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"] []

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

回答1:


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


来源:https://stackoverflow.com/questions/17615547/sonatanotificationbundle-emails-getting-stored-to-database-but-swiftmailer-cons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!