PHP code example of vu / zf2-amqp-carapace

1. Go to this page and download the library: Download vu/zf2-amqp-carapace 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/ */

    

vu / zf2-amqp-carapace example snippets


'AMQPCarapace' => [
    'connection' => [
        'connection_rabbit' => [
            'host'     => '0.0.0.0',
            'port'     => 0000,
            'user'     => 'username',
            'password' => 'password',
        ]
    ],
    'transport' => [
        'php_exchange' => [
            'exchange' => 'php_exchange',
            'routing_key' => 'php_test',
        ],
        'other_exchange' => [
            'exchange' => 'other_php_exchange',
            'routing_key' => 'rawr'
        ]
    ],
    'message' => [
        'text/plain' => [
            'content_type' => 'text/plain',
            'content_encoding' => 'UTF-8',
        ],
        'json' => [
            'content_type' => 'application/json',
            'content_encoding' => 'UTF-8'
        ]
    ],
    'application' => [
        //Every application config MUST 

//Easiest way using predefined application settings
$publisher_factory = new Vu\Zf2AMQPCarapace\Publisher\PublisherFactory();
$myapp_amqp_publisher = $publisher_factory->getPublisher('MyApp');

//You may also create an AMQPPublisher manually using Connection, Transport, and Message objects
$connection_factory = new Vu\Zf2AMQPCarapace\Factory\Connection();
$amqp_connection = $connection_factory->create('connection_rabbit'); //Uses predefined connection config
//Create transport and message objects using Transport and Message factories in the same manner...
//More information on Connection, Transport, and Message factories are listed further down on this page
$manual_amqp_publisher = $publisher_factory->makePublisher($amqp_connection, $amqp_transport, $amqp_message);

//Lastly, you may create an AMQPPublisher by passing in an array of configuration
$config = [
    'connection' => [/* connection settings */],
    'transport' => [/* transport settings */],
    'message' => [/* message settings */]
];
$manual_amqp_publisher = $publisher_factory->makePublisherFromConfiguration($config);

//Publish a single message
$my_first_message = "This will be the first message I publish!";
$myapp_amqp_publisher->basicPublish($my_first_message);
$myapp_amqp_publisher->basicPublish("I also want to publish this message");

//Publish multiple messages
$array_of_strings = [
    "First!",
    "Second...",
    "Tres!!"
];
$myapp_amqp_publisher->batchBasicPublish($array_of_strings);

$publisher_factory->getPublisher('AnotherApp')->basicPublish("Here is my message!");

    $factory->create('config_name');
    

    $factory->createFromArray([/* config settings*/]);