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

feat(mqtt模拟器):新增断开重试参数 #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

445990772
Copy link
Contributor

No description provided.

Copy link
Member

@zhou-hao zhou-hao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重试时,似乎也不能触发脚本中的beforeConnect监听,无法自定义用户名密码规则。

if (counter > options.getReconnectAttempts() && !isAlive()) {
dispose();
} else {
Address localAddress = AddressManager.global().takeAddress(options.getLocalAddress());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应该获取新的地址吧?

dispose();
} else {
Address localAddress = AddressManager.global().takeAddress(options.getLocalAddress());
Disposables.composite()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposables.composite().add()没啥意义,应该将Disposable添加到当前client中,在手动断开时,能取消重试任务。

.flatMap(i -> Mono.<MqttClient>create(sink -> this.connect1(client, options, localAddress, sink)))
.subscribe(mqttClient -> {
log.info("客户端尝试重连:{},次数:{}", mqttClient.getId(), counter);
counter++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

连接失败时似乎并不会触发这里。


disposables = Mono.delay(Duration.ofMillis(options.getReconnectInterval()))
.doOnNext(i -> fallback.run())
.flatMap(i -> Mono.<MqttClient>create(sink -> this.connect1(client, options, this.address, sink, counter, fallback)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里重试不应该创建新的MqttClient,而是替换 当前对象中的 io.vertx.mqtt.MqttClient,否则可能无法发送消息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants