PHP code example of g4 / messenger

1. Go to this page and download the library: Download g4/messenger 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/ */

    

g4 / messenger example snippets


 

// create \PDO object with your db params
$pdo = new \PDO('mysql:dbname=db;host=127.0.0.1:3306', 'root', '1234');

// publish singe message to RabbitMq with your RabbitMq params
(new \G4\Messenger\RabbitMQ\RabbitMq(
    'your_exchange',
    'your_binding',
    $pdo
))->sendMessage(['foo' => 'baz']);

// publish bulk messages to RabbitMq with your RabbitMq params
(new \G4\Messenger\RabbitMQ\RabbitMq(
    'your_exchange',
    'your_binding',
    $pdo
))->sendMessageBulk(
    [
        ['foo1' => 'baz1'],
        ['foo2' => 'baz2'],
        ['foo3' => 'baz3'],
    ]
);


// create your AMQP connection based on your params
$connection =  new PhpAmqpLib\Connection\AMQPStreamConnection(
      'localhost',
       '5672',
       'guest',
       'guest'
);

// restore your undelivered message from db and put them back to RBMQ
(new \G4\Messenger\Messenger\Messenger(
    $pdo,
    $connection
))->restoreMessages();