1 fanout类型工作原理

fanout类型的Exchange路由规则非常简单,它会把所有发送到该Exchange的消息路由到所有与它绑定的Queue中:
当生成者将消息投递到exchange_fanout_clevercode。交互机exchange_fanout_clevercode将会将消息分别投递到和他绑定的queue_fanout_clevercode1,queue_fanout_clevercode2,queue_fanout_clevercode3三个队列中。
2 PHP样例代码
2.1 消费者进程
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPConnection;
//连接
$host = '127.0.0.1';//ip
$port = '5672';//端口
$user = 'guest'; //用户
$password = 'guest'; //密码
$vhost = '/'; //空间
$connection = new AMQPConnection($host, $port,$user, $password,$vhost);
$channel = $connection->channel();
/*
name: 交换机名字
type: 交换机类型
passive: false
durable: true // 交换机将在服务器重启后生存。
auto_delete: false //通道关闭的时候,交换机不会被删除
*/
$channel->exchange_declare('exchange_fanout_clevercode'

最低0.47元/天 解锁文章
893

被折叠的 条评论
为什么被折叠?



