无法在 Mac 上测试 Mosquitto 服务器

Unable to test Mosquitto Server on Mac

我已经使用

使用 brew 安装了 Mosquitto

brew install mosquitto

并使用

测试是否运行

brew services list

输出

Name       Status  User Plist
mongodb    stopped      
mosquitto  started amit /Users/amit/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
postgresql stopped      
tomcat     stopped

但是,当我尝试以下 this 答案时,我得到命令未找到

mosquitto_sub -v -t 'test/topic'
-bash: mosquitto_sub: command not found

我是否必须安装其他东西才能工作?

此外,我尝试使用 python 脚本连接到代理,但收到连接被拒绝的消息

client = mqtt.Client()
client.on_connect = on_connect_handler
client.on_message = on_message_handler

client.connect("localhost", 1883, 60)
client.loop_forever()

编辑 1

我使用 brew link mosquitto.

解决了无法使用 mosquitto_sub 的第一个问题

但我仍然遇到连接被拒绝的情况。

经过一些谷歌搜索和尝试不同的东西后,我找到了这两个问题的答案。

  1. 无法启动发布者和订阅者客户端的第一个问题已使用 brew link mosquitto 解决。要检查 brew link 的工作原理,您可以检查 this post.
  2. 将 mosquitto 代理服务作为守护进程启动允许连接。所以简单地使用 brew services start mosquitto -d 就可以了。我不确定为什么这会起作用而不是启动正常过程。