PHP code example of devmustafa / yii2-amqp

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

    

devmustafa / yii2-amqp example snippets


$ php composer.phar 

	set_time_limit(0);
	error_reporting(E_ALL);

	use devmustafa\amqp\PhpAmqpLib\Connection\AMQPConnection;

	$exchange = 'exchange';
	$queue = 'queue';
	$consumer_tag = 'consumer_1';

	$conn = new AMQPConnection('localhost', 5672, 'username', 'password', '/');
	$ch = $conn->channel();
	$ch->exchange_declare($exchange, 'direct', false, true, false);
	$ch->queue_bind($queue, $exchange);

	function process_message($msg) {
		$body = unserialize($msg->body);
	}

	$ch->basic_consume($queue, $consumer_tag, false, false, false, false, 'process_message');

	function shutdown($ch, $conn) {
		$ch->close();
		$conn->close();
	}

	register_shutdown_function('shutdown', $ch, $conn);

	// Loop as long as the channel has callbacks registered
	while (count($ch->callbacks)) {
		$ch->wait();
	}