PHP code example of takatost / php-pubsub-cmq

1. Go to this page and download the library: Download takatost/php-pubsub-cmq 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/ */

    

takatost / php-pubsub-cmq example snippets


$config = [
    'secret_key' => '',
    'secret_id'  => '',
    'queue_end_point'  => 'https://cmq-queue-sh.api.qcloud.com/v2/index.php',
    'topic_end_point'  => 'https://cmq-topic-sh.api.qcloud.com/v2/index.php',
    'options'    => [
        'debug'   => false,
        'timeout' => 10,
    ]
];

$adapter = new \Takatost\PubSub\CMQ\CMQPubSubAdapter($config);

// consume messages
// note: this is a blocking call
$adapter->subscribe('topic_queue_name', function ($message) {
    var_dump($message);
});

// publish messages
$adapter->publish('topic_name', 'HELLO WORLD');
$adapter->publish('topic_name', json_encode(['hello' => 'world']));
$adapter->publish('topic_name', 1);
$adapter->publish('topic_name', false);
bash
composer