定制 iviu96afa/yii2-amqp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iviu96afa/yii2-amqp

最新稳定版本:v1.0

Composer 安装命令:

composer require iviu96afa/yii2-amqp

包简介

Yii2 extension enables you to use RabbitMQ with native Yii2 syntax

README 文档

README

Yii2 extension enables you to use RabbitMQ queuing with native Yii2 syntax.

Installation

Via composer

$ php composer.phar require devmustafa/yii2-amqp "dev-master"

Or add

"devmustafa/yii2-amqp": "dev-master"

to the require section of your composer.json file.

Also, add the following

'amqp' => [
	'class' => 'devmustafa\amqp\components\Amqp',
	'host' => '127.0.0.1',
	'port' => 5672,
	'user' => 'username',
	'password' => 'password',
	'vhost' => '/',
],

to the components section of your config.php file.

How to use

1- Sending:

	$exchange = 'exchange';
	$queue = 'queue';
	$dataArray = array('x', 'y', 'z');
	$message = serialize($dataArray);

	Yii::$app->amqp->declareExchange($exchange, $type = 'direct', $passive = false, $durable = true, $auto_delete = false);
	Yii::$app->amqp->declareQueue($queue, $passive = false, $durable = true, $exclusive = false, $auto_delete = false);
	Yii::$app->amqp->bindQueueExchanger($queue, $exchange, $routingKey = $queue);
	Yii::$app->amqp->publish_message($message, $exchange, $routingKey = $queue, $content_type = 'applications/json', $app_id = Yii::$app->name);

2- Receiving:

	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();
	}

统计信息

  • 总下载量: 1.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2014-12-19