29. Apache apollo和mqtt下載和部署

一. 簡介

引用其他文章:

Apache Apollo是一個代理服務器,其是在ActiveMQ基礎上發展而來的,可以支持STOMP, AMQP, MQTT, Openwire, SSL, and WebSockets 等多種協議。

      Apollo允許客戶端通過開放的MQTT協議連接。該協議主要是用在資源有限的驅動上,以及網絡不穩定的情況下使用,是一個訂閱、發佈模型。這種驅動通常不適用類似http,stomp這類基於文本,或者類似openfire,AMQP等傳統二進制協議。MQTT是一個簡介的二進制協議,適用這類驅動資源受限,而且是不穩定的網絡條件下。之前的穩定發佈版本中,MQTT是作爲一個Apollo的一個插件提供的。但是現在,這個插件已經變爲開發項目的一部分。MQTT在Apollo中已經不需要其他配置文件或者是第三方插件支持了。
MQTT是一個線路層的協議,任何實現該協議的客戶端都可以連接到Apollo。當然也可以整合其他MQTT兼容的消息代理中。


二. Mac下apollo安裝

1.下載

apollo下載以及源代碼下載


2.解壓


3. 添加環境變量

APOLLO_HOME=解壓目錄


4. 新建broker目錄,最好不要跟APOLLO_HOME一致,便於以後升級


5. 創建broker

1. cd broker目錄

2. ${APOLLO_HOME}/bin/apollo create mybroker

注意windows下命令可能不同,應該可以直接把apollo.bat拖過來執行。

執行完之後,應該會提示怎麼運行:

You can now start the broker by executing:
"/Users/huangrongwei/Documents/1_work_project/apache_apollo/apollo_broker/mybroker/bin/apollo-broker" run

Or you can run the broker in the background using:

"/Users/huangrongwei/Documents/1_work_project/apache_apollo/apollo_broker/mybroker/bin/apollo-broker-service" start


6. 運行broker

按照上面的提示,選擇一個運行。第一個是前臺運行,就是會佔用你的命令行,不會退出。

下面一個命令是後臺運行。


7.查看apollo進程

ps -elf | grep apollo

結果如下;

501  5418  5361     400e   0  31  0  5048532 125212 -      S+                  0 ttys006    2:00.45 apollo -ea -serv  1:27下午


8. 瀏覽器查看結果

http://127.0.0.1:61680/ 或者 https://127.0.0.1:61681/

第一個是http的,後面一個是https的。

默認登錄的用戶名是admin/password,這樣就可以看到apollo的管理界面。


三. 客戶端測試apollo

在apollo的解壓文件夾裏面有個example文件夾,裏面有個mqtt->java

用eclipse導入這個maven工程(eclipse->file->import->maven project),注意可能需要安裝maven eclipse插件


然後裏面有個Listener.java和Publisher.java,可以訂閱和發佈消息。直接右擊->Run as java application啓動起來。

然後看輸出結果。

Listener.java最後會輸入下面的消息。表示1萬條消息接受花費了0.93秒

Received 0 messages.
Received 1000 messages.
Received 2000 messages.
Received 3000 messages.
Received 4000 messages.
Received 5000 messages.
Received 6000 messages.
Received 7000 messages.
Received 8000 messages.
Received 9000 messages.
Received 10000 in 0.93 seconds


四. 其他

1. curl訪問apollo

curl -u "admin:password" http://localhost:61680/broker.json

結果{"id":"default","state":"STARTED","state_since":1499318856654,"version":"1.7.1","home_location":"/Users/huangrongwei/Documents/1_work_project/apache_apollo/apache-apollo-1.7.1","base_location":"/Users/huangrongwei/Documents/1_work_project/apache_apollo/apollo_broker/mybroker","jvm_metrics":{"heap_memory":{"used":23072848,"alloc":79691776,"max":954728448},"non_heap_memory":{"used":71784880,"alloc":74203136,"max":-1},"classes_loaded":7893,"classes_unloaded":0,"threads_current":27,"threads_peak":32,"os_arch":"x86_64","os_name":"Mac OS X 10.12.4","os_memory_total":8589934592,"os_memory_free":60743680,"os_swap_total":0,"os_swap_free":1073741824,"os_fd_open":135,"os_fd_max":6250,"os_load_average":2.90869140625,"os_cpu_time":128597245000,"os_processors":4,"runtime_name":"[email protected]","jvm_name":"Java HotSpot(TM) 64-Bit Server VM 1.8.0_131 (Oracle Corporation)","uptime":14200613,"start_time":1499318843487},"current_time":1499333764968,"virtual_hosts":["mybroker"],"connectors":["tcp","tls","ws","wss"],"connection_counter":16,"connected":0,"messages_sent":80008,"messages_received":70007,"read_counter":19251413,"write_counter":22040503}



2. mqtt協議內容

http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#fixed-header










發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章