標籤:message info 結束 strong lan vhost blog 虛擬 odi
一、背景
近期做一個小的基礎組件,主要作用是非同步訊息通知、緩衝維護、以及耗時任務處理。
當中訊息通知和耗時任務處理要用到開源的RabbitMQ作為訊息中心server。
可是有一點比較噁心,我這個組件是要執行在現有的系統中,即要給現有的系統升級,將我這個組件用進去,並且,除了除資料庫server之外,全部server都是windows server 2003 enterprise edition sp2 64bit的。你沒看錯,就是這麼古老的機器。。。
二、面臨的問題
之前在windows server 2008和centOS上安裝RabbitMQ都很順利。沒有遇到不論什麼阻礙,這次在windows server 2003上面安裝就遇到了問題:
1、首先安裝ErLang的時候,沒有出現不論什麼問題,我裝的是OTP 17.3 Windows 64-bit,地址是:http://www.erlang.org/download.html
2、安裝RabbitMQ 最新版3.3.5的時候出問題了。即無法定位程式輸入焦點inet_pton於動態連結程式庫WS2_32.dll上。例如以:
報出了一個和網路位址轉譯相關的錯誤。。。這讓我想不到。
三、尋找答案的過程和思考
於是開始上網找,中文網頁壓根沒人在windows server 2003上面安裝過RabbitMQ,在非常多qq群問了也無果。
於是開始搜尋英文網頁。找到這麼一個網址:http://comments.gmane.org/gmane.comp.networking.rabbitmq.general/16499
這兩人的對話給我非常多關鍵性資訊。最關鍵的莫過於:
From the information you provided it is likely that this is caused bythe Erlang distributed networking not working on windows 2003 64bit.This platform is sufficiently rare that no-one else has reported thisproblem for Erlang, but I see there was a similar report in Wiresharkcaused by a library ordering problem:https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5160#c16If you can find the shortest set of steps that provokes the error thenthat should be enough to give the Erlang developers a handle on theproblem. I would expect these commands to cause a failure - can youconfirm? Make sure the Erlang bin directory is in your PATH:werl -sname testnode <at> %COMPUTERNAME%werl -sname foo -remsh testnode <at> %COMPUTERNAME%If you need a working RabbitMQ broker in the meantime then considerinstalling the 32bit version of Erlang. I not expect it to suffer fromthe same problem.
看來應該就是Erlang的問題了,RabbitMQ號稱僅僅要ErLang可以跑的系統,它也可以非常好滴工作^_^ !
ErLang的開發人員預計也知道這個問題了,這麼幾年下來到如今最新版17.3了還沒有改動。預計他們也不會打算要修複這個Bug了。連微軟都停止支援windows server 2003了。
於是我又一次下載了一個R16B03 Windows 32-bit Binary
吧之前安裝的RabbitMQ和Erlang所有卸載掉,然後又一次安裝ErLang和RabbitMQ,這次在安裝RabbitMQ的時候又遇到問題了:
這下讓我有點頭痛了,難道我僅僅剩下最後一條能夠嘗試的路了?就是 在這個windows server 2003上面又一次編譯Erlang原始碼麼。。。
我靜下來想了想,突然認為這個錯誤判的是無法注冊RabbitMQ 服務。。。 我暈,下次應該好好觀察一下報的錯誤,這個明顯就是RabbitMQ注冊服務的問題嘛。
。
。應該是和ErLang無關的。
。。
可能是卸載RabbitMQ並沒有卸載乾淨服務和注冊表。
於是我直接把我的系統還原到之前乾淨的鏡像,又一次安裝。OK。!!
四、解決方案
1、安裝ErLang 32-bit。是:http://www.erlang.org/download_release/22,我安裝的是16B03 32bit。
2、建立系統內容變數ERLANG_HOME。值為C:\Program Files (x86)\erl5.10.4,即僅僅要可以找到bin/werl.exe就可以。
3、安裝RabbitMQ 3.3.5。是:https://www.rabbitmq.com/install-windows.html
4、添加rabbitmqctl.bat的路徑(C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.3.5\sbin)到PATH系統內容變數。
非常easy,這就安裝完畢了,接下來建立使用者(最好將預設的guest使用者刪掉)。建立虛擬機器vHost,設定使用者對該虛擬機器的許可權:
好了。以下附上一個C#的測試程式:
send.cs
namespace RabbitMQ.SendReceive{ class Program { static void Main(string[] args) { //ConnectionFactory factory = new ConnectionFactory() { HostName = "192.168.1.103" }; ConnectionFactory factory = new ConnectionFactory(); factory.Uri = "amqp://jiyiqin:[email protected]:5672/cProxy"; using (IConnection conn = factory.CreateConnection()) { using (IModel channel = conn.CreateModel()) { channel.QueueDeclare("hello", false, false, false, null); string mesg = "hello RabbitMQ"; byte[] body = Encoding.UTF8.GetBytes(mesg); channel.BasicPublish("", "hello", null, body); Console.WriteLine(" [x] Sent {0}", mesg); } } } }}
receive.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using RabbitMQ.Client;using RabbitMQ.Client.Events;namespace RabbitMQ.SendReceive{ class Program { static void Main(string[] args) { //ConnectionFactory factory = new ConnectionFactory() { HostName = "192.168.1.103" }; ConnectionFactory factory = new ConnectionFactory(); factory.Uri = "amqp://jiyiqin:[email protected]:5672/cProxy"; using (IConnection conn = factory.CreateConnection()) { using (IModel channel = conn.CreateModel()) { channel.QueueDeclare("hello", false, false, false, null); QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel); channel.BasicConsume("hello", true, consumer); Console.WriteLine(" [*]Waiting for message..."); while (true) { var queueItem = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); byte[] body = queueItem.Body; string mesg = Encoding.UTF8.GetString(body); Console.WriteLine(" [x] Received {0}", mesg); } } } } }}
當然了,64bit的硬體上面跑32bit的程式。肯定無法發揮硬體效果。可能效能也不是很高。可是幸好我們這個古老的系統對並發量等要求太小。哈哈
結束。
windows server 2003 64bit SP2下安裝RabbitMQ