{"id":27076,"date":"2024-11-24T18:47:42","date_gmt":"2024-11-24T10:47:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=27076"},"modified":"2024-11-24T18:47:42","modified_gmt":"2024-11-24T10:47:42","slug":"php%e4%b8%ad%e7%9a%84amqp%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27076\/","title":{"rendered":"PHP\u4e2d\u7684AMQP\u7c7b"},"content":{"rendered":"<p>\u4e00\u5b9a\u8981\u6ce8\u610fphp\u5b89\u88c5AMQP\u7684\u7248\u672c\uff0c\u7248\u672c\u4e0d\u540c\u4f7f\u7528\u7684\u65b9\u6cd5\u4e0d\u4e00\u6837\u3002\u5728\u5b98\u65b9\u7f51\u7ad9\u5c31\u67092\u4e2a\u7248\u672c\u7684AMQP<br \/>\n\u5343\u4e07\u4e0d\u8981\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u627e\u5230\u4e00\u4e2a\u5b98\u65b9\u7684\u7248\u672c\uff0c\u7136\u540e\u6309\u7167example\uff0c\u600e\u4e48\u8c03\u8bd5\u90fd\u4e0d\u901a\u2026.\u6309\u7167PHP\u5b89\u88c5 AMQP\u6269\u5c55\u00a0\u5b89\u88c5\u7684AMQP\u6269\u5c55\u662f\u6700\u65b0\u7684\uff0c\u73b0\u5728\u548cPHP\u5b98\u65b9\u7ed9\u51fa\u7684\u7b2c\u4e8c\u7248\u672c\uff0c\u4e5f\u6709\u4e00\u4e9b\u533a\u522b\u3002\u4e3b\u8981\u4f53\u73b0\u5728exchange\u548cqueue\u4e2d\u6709\u4e2adeclare\u7684\u65b9\u6cd5\uff0c\u5206\u522b\u66f4\u6539\u6210declarExchange()\u548cdeclarQueue().<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e00\u3001AMQPConnection<\/h2>\n<p><strong>::__construct ([ array $credentials = array() ] )<\/strong><\/p>\n<p>\u8fd9\u65b9\u6cd5\u6bd4\u8f83\u7b80\u5355\uff0c<strong>credentials<\/strong>\u7684\u82f1\u6587\u542b\u4e49\u662f\u201c\u51ed\u8bc1\u201d\uff0c\u4f46\u6211\u559c\u6b22\u628a\u5b83\u7406\u89e3\u4e3aconfig\u3002\u8fd9\u4e9b\u914d\u7f6e\u5305\u62ec\u5982\u4e0b\uff1a<br \/>\nhost\u3001vhost\u3001port\u3001login\u3001password\u3001read_timeout\u3001write_timeout\u3001connect_timeout\uff0c\u5982\u679cconfig\u7701\u7565\uff0cphp\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u7684\u8fd95\u4e2a\u503c\uff0c\u521d\u59cb\u5316\uff0c\u5f3a\u70c8\u5efa\u8bae\u5e26\u4e0aconfig\u521d\u59cb\u5316\uff0c\u5176\u4e2dread_timeout\u3001write_timeout\u3001connect_timeout\u8fd9\u4e09\u4e2a\u503c\u662f\u6700\u65b0\u7248\u672c\u624d\u6709\u7684\uff0cPHP\u5b98\u65b9\u73b0\u5728\u8fd8\u6ca1\u6709\uff0c\u5355\u4f4d\u90fd\u662f(\u79d2)<\/p>\n<p><strong>::connect ( void )\u00a0 \u3001\u00a0 ::pconnect ( void )<br \/>\n::disconnect ( void )\u00a0\u00a0 \u3001::pdisconnect ( void )<br \/>\n::reconnect ( void ) \u3001::preconnect ( void )\u00a0\u00a0<\/strong>\u00a0#\u6ce8\u610f\u548c__construct \u7684\u533a\u522b\uff0c\u8be5\u65b9\u6cd5\u4e0d\u5e26\u53c2\u6570\u3002<br \/>\n<strong>::isConnected ( void )<br \/>\n::isPersistent ( void )\u00a0<\/strong>#\u662f\u5426\u6301\u4e45\u94fe\u63a5<strong>\u00a0\uff0c<\/strong>\u4e3a\u4ec0\u4e48\u4e0d\u662fisPconnected \uff1f-_-<strong><br \/>\n<\/strong><\/p>\n<p>\u5982\u679c\u4f7f\u7528\u6301\u4e45\u94fe\u63a5\uff0c\u5728\u7c7b\u65b9\u6cd5__destruct\u4e2d\u91ca\u653e(\u65ad\u5f00\u94fe\u63a5)<\/p>\n<p><strong>::setHost ( string $host )<br \/>\n::setPort ( int $port )<br \/>\n::setVhost ( string $vhost )<br \/>\n::setLogin ( string $login )<br \/>\n::setPassword ( string $password )<br \/>\n::getHost ( void )<br \/>\n::getPort ( void )<br \/>\n::getVhost ( void )<br \/>\n::getLogin ( void )<br \/>\n::getPassword ( void )<br \/>\n\u8fd8\u6709\u7c7b\u4f3c\u7684::setTimeout ( int $timeout ) \u3001::getTime ( void )\u3001::getReadTimeout ( void )\u3001::setReadTimeout ( int $timeout )\u3001::getWriteTimeout (void ) \u3001setWriteTimeout ( int $timeout)<br \/>\n<\/strong><\/p>\n<p>\u4e0a\u9762\u7684\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5c31\u4e0d\u7ec6\u8bf4\u4e86\uff0c\u8fd8\u67092\u4e2a\u4e0d\u5e38\u89c1\u7684\u65b9\u6cd5<\/p>\n<p><strong>::getUsedChannels ( void )<\/strong>\u00a0 #\u5728\u94fe\u63a5\u4f1a\u8bdd\u671f\u95f4\u6700\u540e\u4e00\u6b21\u4f7f\u7528\u7684channel id<br \/>\n<strong>::getMaxChannels ( void )\u00a0<\/strong>\u00a0 #\u5355\u6b21\u94fe\u63a5\u80fd\u521b\u5efa\u6700\u5927channel\u6570\u91cf<\/p>\n<h2>\u4e8c\u3001AMQPChannel<\/h2>\n<p>\u4e3a\u4e86\u4e00\u4e2aAMQP\u7684\u94fe\u63a5\uff0c\u521b\u5efa\u4e00\u4e2achannel instance\uff08\u901a\u9053\u5b9e\u4f8b\uff09\uff0c\u8fd9\u91cc\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u51e0\u4e2a\u6982\u5ff5\uff0c\u4ee5\u53ca\u5979\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u672c\u4eba\u505a\u4e86\u4e00\u4e2a\u7f57\u5217\uff0c\u6c34\u5e73\u6709\u9650\uff0c\u4e0d\u5bf9\u7684\u5730\u65b9\u8bf7\u6307\u6b63\u3002<\/p>\n<pre><strong>client<\/strong> \uff1a\u5ba2\u6237\u7aef\r\n<strong>Broker<\/strong>\uff1a\u82f1\u6587\u542b\u4e49\u662f\u4ee3\u7406\uff0c\u8fd9\u91cc\u6307\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4e5f\u662f\u901a\u5e38\u8bf4\u7684server\uff0c\u4e5f\u53ef\u4ee5\u6307Rabbit cluster\u7684\u8282\u70b9\uff0c\r\n\u4e5f\u5c31\u662f\u5728AMQPConnection\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684host\u3001port\r\n<strong>virtual_host\uff1a<\/strong>\u865a\u62dfhost\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u7406\u89e3\u4e3a\u5728Broker\u4e2d\uff0c\u865a\u62df\u51fa\u6765\u7684\u6d88\u606f\u5904\u7406\u6a21\u5757\u3002\u4e00\u4e2aBroker\u4e2d\r\n\u53ef\u4ee5\u521b\u5efa\u591a\u4e2avirtual_host.\r\n<strong>exchange\uff1a<\/strong>\u903b\u8f91\u4e0a\u5c5e\u4e8evirtual_host\u7684\u5b50\u6a21\u5757\uff0c\u8d1f\u8d23\u6d88\u606f\u8f6c\u53d1\u5230queue\u4e2d\u3002\r\n<strong>queue\uff1a<\/strong>\u903b\u8f91\u4e0a\u5c5e\u4e8evirtual_host\u7684\u5b50\u6a21\u5757\u3002\r\n<strong>channel\uff1a<\/strong>\u901a\u9053\u3002\u94fe\u63a5virtual_host\u7684\u901a\u9053\u3002\r\nroutingkey\uff1a\r\n\r\n<strong>virtual_host\u548cchannel<\/strong>\u7684\u8bbe\u7f6e\u90fd\u662f\u4e3a\u4e86\u589e\u52a0\u5e76\u53d1\u6027\u80fd\uff0c\u964d\u4f4e\u8d44\u6e90\u6d88\u8017\u7684\u3002\r\n\u53c2\u8003\u6587\u7ae0\uff1aRabbitMQ\u4e2d\u7684AMQP\u534f\u8bae\u89c4\u8303<\/pre>\n<p><strong>::__construct ( AMQPConnection $amqp_connection ) \uff03\u521b\u5efachannel<br \/>\n::isConnected ( void )\u00a0<\/strong>\uff03\u8fd9\u91cc\u548cAMQPConnection::isConnected\u4e00\u6837.<strong><br \/>\n<\/strong><\/p>\n<p><strong>::getConnection ( void )<br \/>\n<\/strong>\uff03\u8fd4\u56de\u7684\u7ed3\u679c\u662fAMQPConnection\uff0c\u4ece\u6982\u5ff5\u4e0a\u4e2a\u4eba\u7406\u89e3\uff0cchannel\u662f\u5efa\u7acb\u5728connection\u4e4b\u4e0a\u7684\uff0c\u662f\u4e2a\u72ec\u7acb\u7684\u94fe\u63a5\u3002connection\u662f\u6307\u7269\u7406\u7684\u8fde\u63a5\uff0c\u4e00\u4e2aclient\u4e0e\u4e00\u4e2aserver\u4e4b\u95f4\u6709\u4e00\u4e2a\u8fde\u63a5\uff1b\u4e00\u4e2a\u8fde\u63a5\u4e0a\u53ef\u4ee5\u5efa\u7acb\u591a\u4e2achannel\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u903b\u8f91\u4e0a\u7684\u8fde\u63a5\u3002\u4e00\u822c\u5e94\u7528\u7684\u60c5\u51b5\u4e0b\uff0c\u6709\u4e00\u4e2achannel\u5c31\u591f\u7528\u4e86\uff0c\u4e0d\u9700\u8981\u521b\u5efa\u66f4\u591a\u7684channel<\/p>\n<p><strong>::getChannelId ( void )<br \/>\n<\/strong>\uff03\u8fd4\u56dechannel id\uff0c\u5728PHP\u4e2d\u5faa\u73af\u521b\u5efa\u901a\u9053\uff0c\u53d1\u73b0\u901a\u9053ID\u59cb\u7ec8\u53ea\u67091\u548c2\uff0c\u4e0d\u77e5\u662f\u5426\u548c\u670d\u52a1\u5668\u7684\u8bbe\u7f6e\u6709\u5173\uff1f<strong><br \/>\n<\/strong><\/p>\n<p><strong>::setPrefetchSize ( int $size )\u3001::getPrefetchSize ( void )<\/strong><br \/>\n\u8fd9\u4e2a\u5730\u65b9\u6709\u4e2a\u5751\uff0c\u8bbe\u7f6eprefetchSize\u4e0d\u7b49\u4e8e0\uff0c\u4f1a\u63d0\u793anot_implemented: \u201cprefetch_size!=0 (65535)\u201d\uff0c\u4e5f\u5c31\u662f\u8bf4\u76ee\u524dprefetchSize\u53ea\u80fd\u8bbe\u7f6e\u4e3a0\uff0c\u8fd8\u672a\u5b9e\u73b0\u4e0d\u7b49\u4e8e0\u7684\u60c5\u51b5\u3002<\/p>\n<p><strong>::setPrefetchCount ( int $count )\u3001::getPrefetchCount ( void )<\/strong><br \/>\n\u8fd9\u4e2a\u53c2\u6570\u8bbe\u7f6e\uff0c\u63a5\u6536\u6d88\u606f\u7aef\uff0c\u63a5\u6536\u7684\u6700\u5927\u6d88\u606f\u6570\u91cf\uff08\u5305\u62ec\u4f7f\u7528get\u3001consume\uff09,\u4e00\u65e6\u5230\u8fbe\u8fd9\u4e2a\u6570\u91cf\uff0c\u5ba2\u6237\u7aef\u4e0d\u5728\u63a5\u6536\u6d88\u606f\u30020\u4e3a\u4e0d\u9650\u5236\u3002\u9ed8\u8ba4\u503c\u4e3a3.<\/p>\n<p><strong>::qos ( int $size , int $count )<\/strong><br \/>\n\u540c\u65f6\u8bbe\u7f6eprefetchSize\u3001prefetchCount\uff0c\u4f46prefetchSize\u76ee\u524d\u53ea\u80fd\u8bbe\u7f6e\u4e3a0<\/p>\n<p><strong>\u00a0::basicRecover ( boolen )<\/strong><br \/>\n\u9ed8\u8ba4\u4e3atrue\uff0c\u6ca1\u6709\u786e\u8ba4\u7684\u6d88\u606f\u4f1a\u88ab\u518d\u6b21\u6295\u9012\uff0c\u8fd9\u4e2a\u5730\u65b9\u548c\u6d88\u606f\u786e\u8ba4\u673a\u5236\u6709\u5173\uff0c\u540e\u9762\u518d\u6765\u8bf4\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<h2>\u4e09\u3001\u00a0AMQPExchange<\/h2>\n<p><strong>::__construct ( AMQPChannel $amqp_channel )<\/strong><\/p>\n<p><strong>::setName ( string $exchange_name )\u3001::getName ( void )<\/strong><br \/>\n\u8fd9\u4e2a\u547d\u4ee4\u7684\u6700\u597d\u4f7f\u7528\u6570\u5b57\u3001\u5b57\u6bcd\u3001- _ . \u7ec4\u5408(\u533a\u5206\u5927\u5c0f\u5199\uff0c\u4f46\u6700\u597d\u4f7f\u7528\u5c0f\u5199)<br \/>\n\u4e5f\u4e0d\u8981\u4f7f\u7528amq\u5e26\u5934\uff08\u5185\u7f6e\u7684exchange\u90fd\u662f\u4f7f\u7528amq.\u5f00\u5934\uff09<br \/>\n\u5982\u679c\u7533\u660e\u4e00\u4e2a\u5df2\u5b58\u5728\u7684exchange name\uff0c\u5982\u679ctype\u4e0d\u4e00\u81f4\u4f1a\u629b\u51fa\u5f02\u5e38.<\/p>\n<p><strong>::setType ( string $exchange_type )\u3001::getType ( void )<\/strong><br \/>\n<strong>\u8fd9\u4e2a\u662frabbitmq\u7684\u6838\u5fc3\uff0cexchange\u7684\u7c7b\u578b\uff0c\u51b3\u5b9a\u4e86rabbit\u5b9e\u73b0\u4f55\u79cd\u4e1a\u52a1\u6a21\u578b\u3002<\/strong><br \/>\n\u8fd9\u4e2a\u5730\u65b9\u5c24\u5176\u8981\u6ce8\u610f\uff0cAMQ\u672c\u8eab\u6ca1\u6709\u9ed8\u8ba4\u7684exchangeType\uff0c\u6240\u4ee5\u5728\u7533\u660eexchange\u5fc5\u9700\u8981\u8bbe\u7f6etype\uff0c\u5426\u5219\u4f1a\u629b\u51fa\u5f02\u5e38 Could not declare exchange. Exchanges must have a type\uff0c<br \/>\n\u76ee\u524dexchange\u652f\u63014\u79cd\u7c7b\u578b\u00a0 AMQP_EX_TYPE_DIRECT\u3001 AMQP_EX_TYPE_FANOUT\u3001AMQP_EX_TYPE_HEADERS \u3001 AMQP_EX_TYPE_TOPIC<br \/>\n\u53ef\u53c2\u8003\uff1aRabbitMQ AMQP \u6d88\u606f\u6a21\u578b\u653b\u7565<br \/>\n\u8bb0\u5fc6\u65b9\u6cd5\uff1aamqp_exchange_type_direct\u3001fanout\u3001topic\u3001headers<\/p>\n<p><strong>\u00a0::setFlags ( int $flags )\u3001::getFlags ( void )<\/strong><br \/>\n\u9ed8\u8ba4AMQP_NOPARAM\uff1b \u53ef\u9009AMQP_DURABLE, AMQP_PASSIVE\u3001AMQP_AUTODELETE<\/p>\n<ol>\n<li>passive\uff1a\u58f0\u660e\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u4ea4\u6362\u5668\u7684\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5c06\u629b\u51fa\u5f02\u5e38\uff0c\u8fd9\u4e2a\u4e00\u822c\u7528\u5728consume\u7aef\u3002\u56e0\u4e3a\u4e00\u822cproduce\u7aef\u521b\u5efa,\u5728consume\u7aef\u5efa\u8bae\u8bbe\u7f6e\u6210AMQP_PASSIVE,\u9632\u6b62consume\u521b\u5efaexchange<\/li>\n<li>durable\uff1a\u6301\u4e45exchange\uff0c\u8be5\u4ea4\u6362\u5668\u5c06\u5728broker\u91cd\u542f\u540e\u751f\u6548\uff0c\u4e00\u822c\u5e38\u4f7f\u7528\u8be5\u9009\u9879.<\/li>\n<li>auto_delete\uff1a\u8be5\u4ea4\u6362\u5668\u5c06\u5728\u6ca1\u6709\u6d88\u606f\u961f\u5217\u7ed1\u5b9a\u65f6\u81ea\u52a8\u5220\u9664\u3002\u4e00\u4e2a\u4ece\u672a\u7ed1\u5b9a\u4efb\u4f55\u961f\u5217\u7684\u4ea4\u6362\u5668\u4e0d\u4f1a\u81ea\u52a8\u5220\u9664\u3002\u89e3\u91ca\u6709\u70b9\u7ed5\u3002\u8bf4\u660e\u4e0b\u5427\uff0c\u5f53\u6709\u961f\u5217bind\u5230auto_delete\u7684\u4ea4\u6362\u5668\u4e0a\u4e4b\u540e\uff0c\u5220\u9664\u8be5\u961f\u5217\u3002\u6b64\u65f6\u4ea4\u6362\u5668\u4e5f\u4f1a\u5220\u9664\u3002\u4e00\u822c\u521b\u5efa\u4e3a\u4e34\u65f6\u4ea4\u6362\u5668\u3002<\/li>\n<\/ol>\n<p><strong>::setArgument ( string $key , mixed $value )<\/strong><br \/>\n<strong>::setArguments ( array $arguments )<\/strong><br \/>\n<strong>::getArgument ( string $key )<\/strong><br \/>\n<strong>::getArguments ( void )<\/strong><\/p>\n<p><strong>::declareExchange( void ) \/\/\u548cPHP\u7684\u5b98\u65b9\u6709\u5dee\u522b<br \/>\n<\/strong><\/p>\n<p><strong>::delete ($exchangeName = null, $flags = AMQP_NOPARAM) \/\/\u548cPHP\u7684\u5b98\u65b9\u6709\u5dee\u522b<br \/>\n<\/strong>\u672a\u6307\u5b9a$exchangeName\uff0c\u5220\u9664\u5f53\u524d\u94fe\u63a5\u7684exchange<strong>\uff0c<\/strong>\u4f46\u65e0\u6cd5\u5220\u9664system\u4e2d\u5185\u7f6e\u7684exchange.<\/p>\n<p><strong>::bind($exchange_name, $routing_key = \u201d, array $arguments = array())\u00a0\u00a0\/\/\u548cPHP\u7684\u5b98\u65b9\u6709\u5dee\u522b<\/strong><br \/>\n<strong>::unbind($exchange_name, $routing_key = \u201d, array $arguments = array())\u00a0\u00a0\/\/\u548cPHP\u7684\u5b98\u65b9\u6709\u5dee\u522b<br \/>\n<\/strong>\u53ef\u4ee5\u5c06\u6d88\u606f\u540c\u65f6\u53d1\u9001\u5230\u591a\u4e2aexchange\uff0c\u7a0d\u540e\u8865\u5145\u5b9e\u9645\u7684\u7528\u6cd5\u3002<strong><br \/>\n<\/strong><\/p>\n<p><strong>::publish ( string $message , string $routing_key [, int $flags = AMQP_NOPARAM [, array $attributes = array() ]] ) \/\/\u53d1\u9001\u6d88\u606f\u65b9\u6cd5 $attributes\u53c2\u8003\uff1aRabbitMQ\u7684PHP\u6559\u7a0b\u4e4bRPC (\u516d)<br \/>\n<\/strong><\/p>\n<p>\u53c2\u6570\uff1a$routint_key\uff0c\u5728fanout\u4e0b\u5ffd\u7565\u3002\u5728direct\u7c7b\u578b\u4e0b\uff0c\u5982\u679c\u8be5\u503c\u4e3a\u7a7a\uff0c\u5219bind\u5230exchange\u90fd\u80fd\u6536\u5230\u6d88\u606f\uff0c\u8fd9\u4e2a\u6709\u70b9\u50cffanout\u7684\u5e7f\u64ad\u6a21\u5f0f\u3002<\/p>\n<p>\u53c2\u6570\uff1a$flags\u53ef\u9009\u503c AMQP_MANDATORY\u3001AMQP_IMMEDIATE,\u9ed8\u8ba4\uff1aAMQP_NOPARAM\uff0c\u6b64\u5904\u4e00\u822c\u90fd\u8bbe\u7f6e\u4e3afalse\uff0c\u672c\u4eba\u8fd8\u672a\u6d4b\u51fa\u8fd92\u4e2aflag\u7684\u533a\u522b<\/p>\n<p><strong>::getChannel()\u3001getConnection() \/\/\u4e0d\u518d\u4ecb\u7ecd\uff0c\u89c1\u4e0a\u9762<br \/>\n<\/strong><\/p>\n<h2>\u56db\u3001AMQPQueue<\/h2>\n<p><strong>::__construct(AMQPChannel $amqp_channel) \/\/\u6709PHP\u5b98\u65b9\u6709\u533a\u522b<\/strong><\/p>\n<p><strong>::setName ( string $queue_name )\u3001::getName ( void ) \/\/\u961f\u5217\u540d\u79f0<\/strong><\/p>\n<p><strong>::setFlags ( int $flags )\u3001::getFlags ( void ) \/\/\u91cd\u70b9<\/strong><br \/>\n\u53ef\u9009\u53c2\u6570\uff1aAMQP_DURABLE, AMQP_PASSIVE,AMQP_EXCLUSIVE, AMQP_AUTODELETE<br \/>\n\u9ed8\u8ba4\uff1aauto_delete<\/p>\n<p>auto_delete\uff1a\u5f53\u961f\u5217\u4e2d\u6709\u6d88\u8d39\u8005\uff0c\u5219\u961f\u5217\u5b58\u5728\uff0c\u5f53\u6ca1\u6709\u6d88\u8d39\u8005\u94fe\u63a5\uff0c\u5219\u961f\u5217\u5220\u9664<\/p>\n<p>durable\uff1a\u6301\u4e45\u5316\uff0c\u961f\u5217\u4e0d\u5220\u9664\uff0c\u6ce8\u610f\u4ec5\u4ec5\u662f\u961f\u5217\u6301\u4e45\uff0c\u6d88\u606f\u4e0d\u6301\u4e45\uff08\u6d88\u606f\u7684\u6301\u4e45\u5728publish\u65f6\u7684\u589e\u52a0\u5c5e\u6027delivery_mode\uff09\u3002\u6d88\u8d39\u7684\u6d88\u606f\uff0c\u4ece\u961f\u5217\u91cc\u5220\u9664\uff0c\u672a\u6d88\u8d39\u7684\u6d88\u606f\u4fdd\u5b58\u5728\u961f\u5217\u4e2d\uff0c\u4e0d\u9700\u8981\u5173\u6ce8\u662f\u5426\u6709\u6d88\u8d39\u8005\u3002\u6700\u5b9e\u7528<\/p>\n<p>passive\uff1a\u58f0\u660e\u4e00\u4e2a1\u4e2a\u5df2\u5b58\u5728\u7684\u961f\u5217\u3002\u610f\u4e49\u4e0d\u5927\uff0c\u5982\u679c\u961f\u5217\u4e0d\u5b58\u5728\u4f1a\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<p>exclusive\uff1a\u6392\u4ed6\u961f\u5217\uff0c\u5982\u679c\u4e00\u4e2a\u961f\u5217\u88ab\u58f0\u660e\u4e3a\u6392\u4ed6\u961f\u5217\uff0c\u8be5\u961f\u5217\u4ec5\u5bf9\u9996\u6b21\u58f0\u660e\u5b83\u7684\u8fde\u63a5\u53ef\u89c1\uff0c\u5e76\u5728\u8fde\u63a5\u65ad\u5f00\u65f6\u81ea\u52a8\u5220\u9664\u3002\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u4e09\u70b9\uff1a<\/p>\n<ol>\n<li>\u6392\u4ed6\u961f\u5217\u662f\u57fa\u4e8e\u8fde\u63a5\u53ef\u89c1\u7684\uff0c\u540c\u4e00\u8fde\u63a5\u7684\u4e0d\u540c\u4fe1\u9053\u662f\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u540c\u4e00\u4e2a\u8fde\u63a5\u521b\u5efa\u7684\u6392\u4ed6\u961f\u5217\u7684\u3002<\/li>\n<li>\u201c\u9996\u6b21\u201d\uff0c\u5982\u679c\u4e00\u4e2a\u8fde\u63a5\u5df2\u7ecf\u58f0\u660e\u4e86\u4e00\u4e2a\u6392\u4ed6\u961f\u5217\uff0c\u5176\u4ed6\u8fde\u63a5\u662f\u4e0d\u5141\u8bb8\u5efa\u7acb\u540c\u540d\u7684\u6392\u4ed6\u961f\u5217\u7684\uff0c\u8fd9\u4e2a\u4e0e\u666e\u901a\u961f\u5217\u4e0d\u540c\u3002<\/li>\n<li>\u5373\u4f7f\u8be5\u961f\u5217\u662f\u6301\u4e45\u5316\u7684\uff0c\u4e00\u65e6\u8fde\u63a5\u5173\u95ed\u6216\u8005\u5ba2\u6237\u7aef\u9000\u51fa\uff0c\u8be5\u6392\u4ed6\u961f\u5217\u90fd\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\u7684\u3002\u8fd9\u79cd\u961f\u5217\u9002\u7528\u4e8e\u53ea\u9650\u4e8e\u4e00\u4e2a\u5ba2\u6237\u7aef\u53d1\u9001\u8bfb\u53d6\u6d88\u606f\u7684\u5e94\u7528\u573a\u666f\u3002<\/li>\n<\/ol>\n<p><strong>::setArgument ( string $key , mixed $value )<\/strong><br \/>\n<strong>::setArguments ( array $arguments )<\/strong><br \/>\n<strong>::getArgument ( string $key )<\/strong><br \/>\n<strong>::getArguments ( void )<\/strong><\/p>\n<p><strong>::declareQueue ( void )<br \/>\n<\/strong><strong>::bind ( string $exchange_name , string $routing_key )<\/strong><br \/>\n<strong>::unbind ( string $exchange_name , string $routing_key )<\/strong><\/p>\n<p><strong>::get ([ int $flags ] )<\/strong><br \/>\n\/\/\u975e\u963b\u585e\uff0c\u4ece\u961f\u5217\u4e2d\u68c0\u7d22\u4e0b\u4e00\u4e2a\u53ef\u7528\u7684\u6d88\u606f\uff0cflags\u4e3a\u7a7a\u9ed8\u8ba4\u4e3aamqp.auto_ack\uff08\u5728php.ini\u4e2d\u53ef\u7528\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff09,\u53ef\u9009\u53c2\u6570\uff1aAMQP_AUTOACK<\/p>\n<p><strong>::consume ( callable $callback [, int $flags = AMQP_NOPARAM ] )<\/strong><br \/>\n\/\/\u963b\u585e\uff0c$callback\u652f\u6301\u6570\u7ec4\u7684\u5199\u6cd5\uff0cflags\u4e3a\u7a7a\u9ed8\u8ba4\u4e3aamqp.auto_ack\uff08\u5728php.ini\u4e2d\u53ef\u7528\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff09,\u53ef\u9009\u53c2\u6570\uff1aAMQP_AUTOACK<\/p>\n<h2><strong>::ack ( int $delivery_tag [, int $flags = AMQP_NOPARAM ] )\u00a0 \/\/\u590d\u6742\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u6700\u597d\u91c7\u7528\u624b\u52a8\u5e94\u7b54\uff0c\u9632\u6b62\u6d88\u8d39\u5904\u7406\u4e1a\u52a1\u903b\u8f91\u590d\u6742\u65f6\uff0c\u6d88\u606f\u4e22\u5931\u3002\u6307\u5b9a\u52a1\u5fc5\u6307\u5b9a\u4e3aAMQP_NOPARAM\uff0c \u672c\u4eba\u6d4b\u8bd5\u4f7f\u7528\u53c2\u6570 AMQP_MULTIPLE\uff0c\u8fbe\u4e0d\u5230\u9884\u671f\u7684\u6548\u679c\u3002\u6b64\u5904\u6709\u5f85\u9ad8\u4eba\u89e3\u51b3\u3002<\/strong><\/h2>\n<p>\u66f4\u4eba\u6027\u5316\u7684\u5e94\u7b54\uff0c\u5728\u4f7f\u7528get\u3001consume\u65f6\uff0c\u6307\u5b9aAMQP_NOPARAM\u65f6\uff08\u672a\u6307\u5b9a\u53c2\u6570\uff0c\u5219\u4f1a\u8c03\u7528PHP.ini\u7684\u9ed8\u8ba4\u7684\u8bbe\u7f6e\uff09\uff0c\u6b64\u65f6\u672a\u5bf9\u6d88\u8d39\u7684\u6d88\u606f\u505a\u5e94\u7b54\u3002\u5728\u5904\u7406\u5b8c\u590d\u6742\u7684\u4e1a\u52a1\u903b\u8f91\u540e\uff0c\u4f7f\u7528ack\u505a\u5e94\u7b54\u3002\u6b64\u65f6\u961f\u5217\u4e2d\uff0c\u4f1a\u5220\u9664\u8be5\u6761\u6d88\u606f\uff0c\u5982\u672a\u5e94\u7b54\uff0c\u5219\u4f1a\u4e00\u76f4\u5b58\u5728\u961f\u5217\u4e2d\u3002<\/p>\n<p><strong>::nack($delivery_tag, $flags = AMQP_NOPARAM)\u3001reject($delivery_tag, $flags = AMQP_NOPARAM)<\/strong><br \/>\n\u7528\u6cd5ack\u76f8\u53cd\uff0c\u8868\u793anot ack.<\/p>\n<p><strong>::purge ( void )<\/strong><br \/>\n\u6e05\u7a7a\u961f\u5217\u4e2d\u7684\u6d88\u606f\u3002<\/p>\n<p><strong>::delete ( void )<\/strong><br \/>\n\u5220\u9664\u961f\u5217<\/p>\n<p><strong>::getChannel()\u3001getConnection() \/\/\u4e0d\u518d\u4ecb\u7ecd\uff0c\u89c1\u4e0a\u9762<\/strong><\/p>\n<p><strong>::cancel ([ string $consumer_tag = \u201c\u201d ] )<\/strong>\u00a0\/\/\u6682\u65f6\u4e0d\u77e5\u8be5\u5982\u4f55\u4f7f\u7528<\/p>\n<h2>\u4e94\u3001AMQPEnvelope<\/h2>\n<p>\u8be5\u7c7b\u6ca1\u6709set\u7684\u65b9\u6cd5\uff0c\u5404\u79cdget<\/p>\n<p><strong>::getBody ( void )<\/strong><br \/>\n<strong>::getRoutingKey ( void )<\/strong><br \/>\n<strong>::getDeliveryTag ( void )<\/strong><br \/>\n<strong>::getDeliveryMode ( void )<\/strong><br \/>\n<strong>::getExchangeName ( void )<\/strong><br \/>\n<strong>::isRedelivery ( void )<\/strong><br \/>\n<strong>::getContentType ( void )<\/strong><br \/>\n<strong>::getContentEncoding ( void )<\/strong><br \/>\n<strong>::getType ( void )<\/strong><br \/>\n<strong>::getTimeStamp ( void )<\/strong><br \/>\n<strong>::getPriority ( void )<\/strong><br \/>\n<strong>::getExpiration ( void )<\/strong><br \/>\n<strong>::getUserId ( void )<\/strong><br \/>\n<strong>::getAppId ( void )<\/strong><br \/>\n<strong>::getMessageId ( void )<\/strong><br \/>\n<strong>::getReplyTo ( void )<\/strong><br \/>\n<strong>::getCorrelationId ( void )<\/strong><br \/>\n<strong>::getHeaders ( void )<\/strong><br \/>\n<strong>::getHeader($header_key).<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u5b9a\u8981\u6ce8\u610fphp\u5b89\u88c5AMQP\u7684\u7248\u672c\uff0c\u7248\u672c\u4e0d\u540c\u4f7f\u7528\u7684\u65b9\u6cd5\u4e0d\u4e00\u6837\u3002\u5728\u5b98\u65b9\u7f51\u7ad9\u5c31\u67092\u4e2a\u7248\u672c\u7684AMQP \u5343\u4e07\u4e0d\u8981\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u627e\u5230\u4e00\u4e2a\u5b98\u65b9\u7684\u7248\u672c\uff0c\u7136\u540e\u6309\u7167example\uff0c\u600e\u4e48\u8c03\u8bd5\u90fd\u4e0d\u901a\u2026.\u6309\u7167PHP\u5b89\u88c5 AMQP\u6269\u5c55\u00a0\u5b89\u88c5\u7684AMQP\u6269\u5c55\u662f\u6700\u65b0\u7684\uff0c\u73b0\u5728\u548cPHP\u5b98\u65b9\u7ed9\u51fa\u7684\u7b2c\u4e8c\u7248\u672c\uff0c\u4e5f\u6709\u4e00\u4e9b\u533a\u522b\u3002\u4e3b\u8981\u4f53\u73b0\u5728exchange\u548cqueue\u4e2d\u6709\u4e2adeclare\u7684\u65b9\u6cd5\uff0c\u5206\u522b\u66f4\u6539\u6210declarExchange()\u548cdeclarQueue(). &nbsp; \u4e00\u3001AMQPConnection ::__construct ([ array $credentials = array() ] ) \u8fd9\u65b9\u6cd5\u6bd4\u8f83\u7b80\u5355\uff0ccredentials\u7684\u82f1\u6587\u542b\u4e49\u662f\u201c\u51ed\u8bc1\u201d\uff0c\u4f46\u6211\u559c\u6b22\u628a\u5b83\u7406\u89e3\u4e3aconfig\u3002\u8fd9\u4e9b\u914d\u7f6e\u5305\u62ec\u5982\u4e0b\uff1a host\u3001vhost\u3001port\u3001login\u3001password\u3001read_timeout\u3001write_timeout\u3001connect_timeout\uff0c\u5982\u679cconfig\u7701\u7565\uff0cphp\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u7684\u8fd95\u4e2a\u503c\uff0c\u521d\u59cb\u5316\uff0c\u5f3a\u70c8\u5efa\u8bae\u5e26\u4e0aconfig\u521d\u59cb\u5316\uff0c\u5176\u4e2dread_timeout\u3001write_timeout\u3001connect_timeout\u8fd9\u4e09\u4e2a\u503c\u662f\u6700\u65b0\u7248\u672c\u624d\u6709\u7684\uff0cPHP\u5b98\u65b9\u73b0\u5728\u8fd8\u6ca1\u6709\uff0c\u5355\u4f4d\u90fd\u662f(\u79d2) ::connect ( void )\u00a0 \u3001\u00a0 ::pconnect ( void ) ::disconnect ( void )\u00a0\u00a0 \u3001::pdisconnect ( void ) ::reconnect ( void ) \u3001::preconnect ( void )\u00a0\u00a0\u00a0#\u6ce8\u610f\u548c__construct \u7684\u533a\u522b\uff0c\u8be5\u65b9\u6cd5\u4e0d\u5e26\u53c2\u6570\u3002 ::isConnected ( void ) ::isPersistent ( void )\u00a0#\u662f\u5426\u6301\u4e45\u94fe\u63a5\u00a0\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u662fisPconnected \uff1f-_- \u5982\u679c\u4f7f\u7528\u6301\u4e45\u94fe\u63a5\uff0c\u5728\u7c7b\u65b9\u6cd5__destruct\u4e2d\u91ca\u653e(\u65ad\u5f00\u94fe\u63a5) ::setHost ( string $host [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-27076","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27076"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27076\/revisions"}],"predecessor-version":[{"id":27089,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27076\/revisions\/27089"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}