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

fixed #85 require an messageId and send message with it #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/io/vertx/mqtt/MqttEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,24 @@ public interface MqttEndpoint {
@Fluent
MqttEndpoint publish(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain);

/**
* Sends the PUBLISH message with specified messageId to the remote MQTT client
*
* @param topic topic on which the message is published
* @param payload message payload
* @param qosLevel quality of service level
* @param isDup if the message is a duplicate
* @param isRetain if the message needs to be retained
* @return a reference to this, so the API can be used fluently
*/
@Fluent
MqttEndpoint publishWithId(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain,int messageId);
Copy link
Contributor

Choose a reason for hiding this comment

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

How can a message Id generated by hands be useful?


/**
* require an messageId
* @return the next messageId
*/
int requireMessageId();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a purpose of this?

/**
* Sends the PINGRESP message to the remote MQTT client
*
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,18 @@ public MqttEndpointImpl publishComplete(int publishMessageId) {
}

public MqttEndpointImpl publish(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain) {
publishWithId(topic, payload, qosLevel, isDup, isRetain, nextMessageId());
return this;
}

@Override
public MqttEndpointImpl publishWithId(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain, int messageId) {
this.checkConnected();

MqttFixedHeader fixedHeader =
new MqttFixedHeader(MqttMessageType.PUBLISH, isDup, qosLevel, isRetain, 0);
MqttPublishVariableHeader variableHeader =
new MqttPublishVariableHeader(topic, this.nextMessageId());
new MqttPublishVariableHeader(topic, messageId);

ByteBuf buf = Unpooled.copiedBuffer(payload.getBytes());

Expand All @@ -442,6 +447,11 @@ public MqttEndpointImpl publish(String topic, Buffer payload, MqttQoS qosLevel,
return this;
}

@Override
public int requireMessageId() {
return 0;
}

public MqttEndpointImpl pong() {

this.checkConnected();
Expand Down