Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.59 KB

7-messenger-integration.md

File metadata and controls

47 lines (36 loc) · 1.59 KB

Messenger integration

If you have installed Symfony Messenger, then you can dispatch Presta\SitemapBundle\Messenger\DumpSitemapMessage message to your transport to handle it asynchronously or synchronously.

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: "%env(MESSENGER_TRANSPORT_DSN)%"

        routing:
            # async is whatever name you gave your transport above
            'Presta\SitemapBundle\Messenger\DumpSitemapMessage':  async

After configuring the message routing dispatch the message like this:

// src/Controller/DefaultController.php
namespace App\Controller;

use Presta\SitemapBundle\Messenger\DumpSitemapMessage;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Messenger\MessageBusInterface;

class DefaultController extends AbstractController
{
    public function index(MessageBusInterface $bus)
    {
        // this will dispatch to dump all sitemap sections
        $bus->dispatch(new DumpSitemapMessage());

        // If you wish to dump a single section, change the base url, target dir
        // and gzip option you can provide these through the message constructor
        $bus->dispatch(new DumpSitemapMessage('custom_section', 'https://sitemap.acme.org', '/path/to/sitemap', ['gzip' => true]));
    }
}

« Dumping sitemapREADME »