Connection: AMQPConnection first look at the server's existing link rabbitmqctl. The bat-qlist_connections is displayed as the air line below the code and then view the link connect. php? Php $ connectnewAMQPConnection (); $ connect-connect (); while (true) {} rabbitmqctl. bat-qlist_connections now serves
Connection: AMQPConnection first check the existing Server link rabbitmqctl. bat-q list_connections. It is displayed as null. Run the following code and check the link connect. php? Php $ connect = new AMQPConnection (); $ connect-connect (); while (true) {} rabbitmqctl. bat-q list_connections services
Connection: AMQPConnection
Check the existing connection of the server.
Rabbitmqctl. bat-q list_connections is blank
Run the following code and check the link.
Connect. php
connect();while (true) { }
Rabbitmqctl. bat-q list_connections current server Link
Channel: AMQPChannel
Rabbitmqctl. bat-q list_channels is blank
Run the Code channel. php.
connect();$channel = new AMQPChannel($connect);while (true) { }
Rabbitmqctl. bat-q list_channels:
Switch: Exchange
Rabbitmqctl. bat-q list_exchanges:
Run exchange. php
connect();$channel = new AMQPChannel($connect);$exchange = new AMQPExchange($channel);$exchange->setName('exchange_name');$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declare();while (true) { }
Rabbitmqctl. bat-q list_exchanges:
If the queue service is not restarted, The exchange_name switch will always exist.
Queue: AMQPQueue
Rabbitmqctl. bat-q list_queues:
Run queue. php In cmd.
connect();$channel = new AMQPChannel($connect);$exchange = new AMQPExchange($channel);$exchange->setName('exchange_name');$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declare();$queue = new AMQPQueue($channel);$queue->setName('queue_name');$queue->declare();while (true) { }
Run rabbitmqctl. bat-q list_queues.
Bind & routing_key
Rabbitmqctl. bat-q list_bindings:
Run the following php code bind. php:
connect();$channel = new AMQPChannel($connect);$exchange = new AMQPExchange($channel);$exchange->setName('exchange_name');$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declare();$queue = new AMQPQueue($channel);$queue->setName('queue_name');$queue->declare();$queue->bind('exchange_name', 'routing_key');while (true) { }
Run rabbitmqctl. bat-q list_bindings again.
Information: Envelope
Next we will change the above bind. php to an acceptor (Information processing end)
connect();$channel = new AMQPChannel($connect);$exchange = new AMQPExchange($channel);$exchange->setName('exchange_name');$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declare();$queue = new AMQPQueue($channel);$queue->setName('queue_name');$queue->declare();$queue->bind('exchange_name', 'routing_key');while (true) { $queue->consume('functionName');}function functionName($envelope,$queue) { var_dump($envelope->getBody());}
Run the following in dos:
Let's write another sender, envelope. php.
connect();$channel = new AMQPChannel($connect);$exchange = new AMQPExchange($channel);$exchange->setName('exchange_name');$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declare();$exchange->publish('hello world','routing_key');$connect->disconnect();
After running envelope. php, you can see that the receiving end has received the message.