这是paho Async客户端:
client = new MqttAsyncClient(appProps.getProperty("mqtt.broker"),
appProps.getProperty("mqtt.clientId"), new MemoryPersistence());
client.setCallback(this);
client.connect(null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken imt) {
try {
client.subscribe(Constants.internalTopics, Constants.internalTopicQOS);
} catch (MqttException ex) {
ex.printStackTrace();
}
}
@Override
public void onFailure(IMqttToken imt, Throwable thrwbl) {
thrwbl.printStackTrace();
}
});
Run Code Online (Sandbox Code Playgroud)
我在这里循环发送消息:
while (iterator.hasNext()) {
try {
client.publish("user/" + userId + "/downstream", mqttMessage);
} catch(Exception ex) {
ex.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
Too many publishes in progress (32202)
at org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:436)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:121)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:139)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:858)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:836)
Run Code Online (Sandbox Code Playgroud)
我在用 …
在 Mosquitto 上配置身份验证时遇到问题。
只要我允许匿名连接mosquitto.conf,我就可以毫无问题地访问代理(发布和订阅)。但是一旦我启用身份验证,我就会得到一个“ connection refused”。我遵循了多个关于如何设置身份验证的教程,但我无法让它工作,也无法弄清楚原因。
我已经在 Raspberry PI 3 B 型上安装了 Mosquitto 1.4.10。
我使用命令创建了一个密码文件:sudo mosquitto_passwd -c /etc/mosquitto/passwd test并将密码设置为“test”。
我已设置allow_anonymous为 false 并将 password_file设置为/etc/mosquitto/passwdin mosquitto.conf。
然后,当我尝试命令时sudo mosquitto_sub -t hello/world -u test -P test,我收到“错误:连接被拒绝”。
我检查了密码文件,它似乎是正确的(它具有正确的名称和路径/etc/mosquitto/passwd,并且包含我的用户“test”的条目)。
题:
我在配置中犯了错误吗?我错过了什么吗?
我是 MQTT 协议的新手。当我通读文档时,我看不到任何删除已发布主题的功能。我的目的是允许发布者删除已发布的主题。我错过了 mqtt 文档中的某些内容吗?有什么建议吗?谢谢 !
我正在尝试使用paho pkg通过golang构建mqtt子客户端,当代理断开连接时,我的客户端出现问题,我认为应该会出现丢失的消息,但这不会发生,如果我启动代理,mqtt子客户端可以无法获取mqtt pub客户端发送的消息。
为什么会发生这种情况,我该如何解决?
码
package main
import (
"fmt"
"os"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
var (
broker = "tcp://localhost:1883"
f mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
fmt.Printf("TOPIC: %s\n", msg.Topic())
fmt.Printf("MSG: %s\n", msg.Payload())
}
)
func main() {
//create a ClientOptions
opts := mqtt.NewClientOptions().AddBroker(broker)
opts.SetClientID("group-one")
opts.SetDefaultPublishHandler(f)
//create and start a client using the above ClientOptions
c := mqtt.NewClient(opts)
if token := c.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
if token := c.Subscribe("test", 0, nil); token.Wait() …Run Code Online (Sandbox Code Playgroud) 问候我正在配置一个节点红色的服务器,在应用Nginx重定向后,出现了以下问题。

使用Nginx将子域node-red.domain.com重定向到localhost:1880之后
Nginx重定向配置:
server {
listen 80;
server_name sub1.domain.com;
location / {
proxy_pass "https://127.0.0.1:8080";
}
}
server {
listen 80;
server_name sub2.domain.com;
location / {
proxy_pass "https://127.0.0.1:8080";
}
}
Run Code Online (Sandbox Code Playgroud)
请任何人可以帮助我吗?
我目前有一个MQTT代码,可以订阅主题,打印出收到的消息,然后将更多指令发布到新主题.在订阅/打印在一个够程完成,出版在另一个goroutine中进行.这是我的代码:
var wg, pg sync.WaitGroup
// All messages are handled here - printing published messages and publishing new messages
var f MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {
wg.Add(1)
pg.Add(1)
go func() {
defer wg.Done()
fmt.Printf("%s\n", msg.Payload())
//fmt.Println(os.Getpid())
}()
go func(){
defer pg.Done()
message := ""
//Changing configurations
if strings.Contains(string(msg.Payload()), "arduinoLED") == true {
message = fmt.Sprintf("change configuration")
}
if strings.Contains(string(msg.Payload()), "NAME CHANGED") == true{
message = fmt.Sprintf("change back")
}
// Publish further instructions to "sensor/instruction" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 nodejs 中获取 mqttjs 的工作示例。我在尝试使用node main.jsWindows 10 cmd 提示符中的命令执行我的 main.js 文件时收到此错误:
错误:
C:\Users\Rich\Documents\Code\nodejs\onoff\node_modules\mqtt\lib\connect\index.js:64
throw new Error('Missing protocol')
^
Error: Missing protocol
at Object.connect (C:\Users\Rich\Documents\Code\nodejs\onoff\node_modules\mqtt\lib\connect\index.js:64:13)
at Object.<anonymous> (C:\Users\Rich\Documents\Code\nodejs\onoff\main.js:2:20)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Run Code Online (Sandbox Code Playgroud)
代码:
var mqtt = require('mqtt');
var client = mqtt.connect('192.168.0.22');
client.on('connect', function () {
client.subscribe('mydevice')
client.publish('presence', 'Hello mqtt')
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString()) …Run Code Online (Sandbox Code Playgroud) 我创建了使用Meteor创建的APP,该App使用Mosquitto通过MQTT与某些硬件进行通信。它是在Linux计算机上完成的,每个人都运行良好。现在,我已将文件加载到OSX上,并收到以下错误消息。我尝试将sass更新到最新版本,然后重做npm安装,但无济于事。
=> A patch (Meteor 1.7.0.5) for your current release is available!
Update this project now with 'meteor update --patch'.
Errors prevented startup:
While loading package materialize:materialize@0.100.2:
error: Command failed: /Users/random/.meteor/packages/meteor- tool/.1.7.0_4.x53m8m.ifru9++os.osx.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.x86_64/dev_bundle/bin/npm rebuild --update-binary
Cannot download "https://github.com/sass/node- sass/releases/download/v4.5.2/darwin-x64-57_binding.node": HTTP error 404 Not Found
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个带有微服务的项目。
我对这个主题有一些疑问(有些不清楚):
1)如何实现微服务通信?
A) HTTP:每个微服务都会公开 HTTP API,即 API 网关广播请求。
B) MQTT:每个微服务发布/订阅到代理
C) 两者:但是如何理解一个比另一个更好呢?
即使对于通常通过 HTTP 执行的经典操作,我是否也必须使用 pub/sub 协议作为标准?例如我有两个微服务: 网络管理和Product-service。网络管理是一个面板,允许管理员在其电子商务数字商店中添加、修改...产品。假设我们要实现 createProduct 操作。它是一个命令(根据事件/命令区分),是一对一的通信。
我可以在产品服务中打开一个 API,比如说(POST,“/product”)来添加新产品。我还可以在ProductCreationRequest事件中实现此转换命令。在这种情况下:web-managemnet发布此事件。产品服务监听productCreationRequest事件(以及productUpdateRequest、productGetEvents等),一旦收到通知,它就会执行操作并发出productCreated事件。
我觉得这个案子很边缘化。例如,最后一次服务可以侦听ProductCreated并立即向客户发送消息(电子邮件或推送通知)。您对这个用例有何看法?
2)哪个可能是有效的代理(我将使用 docker-compose 或 kubernetes 来编排容器化微服务:采用的语言可能是 java、javascript、python)?
我正在使用 WebCrypto,但输出令人困惑。
以下测试用例使用新生成的 128 位密钥和 128 位随机 IV 加密随机 16 字节(128 位)纯文本,但输出 32 字节(256 位)输出。
如果我记得 AES-CBC 的细节,它应该输出 128 位块。
function test() {
var data = new Uint8Array(16);
window.crypto.getRandomValues(data);
console.log(data)
window.crypto.subtle.generateKey(
{
name: "AES-CBC",
length: 128,
},
false,
["encrypt", "decrypt"]
)
.then(function(key){
//returns a key object
console.log(key);
window.crypto.subtle.encrypt(
{
name: "AES-CBC",
iv: window.crypto.getRandomValues(new Uint8Array(16)),
},
key,
data
)
.then(function(encrypted){
console.log(new Uint8Array(encrypted));
})
.catch(function(err){
console.error(err);
});
})
.catch(function(err){
console.error(err);
});
}
Run Code Online (Sandbox Code Playgroud)
示例输出:
Uint8Array(16) [146, 207, 22, 56, 56, 151, 125, 174, …Run Code Online (Sandbox Code Playgroud)