{"id":1617,"date":"2022-01-28T17:43:13","date_gmt":"2022-01-28T09:43:13","guid":{"rendered":"https:\/\/www.siediyer.cn\/?p=1617"},"modified":"2022-01-28T17:43:13","modified_gmt":"2022-01-28T09:43:13","slug":"%e5%85%b3%e4%ba%8erabbitmq%ef%bc%9aphp-amqp%e4%bd%bf%e7%94%a8%e8%80%85%ef%bc%9a%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%80%9a%e9%81%93%e9%94%99%e8%af%af%ef%bc%9a404%ef%bc%8c%e6%b6%88%e6%81%af%ef%bc%9anot_found","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1617","title":{"rendered":"\u5173\u4e8eRabbitmq\uff1aPHP AMQP\u4f7f\u7528\u8005\uff1a\u670d\u52a1\u5668\u901a\u9053\u9519\u8bef\uff1a404\uff0c\u6d88\u606f\uff1aNOT_FOUND"},"content":{"rendered":"<h2>PHP AMQP consumer: Server channel error: 404, message: NOT_FOUND<\/h2>\n<div id=\"fc\">\n<p>\u6211\u6b63\u5728pecl 1.0.3\u4e2d\u4f7f\u7528amqp\u6269\u5c55\u540d\uff0c\u8be5\u6269\u5c55\u540d\u4e3a2.7.1 rabbitmq\u3002<\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u4f7f\u57fa\u672c\u7684\u6d88\u8d39\u8005\/\u751f\u4ea7\u8005\u793a\u4f8b\u6b63\u5e38\u5de5\u4f5c\uff0c\u4f46\u662f\u6211\u4e00\u76f4\u5728\u51fa\u9519\u3002 \u8fd9\u4e2a\u6269\u5c55\u540d\u7684PHP\u6587\u6863\u5f88\u5c11\uff0c\u800c\u4e14\u5f88\u591a\u4f3c\u4e4e\u5df2\u7ecf\u8fc7\u65f6\u6216\u9519\u8bef\u3002<\/p>\n<p>\u6211\u4f7f\u7528\u4e86\u7528\u6237\u53d1\u5e03\u7684\u4ee3\u7801\uff0c\u4f46\u4f3c\u4e4e\u65e0\u6cd5\u4f7f\u6d88\u8d39\u8005\u90e8\u5206\u6b63\u5e38\u5de5\u4f5c<\/p>\n<p>\u8fde\u63a5\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function amqp_connection() {\r\n    $amqpConnection = new AMQPConnection();\r\n    $amqpConnection-&gt;setLogin(\"guest\");\r\n    $amqpConnection-&gt;setPassword(\"guest\");\r\n    $amqpConnection-&gt;connect();\r\n\r\n    if(!$amqpConnection-&gt;isConnected()) {\r\n       die(\"Cannot connect to the broker, exiting !\\\r\n\");\r\n    }\r\n\r\n    return $amqpConnection;\r\n}<\/pre>\n<p>\u53d1\u4ef6\u4eba\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function amqp_send($text, $routingKey, $exchangeName){\r\n    $amqpConnection = amqp_connection();\r\n\r\n    $channel = new AMQPChannel($amqpConnection);\r\n    $exchange = new AMQPExchange($channel);\r\n\r\n    $exchange-&gt;setName($exchangeName);\r\n    $exchange-&gt;setType(\"fanout\");\r\n\r\n\r\n    if($message = $exchange-&gt;publish($text, $routingKey)){\r\n       echo\"sent\";\r\n    }\r\n\r\n    if (!$amqpConnection-&gt;disconnect()) {\r\n        throw new Exception(\"Could not disconnect !\");\r\n    }\r\n}<\/pre>\n<p>\u63a5\u6536\u8005\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function amqp_receive($exchangeName, $routingKey, $queueName) {\r\n    $amqpConnection = amqp_connection();\r\n\r\n    $channel = new AMQPChannel($amqpConnection);\r\n    $queue = new AMQPQueue($channel);\r\n    $queue-&gt;setName($queueName);\r\n    $queue-&gt;bind($exchangeName, $routingKey);\r\n\r\n    \/\/Grab the info\r\n    \/\/...\r\n}<\/pre>\n<p>\u7136\u540e\u53d1\u9001\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">amqp_send(\"Abcdefg\",\"action\",\"amq.fanout\");<\/pre>\n<p>\u5e76\u63a5\u6536\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">amqp_receive(\"amq.fanout\",\"action\",\"action\");<\/pre>\n<p>\u6211\u5728\u8fd0\u884c\u811a\u672c\u65f6\u9047\u5230\u95ee\u9898\uff0c\u5e76\u6307\u5411amqp\u63a5\u6536\uff1a<\/p>\n<blockquote><p>PHP Fatal error: Uncaught exception &#8216;AMQPQueueException&#8217; with message &#8216;Server channel error: 404, message: NOT_FOUND &#8211; no queue &#8216;action&#8217; in vhost &#8216;\/&#8221; in \/home\/jamescowhen\/test.php:21<\/p><\/blockquote>\n<p>\u8c01\u80fd\u6307\u51fa\u6211\u6b63\u786e\u7684\u65b9\u5411\uff1f \u6574\u4e2a\u793a\u4f8b\u6765\u81ea\u6b64\u5904\u7684\u7528\u6237\u8bf4\u660e\uff1a<br \/>\nhttp:\/\/www.php.net\/manual\/zh\/amqp.examples.php#109024<\/p>\n<\/div>\n<p>\u8be5\u5f02\u5e38\u4f3c\u4e4e\u662f\u7531\u4e8e\u672a\u58f0\u660e\u60a8\u7684\u961f\u5217\u5f15\u8d77\u7684(\u56e0\u4e3a\u9519\u8bef\u6d88\u606f\u63cf\u8ff0404-\u672a\u627e\u5230\u961f\u5217&#8221;\u64cd\u4f5c&#8221;)\u3002 \u8be5\u793a\u4f8b\u9002\u7528\u4e8e\u539f\u59cb\u6d77\u62a5\u7684\u539f\u56e0\u53ef\u80fd\u662f\u56e0\u4e3a\u4ed6\u5df2\u7ecf\u63d0\u524d\u58f0\u660e\u4e86\u961f\u5217\uff0c\u4f46\u6ca1\u6709\u610f\u8bc6\u5230\u793a\u4f8b\u4e2d\u7f3a\u5c11\u8be5\u961f\u5217\u3002<\/p>\n<p><center><\/center>\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u961f\u5217\u5bf9\u8c61\u4e0a\u8c03\u7528-&gt; declare()\u6765\u58f0\u660e\u961f\u5217\u3002 \u60a8\u8fd8\u5fc5\u987b\u5bf9\u4ea4\u6362\u5bf9\u8c61\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u9664\u975e\u60a8\u5728\u5c1d\u8bd5\u5c06\u961f\u5217\u6302\u63a5\u5230\u4ea4\u6362\u5bf9\u8c61\u65f6\u786e\u5b9a\u5b83\u5df2\u7ecf\u5b58\u5728\u3002<\/p>\n<div id=\"fc\">\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP AMQP consumer: Server channel error: 404, message:  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[118],"class_list":["post-1617","post","type-post","status-publish","format-standard","hentry","category-php","tag-amqp"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1617"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1617\/revisions"}],"predecessor-version":[{"id":1618,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1617\/revisions\/1618"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}