参考:原文链接
写在前面的话:
mac 本来实践一下看看
先下载好MQTTLents和安装java,此处不再赘述,可自行谷歌
实践
1、下载apollo
https://archive.apache.org/dist/activemq/activemq-apollo/1.7.1/
2、解压并启动apollo
- 双击上面的可执行文件弹出terminal或在命令行执行如下命令,可能会有如下提示:没有设置JAVA_HOME
xxxxxxx@localhost /xxxxxxx/study/python3_demo /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/bin/apollo
Error: JAVA_HOME is not defined correctly.
We cannot execute /System/Library/Frameworks/JavaVM.framework/Home/bin/java
- 设置JAVA_HOME:注意–此处sudo 修改/etc/profile是没用的。必须修改~/.bash_profile。
xxxxxxx@localhost /xxxxxxx/study/python3_demo vim ~/.bash_profile
......
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
export JAVA_HOME=$JAVA_8_HOME
export PATH=$JAVA_HOME/bin:$PATH:.:$JMETER_HOME/bin:$PATH:~/Library/Python/2.7/lib/python/site-packages
......
- 使环境变量生效
xxxxxxx@localhost /xxxxxxx/study/python3_demo source ~/.bash_profile
- 启动apollo
xxxxxxx@localhost /xxxxxxx/study/python3_demo
/Users/wangjie/Downloads/apache-apollo-1.7.1/bin/apollo
usage: apollo [--log <log_level>] <command> [<args>]
The most commonly used apollo commands are:
create creates a new broker instance
disk-benchmark Benchmarks your disk's speed
help Display help information
version Displays the broker version
See apollo help <command>' for more information on a specific command.
# 启动命令如下:create + 自动以name + broker目录,缺一不可,否则会报错
xxxxxxx@localhost /xxxxxxx/study/python3_demo /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/bin/apollo create myapollo /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/broker
Creating apollo instance at: /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/broker
Generating ssl keystore...
Warning:
JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore keystore -destkeystore keystore -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。
You can now start the broker by executing:
"/Users/xxxxx/Downloads/apache-apollo-1.7.1/broker/bin/apollo-broker" run
Or you can run the broker in the background using:
"/Users/xxxxx/Downloads/apache-apollo-1.7.1/broker/bin/apollo-broker-service" start
xxxxxxx@localhost /xxxxxxx/study/python3_demo /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/broker/bin/apollo-broker run
_____ .__ .__
/ _ \ ______ ____ | | | | ____
/ /_\ \\____ \ / _ \| | | | / _ \
/ | \ |_> > <_> ) |_| |_( <_> )
\____|__ / __/ \____/|____/____/\____/
\/|__| Apache Apollo (1.7.1)
Loading configuration file '/Users/xxxxxxx/Downloads/apache-apollo-1.7.1/broker/etc/apollo.xml'.
INFO | OS : Mac OS X 10.14.3
INFO | JVM : Java HotSpot(TM) 64-Bit Server VM 1.8.0_201 (Oracle Corporation)
INFO | Apollo : 1.7.1 (at: /Users/xxxxxxx/Downloads/apache-apollo-1.7.1)
INFO | OS is restricting the open file limit to: 10240
INFO | Starting store: leveldb store at /Users/xxxxxxx/Downloads/apache-apollo-1.7.1/broker/data
INFO | Accepting connections at: tcp://0.0.0.0:61613
INFO | Accepting connections at: tls://0.0.0.0:61614
INFO | Accepting connections at: ws://0.0.0.0:61623/
INFO | Accepting connections at: wss://0.0.0.0:61624/
INFO | Administration interface available at: https://127.0.0.1:61681/
INFO | Administration interface available at: http://127.0.0.1:61680/
4、浏览器打开:各种协议的端口如上
http://127.0.0.1:61680/ admin登录进入管理页面(用户名和密码admin/password),可以新增几个topics。
ok了,看着apollo是可以了。
5、打开MQTTLens,连接apollo服务,相关注意事项都在图中了
点击下方保存后,进入如下界面,如果没连接成功,左侧myapollo的按钮不是绿色而是红色。下图中的1和2就是之前在apollo页面新增的,填写好1之后一定要点击右侧的subscribe按钮,会在下方生成一个类似消息打印的下拉框。然后在3输入想要发送的message,就可以点击右侧2的publish发送消息了。这时候发送成功会在下方显示成功的消息。如下图:
6、值得一提的是:apollo目录下有一个example,其中有个文件,可以双击点开然后也可以连接apollo,来发布和订阅topic消息,从而可以和mqttlens互动,达到聊天室的功能。
双击上图的index.html即可进入如下页面:
8、未完待续…