Skip to content

Commit a9ab56e

Browse files
authored
MqttMessage now contains qos, retain, dup (#132)
- MqttMessage now contains `qos` and `retain` members. Stop using deprecated methods which passed these as separate params. - use aws-crt-java v0.10.8
1 parent a3d61b2 commit a9ab56e

File tree

9 files changed

+34
-29
lines changed

9 files changed

+34
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mvn clean install
5050
``` sh
5151
# NOTE: use the latest version of the CRT here
5252

53-
git clone --branch v0.9.2 https://github.com/awslabs/aws-crt-java.git
53+
git clone --branch v0.10.8 https://github.com/awslabs/aws-crt-java.git
5454

5555
git clone https://github.com/awslabs/aws-iot-device-sdk-java-v2.git
5656
cd aws-crt-java
@@ -65,7 +65,7 @@ Supports API 26 or newer.
6565
NOTE: The shadow sample does not currently complete on android due to its dependence on stdin keyboard input.
6666

6767
``` sh
68-
git clone --recursive --branch v0.9.2 https://github.com/awslabs/aws-crt-java.git
68+
git clone --recursive --branch v0.10.8 https://github.com/awslabs/aws-crt-java.git
6969
git clone https://github.com/awslabs/aws-iot-device-sdk-java-v2.git
7070
cd aws-crt-java/android
7171
./gradlew connectedCheck # optional, will run the unit tests on any connected devices/emulators
@@ -86,7 +86,7 @@ repositories {
8686
}
8787
8888
dependencies {
89-
implementation 'software.amazon.awssdk.crt:android:0.9.2'
89+
implementation 'software.amazon.awssdk.crt:android:0.10.8'
9090
}
9191
```
9292

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ repositories {
5050
dependencies {
5151
implementation fileTree(dir: 'libs', include: ['*.jar'])
5252
implementation project(":iotdevicesdk")
53-
implementation 'software.amazon.awssdk.crt:android:0.9.2'
53+
implementation 'software.amazon.awssdk.crt:android:0.10.8'
5454
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5555
implementation 'androidx.appcompat:appcompat:1.1.0'
5656
implementation 'androidx.core:core:1.2.0'

android/iotdevicesdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ repositories {
8787

8888
dependencies {
8989
implementation fileTree(dir: 'libs', include: ['*.jar'])
90-
implementation 'software.amazon.awssdk.crt:android:0.9.2'
90+
implementation 'software.amazon.awssdk.crt:android:0.10.8'
9191
implementation 'com.google.code.gson:gson:2.8.5'
9292
implementation 'androidx.appcompat:appcompat:1.1.0'
9393
testImplementation 'junit:junit:4.12'

samples/BasicPubSub/src/main/java/pubsub/PubSub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public void onConnectionResumed(boolean sessionPresent) {
305305

306306
int count = 0;
307307
while (count++ < messagesToPublish) {
308-
CompletableFuture<Integer> published = connection.publish(new MqttMessage(topic, message.getBytes()), QualityOfService.AT_LEAST_ONCE, false);
308+
CompletableFuture<Integer> published = connection.publish(new MqttMessage(topic, message.getBytes(), QualityOfService.AT_LEAST_ONCE, false));
309309
published.get();
310310
Thread.sleep(1000);
311311
}

samples/Greengrass/src/main/java/greengrass/BasicDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static void main(String[] args) {
193193

194194
if ("publish".equals(mode) || "both".equals(mode)) {
195195
final CompletableFuture<Integer> publishResult = connection.publish(new MqttMessage(topic,
196-
input.getBytes(StandardCharsets.UTF_8)), QualityOfService.AT_MOST_ONCE, false);
196+
input.getBytes(StandardCharsets.UTF_8), QualityOfService.AT_MOST_ONCE, false));
197197
Integer result = publishResult.get();
198198
}
199199
}

samples/PubSubStress/src/main/java/pubsubstress/PubSubStress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public static void main(String[] args) {
372372
String publishTopic = validTopics.get(Math.abs(rng.nextInt()) % validTopics.size());
373373

374374
try {
375-
publishFutures.add(connection.publish(new MqttMessage(publishTopic, messageContent.getBytes()), QualityOfService.AT_LEAST_ONCE, false));
375+
publishFutures.add(connection.publish(new MqttMessage(publishTopic, messageContent.getBytes(), QualityOfService.AT_LEAST_ONCE, false)));
376376
} catch (Exception e) {
377377
System.out.println(String.format("Publishing Exception: %s", e.getMessage()));
378378
}

samples/RawPubSub/src/main/java/rawpubsub/RawPubSub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void onConnectionResumed(boolean sessionPresent) {
230230

231231
int count = 0;
232232
while (count++ < messagesToPublish) {
233-
CompletableFuture<Integer> published = connection.publish(new MqttMessage(topic, message.getBytes()), QualityOfService.AT_LEAST_ONCE, false);
233+
CompletableFuture<Integer> published = connection.publish(new MqttMessage(topic, message.getBytes(), QualityOfService.AT_LEAST_ONCE, false));
234234
published.get();
235235
Thread.sleep(1000);
236236
}

sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>software.amazon.awssdk.crt</groupId>
4444
<artifactId>aws-crt</artifactId>
45-
<version>0.10.3</version>
45+
<version>0.10.8</version>
4646
</dependency>
4747
<dependency>
4848
<groupId>junit</groupId>

sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqttConnectionBuilder.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected void releaseNativeHandle() {}
9090

9191
/**
9292
* Create a new builder with mTLS file paths
93-
*
93+
*
9494
* @param certPath - Path to certificate, in PEM format
9595
* @param privateKeyPath - Path to private key, in PEM format
9696
*/
@@ -102,7 +102,7 @@ public static AwsIotMqttConnectionBuilder newMtlsBuilderFromPath(String certPath
102102

103103
/**
104104
* Create a new builder with mTLS cert pair in memory
105-
*
105+
*
106106
* @param certificate - Certificate, in PEM format
107107
* @param privateKey - Private key, in PEM format
108108
*/
@@ -114,7 +114,7 @@ public static AwsIotMqttConnectionBuilder newMtlsBuilder(String certificate, Str
114114

115115
/**
116116
* Create a new builder with mTLS cert pair in memory
117-
*
117+
*
118118
* @param certificate - Certificate, in PEM format
119119
* @param privateKey - Private key, in PEM format
120120
*/
@@ -137,7 +137,7 @@ public static AwsIotMqttConnectionBuilder newDefaultBuilder()
137137

138138
/**
139139
* Overrides the default system trust store.
140-
*
140+
*
141141
* @param caDirPath - Only used on Unix-style systems where all trust anchors
142142
* are stored in a directory (e.g. /etc/ssl/certs).
143143
* @param caFilePath - Single file containing all trust CAs, in PEM format
@@ -150,7 +150,7 @@ public AwsIotMqttConnectionBuilder withCertificateAuthorityFromPath(String caDir
150150

151151
/**
152152
* Overrides the default system trust store.
153-
*
153+
*
154154
* @param caRoot - Buffer containing all trust CAs, in PEM format
155155
*/
156156
public AwsIotMqttConnectionBuilder withCertificateAuthority(String caRoot) {
@@ -161,7 +161,7 @@ public AwsIotMqttConnectionBuilder withCertificateAuthority(String caRoot) {
161161

162162
/**
163163
* Configures the IoT endpoint for connections from this builder.
164-
*
164+
*
165165
* @param endpoint The IoT endpoint to connect to
166166
*/
167167
public AwsIotMqttConnectionBuilder withEndpoint(String endpoint) {
@@ -172,7 +172,7 @@ public AwsIotMqttConnectionBuilder withEndpoint(String endpoint) {
172172
/**
173173
* Configures the port to connect to for connections from this builder. If not set, 443 will be used for
174174
* a websocket connection or where ALPN support is available. Otherwise the default is 8883.
175-
*
175+
*
176176
* @param port The port to connect to on the IoT endpoint. Usually 8883 for
177177
* MQTT, or 443 for websockets
178178
*/
@@ -183,7 +183,7 @@ public AwsIotMqttConnectionBuilder withPort(short port) {
183183

184184
/**
185185
* Configures the client id to use to connect to the IoT Core service.
186-
*
186+
*
187187
* @param clientId The client id for connections from this builder. Needs to be unique across
188188
* all devices/clients.
189189
*/
@@ -195,7 +195,7 @@ public AwsIotMqttConnectionBuilder withClientId(String clientId) {
195195
/**
196196
* Configures whether or not the service should try to resume prior
197197
* subscriptions, if it has any
198-
*
198+
*
199199
* @param cleanSession true if the session should drop prior subscriptions when
200200
* a connection from this builder is established, false to resume the session
201201
*/
@@ -207,7 +207,7 @@ public AwsIotMqttConnectionBuilder withCleanSession(boolean cleanSession) {
207207
/**
208208
* Configures MQTT keep-alive via PING messages. Note that this is not TCP
209209
* keepalive.
210-
*
210+
*
211211
* @param keepAliveMs How often in milliseconds to send an MQTT PING message to the
212212
* service to keep connections alive
213213
*/
@@ -230,7 +230,7 @@ public AwsIotMqttConnectionBuilder withPingTimeoutMs(int pingTimeoutMs) {
230230

231231
/**
232232
* Configures the TCP socket connect timeout (in milliseconds)
233-
*
233+
*
234234
* @param timeoutMs TCP socket timeout
235235
*/
236236
public AwsIotMqttConnectionBuilder withTimeoutMs(int timeoutMs) {
@@ -240,7 +240,7 @@ public AwsIotMqttConnectionBuilder withTimeoutMs(int timeoutMs) {
240240

241241
/**
242242
* Configures the common settings for the socket to use for connections created by this builder
243-
*
243+
*
244244
* @param socketOptions The socket settings
245245
*/
246246
public AwsIotMqttConnectionBuilder withSocketOptions(SocketOptions socketOptions) {
@@ -283,19 +283,24 @@ public AwsIotMqttConnectionBuilder withConnectionEventCallbacks(MqttClientConnec
283283
* disconnects
284284
*
285285
* @param message The message to publish as the will. The message contains the
286-
* topic that the message will be published to on disconnect.
287-
* @param qos The {@link QualityOfService} of the will message
288-
* @param retain Whether or not the message should be retained by the mqtt broker to
289-
* be delivered to future subscribers
286+
* topic that the message will be published to on disconnect,
287+
* along with the {@link QualityOfService} that it will be
288+
* published with and whether it will be retained when it is published.
290289
*/
291-
public AwsIotMqttConnectionBuilder withWill(MqttMessage message, QualityOfService qos, boolean retain) throws MqttException {
290+
public AwsIotMqttConnectionBuilder withWill(MqttMessage message) throws MqttException {
292291
this.config.setWillMessage(message);
293-
this.config.setWillQos(qos);
294-
this.config.setWillRetain(retain);
295292

296293
return this;
297294
}
298295

296+
/**
297+
* @deprecated Use alternate withWill(). QoS and retain are now set directly on the {@link MqttMessage}
298+
*/
299+
@Deprecated
300+
public AwsIotMqttConnectionBuilder withWill(MqttMessage message, QualityOfService qos, boolean retain) throws MqttException {
301+
return withWill(new MqttMessage(message.getTopic(), message.getPayload(), qos, retain));
302+
}
303+
299304
/**
300305
* Configures the client bootstrap to use for connections created by this builder
301306
*

0 commit comments

Comments
 (0)