PHP中使用AMQP訊息佇列
阿新 • • 發佈:2019-01-03
'password'=> 'guest','vhost' =>'/');
$conn = new AMQPConnection($conn_args);
$conn->connect();
//建立exchange名稱和型別
$channel = new AMQPChannel($conn);
$ex = new AMQPExchange($channel);
$ex->setName('direct_exchange_name');
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE | AMQP_AUTODELETE );
$ex->declare();
//建立queue名稱,使用exchange,繫結routingkey
$q = new AMQPQueue($channel);
$q->setName('queue_name');
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
$q->declare();
$q->bind('direct_exchange_name', 'routingkey_name');
//訊息釋出
$channel->startTransaction();
$message = json_encode(array('Hello World!' ,'DIRECT'));
$conn = new AMQPConnection($conn_args);
$conn->connect();
//建立exchange名稱和型別
$channel = new AMQPChannel($conn);
$ex = new AMQPExchange($channel);
$ex->setName('direct_exchange_name');
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE | AMQP_AUTODELETE
$ex->declare();
//建立queue名稱,使用exchange,繫結routingkey
$q = new AMQPQueue($channel);
$q->setName('queue_name');
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
$q->declare();
$q->bind('direct_exchange_name', 'routingkey_name');
//訊息釋出
$channel->startTransaction();
$message = json_encode(array('Hello World!'