PHP code example of braincrafted / mq-bundle

1. Go to this page and download the library: Download braincrafted/mq-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

braincrafted / mq-bundle example snippets


// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Braincrafted\Bundle\MqBundle\BraincraftedMqBundle()
    );

    // ...

    return $bundles;
}


// src/Braincrafted/Bundle/MqDemoBundle/Consumer/WriteFileConsumer.php

namespace Braincrafted\Bundle\MqDemoBundle\Consumer;

class WriteFileConsumer
{
    private $filename;

    public function __construct($filename)
    {
        $this->filename = $filename;
    }

    public function consume($message)
    {
        file_put_contents($this->filename, $message."\n", FILE_APPEND);
    }
}

$producer = $container->get('braincrafted_mq.producer');
$producer->produce('write_file', 'Hello World!');

$producer = $container->get('braincrafted_mq.producer');
$producer->produce('write_file', array('text' => 'Hello World!', 'time' => time());