Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

客户端收到的消息不是最新的 The message received by the client is not the latest #1948

Open
hn-lyf opened this issue Mar 14, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@hn-lyf
Copy link

hn-lyf commented Mar 14, 2024

首先使用mqttnet 创建了一个 Broker A, 端口 61883 ,
然后又启动第二个 Broker B , 端口 11883
然后开一个客户端链接 Broker A 订阅 Topic up/# 然后讲 收到的消息 发给Broker B (保留原样)

然后在开一个客户端 C 链接 Broker B 订阅 Topic up/# ,并打印出来 收到的日志

在开一个客户端 链接 Broker A 发送 Topic up/1... up/10000 一万个主题 内容为1,设置 retain 保留消息,发送完第二次后,把Broker B 重启,然后继续发送最新的 Topic up/1... up/10000 一万个主题,内容为 2 设置 retain 保留消息
客户端 C 立即重连后 C收到的数据 部分是最新的内容2 部分是旧数据1

单在开一个客户端 链接 Broker A 收到的 收到的数据是最新的

问题可能是在,Broker B, Broker B 下面的客户端订阅 Topic up/# 后,Broker 发送给客户端时,Broker 又收到最新的数据,但是 Broker 发送还没有完成,新收到的数据他认为本次已经发送了,所以导致客户端没收到最新的

我原本的需求是 有4级 Broker,分别是 A1->B1->C1->D1
每个Broker 有一个客户端链接到上一级,把本级Broker的数据发送到上一级
但是后面发现 可能重启 中间的B1 后,B1下面的客户端 订阅的主题 部分收不到retain 消息的最新的数据,是老的数据,
下面是我测试的例子
ConsoleApp51.zip

First created a Broker A, port 61883,
Then launch a second Broker B, port 11883
Then open a client link Broker A subscribe to Topic up / # and then send the received message to Broker B (remain as is)

Then open a client C link Broker B subscribe Topic up / # and print out the received log

In open a client link Broker A send Topic up / 1...] up / 10000 10000 topics content to 1, set retain retention message, send the second time, restart the Broker B, and then continue to send the latest Topic up / 1...] up / 1000010000 topics, content for 2 set retain retention message
Client C immediately reconnects after C received the data part is the latest content part 2 is the old data 1

The data received by Broker A after opening a client link is up-to-date

The problem may be that after the client below Broker B and Broker B subscribes to Topic up / #, when Broker sends it to the client, Broker receives the latest data, but Broker has not completed yet. He thinks the newly received data has been sent this time, so the client does not receive the latest data

My original requirement was to have a 4-level Broker, which was A1-> B1-> C1-> D1 respectively
Each Broker has a client link to the upper level, sending the data of the Broker to the upper level
But later I found that after you may restart the B1 in the middle, the subject part of the client subscription under B1 can not receive the latest data of the retain message, it is the old data,
Here is an example of my test
ConsoleApp51.zip

@hn-lyf hn-lyf added the bug Something isn't working label Mar 14, 2024
@hn-lyf
Copy link
Author

hn-lyf commented Mar 14, 2024

11883 的Topic[/up/4946/text] 值是 100000
image
订阅 61883的值是110000
image

@chkr1011
Copy link
Collaborator

Please share the code here. I will not download any ZIP files on my machine.

Also please check how you handle incoming messages? Are they handled in a separate thread/task?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants