vertx-mqtt icon indicating copy to clipboard operation
vertx-mqtt copied to clipboard

Unable to unsubscribe from multiple topics at once

Open ctron opened this issue 3 years ago • 6 comments

Describe the feature

Currently there is an unsubscribe method, which only allows to unsubscribe from a single topic. However, with MQTT you can unsubscribe from multiple topic filters at the same time.

Use cases

Unsubscribe from multiple topics, in a single message.

ctron avatar May 27 '21 16:05 ctron

Yeah, MQTT topic filters are a very important feature, look at the source implementation, it doesn't seem to do this specifically, right?

chenzhiguo avatar May 30 '21 15:05 chenzhiguo

@ctron would you like to contribute?

tsegismont avatar Oct 14 '21 13:10 tsegismont

I could draft up a PR. However I am not sure I can find the time to follow up on this to get it merged. I think this should come from the project.

ctron avatar Oct 15 '21 07:10 ctron

Hi @vietj i would like to contribute. Let me know what is the process.

SivaAkiro avatar Jul 26 '22 19:07 SivaAkiro

MqttClientImpl Class.

@Override public Future<Integer> unsubscribe(List<String> topics) {

MqttFixedHeader fixedHeader = new MqttFixedHeader(
  MqttMessageType.UNSUBSCRIBE,
  false,
  AT_LEAST_ONCE,
  false,
  0);

MqttMessageIdVariableHeader variableHeader = new MqttMessageIdAndPropertiesVariableHeader(
  nextMessageId(), MqttProperties.NO_PROPERTIES);

MqttUnsubscribePayload payload = new MqttUnsubscribePayload(topics);

io.netty.handler.codec.mqtt.MqttMessage unsubscribe = MqttMessageFactory.newMessage(fixedHeader,
  variableHeader, payload);

this.write(unsubscribe);

return ctx.succeededFuture(variableHeader.messageId());

}

Changed the corresponding other classes also.

Tested the same with sample server and client.

SivaAkiro avatar Jul 26 '22 21:07 SivaAkiro

you can read these

  • https://github.com/vert-x3/.github/blob/478611907c326b37f676db4e3657b19278aa64cb/CONTRIBUTING.md
  • https://docs.github.com/articles/github-community-guidelines

happy to have a PR @SivaAkiro

vietj avatar Jul 27 '22 09:07 vietj