成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

RabbitMQ+PHP 消息隊(duì)列環(huán)境配置

geekidentity / 1223人閱讀

摘要:參考文檔依賴包安裝環(huán)境配置環(huán)境變量增加內(nèi)容保存退出,并刷新變量測(cè)試是否安裝成功安裝完成以后,執(zhí)行看是否能打開(kāi),用退出,注意后面的點(diǎn)號(hào),那是的結(jié)束符。

參考文檔:
http://www.cnblogs.com/phpinfo/p/4104551...
http://blog.csdn.net/historyasamirror/ar...

依賴包安裝
yum install ncurses-devel unixODBC unixODBC-devel  
erlang環(huán)境
wget http://erlang.org/download/otp_src_18.1.tar.gz
tar -zxvf otp_src_18.1.tar.gz
cd otp_src_18.1
./configure --prefix=/usr/local/erlang
make
make install


# 配置erlang環(huán)境變量
vim /etc/profile
# 增加內(nèi)容:
export PATH="$PATH:/usr/local/erlang/bin"

# 保存退出,并刷新變量
source /etc/profile


# 測(cè)試erlang是否安裝成功
# 安裝完成以后,執(zhí)行erl看是否能打開(kāi)eshell,用’halt().’退出,注意后面的點(diǎn)號(hào),那是erlang的結(jié)束符。
[root@localhost src]# erl 
Erlang/OTP 17 [erts-6.1] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V6.1  (abort with ^G) 
2> 9+3. 
12 
3> halt().
安裝rabbitmq依賴文件,安裝rabbitmq
# 安裝rabbitmq依賴包
yum install xmlto

# 安裝rabbitmq服務(wù)端
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server-3.5.7.tar.gz
tar zxvf rabbitmq-server-3.5.7.tar.gz
cd rabbitmq-server-3.5.7/
make
make install TARGET_DIR=/usr/local/rabbitmq SBIN_DIR=/usr/local/rabbitmq/sbin MAN_DIR=/usr/local/rabbitmq/man DOC_INSTALL_DIR=/usr/local/rabbitmq/doc

# 配置hosts
vim /etc/hosts
# 增加一行內(nèi)容
# 當(dāng)前IP地址   綁定HOSTNAME名稱(vim /etc/sysconfig/network)
192.168.2.208 localhost.localdomain

# 這種會(huì)提示錯(cuò)誤(Warning: PID file not written; -detached was passed.)
/usr/local/rabbitmq/sbin/rabbitmq-server -detached 啟動(dòng)rabbitmq
/usr/local/rabbitmq/sbin/rabbitmqctl status 查看狀態(tài)
/usr/local/rabbitmq/sbin/rabbitmqctl stop 關(guān)閉rabbitmq

# 目前我自己使用
/usr/local/rabbitmq/sbin/rabbitmq-server start & 啟動(dòng)rabbitmq
/usr/local/rabbitmq/sbin/rabbitmqctl status 查看狀態(tài)
/usr/local/rabbitmq/sbin/rabbitmqctl stop 關(guān)閉rabbitmq
啟用管理插件
mkdir /etc/rabbitmq
/usr/local/rabbitmq/sbin/rabbitmq-plugins list 查看插件列表
/usr/local/rabbitmq/sbin/rabbitmq-plugins enable rabbitmq_management  (啟用插件)
/usr/local/rabbitmq/sbin/rabbitmq-plugins disable rabbitmq_management (禁用插件)

# 重啟rabbitmq
# 訪問(wèn) http://127.0.0.1:15672/

# 如果有iptables
vim /etc/sysconfig/iptables

# 增加一下內(nèi)容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 15672 -j ACCEPT

# 重啟動(dòng)iptable
service iptables restart
開(kāi)機(jī)自啟動(dòng)配置
#!/bin/sh
#start rabbitMq
sudo /usr/local/rabbitmq/sbin/rabbitmq-server & > /usr/local/rabbitmq/logs/rabbitmq.log 2>&1
RabbitMQ PHP擴(kuò)展安裝
# 安裝rabbitmq-c依賴包
yum install libtool autoconf

# 安裝rabbitmq-c ( 最好下載 0.5的,0.6安裝可能會(huì)報(bào)錯(cuò))
# 版本下載:https://github.com/alanxz/rabbitmq-c/releases/tag/v0.5.0
wget https://github.com/alanxz/rabbitmq-c/releases/download/v0.5.0/rabbitmq-c-0.5.0.tar.gz
tar -zxvf v0.5.0
cd rabbitmq-c-0.5.0/
autoreconf -i
./configure --prefix=/usr/local/rabbitmq-c
make
make install

# 安裝PHP擴(kuò)展 amqp
wget http://pecl.php.net/get/amqp-1.6.1.tgz
tar zxvf amqp-1.6.1.tgz
cd amqp-1.6.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c
make
make install

# 編輯php.ini文件,增加amqp擴(kuò)展支持
vim /usr/local/php/etc/php.ini

# 增加下面內(nèi)容
; rabbitmq擴(kuò)展支持
extension=amqp.so

# 重啟php-fpm
/etc/init.d/php-fpm restart

驗(yàn)證是否成功 phpinfo()查看下是否支持amqp擴(kuò)展


相關(guān)配置
hostname mq        // 設(shè)置hostname名稱
vim /etc/sysconfig/network    // 設(shè)置hostname
vim /etc/hosts    // 編輯hosts
./rabbitmqctl add_user admin admin     // 添加用戶
./rabbitmqctl set_user_tags admin administrator        // 添加admin 到 administrator分組
./rabbitmqctl set_permissions -p / admin "*." "*." "*."    // 添加權(quán)限
創(chuàng)建配置文件
#在/usr/rabbitmq/sbin/rabbitmq-defaults 查看config文件路徑
# 創(chuàng)建配置文件 
touch/usr/rabbitmq/sbin
#vm_memory_high_watermark 內(nèi)存低水位線,若低于該水位線,則開(kāi)啟流控機(jī)制,阻止所有請(qǐng)求,默認(rèn)值是0.4,即內(nèi)存總量的40%,
#vm_memory_high_watermark_paging_ratio 內(nèi)存低水位線的多少百分比開(kāi)始通過(guò)寫(xiě)入磁盤(pán)文件來(lái)釋放內(nèi)存
vi /usr/rabbitmq/sbin/rabbitmq.config 輸入
[
{rabbit, [{vm_memory_high_watermark_paging_ratio, 0.75},
         {vm_memory_high_watermark, 0.7}]}
].
創(chuàng)建環(huán)境文件
touch /etc/rabbitmq/rabbitmq-env.conf
#輸入
    RABBITMQ_NODENAME=FZTEC-240088 節(jié)點(diǎn)名稱
    RABBITMQ_NODE_IP_ADDRESS=127.0.0.1 監(jiān)聽(tīng)I(yíng)P
    RABBITMQ_NODE_PORT=5672 監(jiān)聽(tīng)端口
    RABBITMQ_LOG_BASE=/data/rabbitmq/log 日志目錄
    RABBITMQ_PLUGINS_DIR=/data/rabbitmq/plugins 插件目錄
    RABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesia 后端存儲(chǔ)目錄
操作命令
 查看exchange信息
          /usr/rabbitmq/sbin/rabbitmqctl list_exchanges name type durable auto_delete arguments

 查看隊(duì)列信息
          /usr/rabbitmq/sbin/rabbitmqctl list_queues name durable auto_delete messages consumers me
  查看綁定信息
          /usr/rabbitmq/sbin/rabbitmqctl list_bindings
 查看連接信息
          /usr/rabbitmq/sbin/rabbitmqctl list_connections
php的server端腳本
 "localhost", "port" => "5672", "login" => "guest", "password" => "guest");
$conn = new AMQPConnection($conn_args);
if ($conn->connect()) {
    echo "Established a connection to the broker 
";
}
else {
    echo "Cannot connect to the broker 
 ";
}
//你的消息
$message = json_encode(array("Hello World3!","php3","c++3:"));
//創(chuàng)建channel
$channel = new AMQPChannel($conn);
//創(chuàng)建exchange
$ex = new AMQPExchange($channel);
$ex->setName("exchange");//創(chuàng)建名字
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE);
//$ex->setFlags(AMQP_AUTODELETE);
//echo "exchange status:".$ex->declare();
echo "exchange status:".$ex->declareExchange();
echo "
";
for($i=0;$i<100;$i++){
        if($routingkey=="key2"){
                $routingkey="key";
        }else{
                $routingkey="key2";
        }
        $ex->publish($message,$routingkey);
}
/*
$ex->publish($message,$routingkey);
創(chuàng)建隊(duì)列
$q = new AMQPQueue($channel);
設(shè)置隊(duì)列名字 如果不存在則添加
$q->setName("queue");
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
echo "queue status: ".$q->declare();
echo "
";
echo "queue bind: ".$q->bind("exchange","route.key");
將你的隊(duì)列綁定到routingKey
echo "
";

$channel->startTransaction();
echo "send: ".$ex->publish($message, "route.key"); //將你的消息通過(guò)制定routingKey發(fā)送
$channel->commitTransaction();
$conn->disconnect();
*/
php客戶端腳本
"127.0.0.1" , "port"=> "5672", "login"=>"guest" , "password"=> "guest","vhost" =>"/");
$conn = new AMQPConnection($conn_args);
$conn->connect();
//設(shè)置queue名稱,使用exchange,綁定routingkey
$channel = new AMQPChannel($conn);
$q = new AMQPQueue($channel);
$q->setName("queue2");
$q->setFlags(AMQP_DURABLE);
$q->declare();
$q->bind("exchange",$bindingkey);
//消息獲取
$messages = $q->get(AMQP_AUTOACK) ;
if ($messages){
var_dump(json_decode($messages->getBody(), true ));
}
$conn->disconnect();
?>
翻譯了部分mq常量設(shè)置,不正確的地方,大家以試驗(yàn)為準(zhǔn)
/**
 * Passing in this constant as a flag will forcefully disable all other flags.
 * Use this if you want to temporarily disable the amqp.auto_ack ini setting.
 * 傳遞這個(gè)參數(shù)作為標(biāo)志將完全禁用其他標(biāo)志,如果你想臨時(shí)禁用amqp.auto_ack設(shè)置起效
 */
define("AMQP_NOPARAM", 0);

/**
 * Durable exchanges and queues will survive a broker restart, complete with all of their data.
 * 持久化交換機(jī)和隊(duì)列,當(dāng)代理重啟動(dòng)后依然存在,并包括它們中的完整數(shù)據(jù)
 */
define("AMQP_DURABLE", 2);

/**
 * Passive exchanges and queues will not be redeclared, but the broker will throw an error if the exchange or queue does not exist.
 * 被動(dòng)模式的交換機(jī)和隊(duì)列不能被重新定義,但是如果交換機(jī)和隊(duì)列不存在,代理將扔出一個(gè)錯(cuò)誤提示
 */
define("AMQP_PASSIVE", 4);

/**
 * Valid for queues only, this flag indicates that only one client can be listening to and consuming from this queue.
 * 僅對(duì)隊(duì)列有效,這個(gè)人標(biāo)志定義隊(duì)列僅允許一個(gè)客戶端連接并且從其消費(fèi)消息
 */
define("AMQP_EXCLUSIVE", 8);

/**
 * For exchanges, the auto delete flag indicates that the exchange will be deleted as soon as no more queues are bound
 * to it. If no queues were ever bound the exchange, the exchange will never be deleted. For queues, the auto delete
 * flag indicates that the queue will be deleted as soon as there are no more listeners subscribed to it. If no
 * subscription has ever been active, the queue will never be deleted. Note: Exclusive queues will always be
 * automatically deleted with the client disconnects.
 * 對(duì)交換機(jī)而言,自動(dòng)刪除標(biāo)志表示交換機(jī)將在沒(méi)有隊(duì)列綁定的情況下被自動(dòng)刪除,如果從沒(méi)有隊(duì)列和其綁定過(guò),這個(gè)交換機(jī)將不會(huì)被刪除.
 * 對(duì)隊(duì)列而言,自動(dòng)刪除標(biāo)志表示如果沒(méi)有消費(fèi)者和你綁定的話將被自動(dòng)刪除,如果從沒(méi)有消費(fèi)者和其綁定,將不被刪除,獨(dú)占隊(duì)列在客戶斷
 * 開(kāi)連接的時(shí)候?qū)⒖偸菚?huì)被刪除
 */
define("AMQP_AUTODELETE", 16);

/**
 * Clients are not allowed to make specific queue bindings to exchanges defined with this flag.
 * 這個(gè)標(biāo)志標(biāo)識(shí)不允許自定義隊(duì)列綁定到交換機(jī)上
 */
define("AMQP_INTERNAL", 32);

/**
 * When passed to the consume method for a clustered environment, do not consume from the local node.
 * 在集群環(huán)境消費(fèi)方法中傳遞這個(gè)參數(shù),表示將不會(huì)從本地站點(diǎn)消費(fèi)消息
 */
define("AMQP_NOLOCAL", 64);

/**
 * When passed to the {@link AMQPQueue::get()} and {@link AMQPQueue::get()} methods as a flag,
 * the messages will be immediately marked as acknowledged by the server upon delivery.
 * 當(dāng)在隊(duì)列g(shù)et方法中作為標(biāo)志傳遞這個(gè)參數(shù)的時(shí)候,消息將在被服務(wù)器輸出之前標(biāo)志為acknowledged (已收到)
 */
define("AMQP_AUTOACK", 128);

/**
 * Passed on queue creation, this flag indicates that the queue should be deleted if it becomes empty.
 * 在隊(duì)列建立時(shí)候傳遞這個(gè)參數(shù),這個(gè)標(biāo)志表示隊(duì)列將在為空的時(shí)候被刪除
 */
define("AMQP_IFEMPTY", 256);

/**
 * Passed on queue or exchange creation, this flag indicates that the queue or exchange should be
 * deleted when no clients are connected to the given queue or exchange.
 * 在交換機(jī)或者隊(duì)列建立的時(shí)候傳遞這個(gè)參數(shù),這個(gè)標(biāo)志表示沒(méi)有客戶端連接的時(shí)候,交換機(jī)或者隊(duì)列將被刪除
 */
define("AMQP_IFUNUSED", 512);

/**
 * When publishing a message, the message must be routed to a valid queue. If it is not, an error will be returned.
 * 當(dāng)發(fā)布消息的時(shí)候,消息必須被正確路由到一個(gè)有效的隊(duì)列,否則將返回一個(gè)錯(cuò)誤
 */
define("AMQP_MANDATORY", 1024);

/**
 * When publishing a message, mark this message for immediate processing by the broker. (High priority message.)
 * 當(dāng)發(fā)布消息時(shí)候,這個(gè)消息將被立即處理.
 */
define("AMQP_IMMEDIATE", 2048);

/**
 * If set during a call to {@link AMQPQueue::ack()}, the delivery tag is treated as "up to and including", so that multiple
 * messages can be acknowledged with a single method. If set to zero, the delivery tag refers to a single message.
 * If the AMQP_MULTIPLE flag is set, and the delivery tag is zero, this indicates acknowledgement of all outstanding
 * messages.
 * 當(dāng)在調(diào)用AMQPQueue::ack時(shí)候設(shè)置這個(gè)標(biāo)志,傳遞標(biāo)簽將被視為最大包含數(shù)量,以便通過(guò)單個(gè)方法標(biāo)示多個(gè)消息為已收到,如果設(shè)置為0
 * 傳遞標(biāo)簽指向單個(gè)消息,如果設(shè)置了AMQP_MULTIPLE,并且傳遞標(biāo)簽是0,將所有未完成消息標(biāo)示為已收到
 */
define("AMQP_MULTIPLE", 4096);

/**
 * If set during a call to {@link AMQPExchange::bind()}, the server will not respond to the method.The client should not wait
 * for a reply method. If the server could not complete the method it will raise a channel or connection exception.
 * 當(dāng)在調(diào)用AMQPExchange::bind()方法的時(shí)候,服務(wù)器將不響應(yīng)請(qǐng)求,客戶端將不應(yīng)該等待響應(yīng),如果服務(wù)器無(wú)法完成該方法,將會(huì)拋出一個(gè)異常
 */
define("AMQP_NOWAIT", 8192);

/**
 * If set during a call to {@link AMQPQueue::nack()}, the message will be placed back to the queue.
 * 如果在調(diào)用AMQPQueue::nack方法時(shí)候設(shè)置,消息將會(huì)被傳遞回隊(duì)列
 */
define("AMQP_REQUEUE", 16384);

/**
 * A direct exchange type.
 * direct類型交換機(jī)
 */
define("AMQP_EX_TYPE_DIRECT", "direct");

/**
 * A fanout exchange type.
 * fanout類型交換機(jī)
 */
define("AMQP_EX_TYPE_FANOUT", "fanout");

/**
 * A topic exchange type.
 * topic類型交換機(jī)
 */
define("AMQP_EX_TYPE_TOPIC", "topic");

/**
 * A header exchange type.
 * header類型交換機(jī)
 */
define("AMQP_EX_TYPE_HEADERS", "headers");

/**
 * socket連接超時(shí)設(shè)置
 */
define("AMQP_OS_SOCKET_TIMEOUT_ERRNO", 536870947);

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/21454.html

相關(guān)文章

  • RabbitMQ使用

    摘要:的定義是使用語(yǔ)言開(kāi)發(fā)的開(kāi)源消息隊(duì)列系統(tǒng),完整的實(shí)現(xiàn)了高級(jí)抽象層消息通信協(xié)議。交換機(jī)接受發(fā)送的消息,并根據(jù)綁定規(guī)則轉(zhuǎn)發(fā)到對(duì)應(yīng)的隊(duì)列。默認(rèn)是無(wú)名交換使用空字符串標(biāo)識(shí)。消息隊(duì)列是內(nèi)部對(duì)象,用于存儲(chǔ)未被消費(fèi)的消息。 RabbitMQ的定義 RabbitMQ是使用erlang語(yǔ)言開(kāi)發(fā)的開(kāi)源消息隊(duì)列系統(tǒng),完整的實(shí)現(xiàn)了AMPQ(高級(jí)抽象層消息通信協(xié)議)。 Mac下RabbitMQ安裝 使用Hom...

    codeKK 評(píng)論0 收藏0
  • RabbitMQ+PHP 教程二(Work Queues)

    摘要:平均每個(gè)消費(fèi)者將得到相同數(shù)量的消息。消息確認(rèn)完成任務(wù)可能需要幾秒鐘。為了確保消息不會(huì)丟失,支持消息確認(rèn)。沒(méi)有任何消息超時(shí)當(dāng)這個(gè)消費(fèi)者中止了,將會(huì)重新分配消息時(shí)。這是因?yàn)橹皇钦{(diào)度消息時(shí),消息進(jìn)入隊(duì)列。 showImg(https://segmentfault.com/img/bVXNuN?w=332&h=111); 介紹 在上一個(gè) Hello World 教程中,我們編寫(xiě)了從指定隊(duì)列發(fā)送...

    iKcamp 評(píng)論0 收藏0
  • RabbitMQ 基礎(chǔ)教程(1) - Hello World

    摘要:基礎(chǔ)教程注本文是對(duì)眾多博客的學(xué)習(xí)和總結(jié),可能存在理解錯(cuò)誤。請(qǐng)帶著懷疑的眼光,同時(shí)如果有錯(cuò)誤希望能指出。安裝庫(kù)這里我們首先將消息推入隊(duì)列,然后消費(fèi)者從隊(duì)列中去除消息進(jìn)行消費(fèi)。 RabbitMQ 基礎(chǔ)教程(1) - Hello World 注:本文是對(duì)眾多博客的學(xué)習(xí)和總結(jié),可能存在理解錯(cuò)誤。請(qǐng)帶著懷疑的眼光,同時(shí)如果有錯(cuò)誤希望能指出。 如果你喜歡我的文章,可以關(guān)注我的私人博客:http:...

    wushuiyong 評(píng)論0 收藏0
  • PHP-RabbitMQ學(xué)習(xí)日記(一)

    摘要:通道,建立一個(gè)訪問(wèn)通道。隊(duì)列,每個(gè)消息都會(huì)被投入到一個(gè)或多個(gè)隊(duì)列。路由,根據(jù)這個(gè)關(guān)鍵字進(jìn)行消息投遞。消息消費(fèi)者,就是接受消息的程序。 給自己做一個(gè)記錄 本文主要介紹有一下 1.RabbitMQ是概念 2.RabbitMQ在windows上安裝,啟動(dòng),關(guān)閉 3.RabbitMQ其他小介紹 下面一步一步走起來(lái) 1.RabbitMQ是概念 RabbitMQ是一個(gè)建立在AMQP(高級(jí)消息隊(duì)列協(xié)...

    SolomonXie 評(píng)論0 收藏0
  • 轉(zhuǎn): RabbitMQPHP(一)

    摘要:需要特別明確的概念交換機(jī)的持久化,并不等于消息的持久化。消息的處理,是有兩種方式,一次性。在上述示例中,使用的,意味著接收全部的消息。注意與是兩個(gè)不同的隊(duì)列。后端處理,可以針對(duì)每一個(gè)啟動(dòng)一個(gè)或多個(gè),以提高消息處理的實(shí)時(shí)性。 RabbitMQ與PHP(一) 項(xiàng)目中使用RabbitMQ作為隊(duì)列處理用戶消息通知,消息由前端PHP代碼產(chǎn)生,處理消息使用Python,這就導(dǎo)致代碼一致性問(wèn)題,調(diào)...

    wpw 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<