-
Notifications
You must be signed in to change notification settings - Fork 76
Split the PubSub sample down into smaller samples #233
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
450b041
Split pubsub samples into smaller connect samples
TwistedTwigleg 0e6342e
Added builder creation functions to command line utils and simplified…
TwistedTwigleg 1809d46
Further simplification of existing samples
TwistedTwigleg abeb6f9
Adjusted README to fit latest changes
TwistedTwigleg c93cb31
Adjusted code based on code review:
TwistedTwigleg 2852b9c
Fixed websocket test passing region as the command instead of signing…
TwistedTwigleg d5b47df
Merge branch 'main' of https://github.com/aws/aws-iot-device-sdk-java…
TwistedTwigleg ed442d8
Adjusted WindowsCertPubSub to WindowsCertConnect. Modified to fit oth…
TwistedTwigleg 32b242b
Merge branch 'main' of https://github.com/aws/aws-iot-device-sdk-java…
TwistedTwigleg 0e9d093
Merge branch 'main' into PubSubSampleSplit
TwistedTwigleg fbd44bb
Merge branch 'main' into PubSubSampleSplit
TwistedTwigleg 45396de
Updated README to make command examples consistent
TwistedTwigleg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
env | ||
|
||
pushd $CODEBUILD_SRC_DIR/samples/BasicConnect | ||
|
||
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') | ||
|
||
mvn compile | ||
|
||
echo "Basic Mqtt (Direct) Connect test" | ||
mvn exec:java -Dexec.mainClass="basicconnect.BasicConnect" -Daws.crt.ci="True" -Dexec.arguments="--endpoint,$ENDPOINT,--key,/tmp/privatekey.pem,--cert,/tmp/certificate.pem" | ||
|
||
popd | ||
|
||
pushd $CODEBUILD_SRC_DIR/samples/WebsocketConnect | ||
|
||
mvn compile | ||
|
||
echo "Websocket Connect test" | ||
mvn exec:java -Dexec.mainClass="websocketconnect.WebsocketConnect" -Daws.crt.ci="True" -Dexec.arguments="--endpoint,$ENDPOINT,--signing_region,us-east-1,--port,443" | ||
|
||
popd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>software.amazon.awssdk.iotdevicesdk</groupId> | ||
<artifactId>BasicConnect</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>${project.groupId}:${project.artifactId}</name> | ||
<description>Java bindings for the AWS IoT Core Service</description> | ||
<url>https://github.com/awslabs/aws-iot-device-sdk-java-v2</url> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk.iotdevicesdk</groupId> | ||
<artifactId>aws-iot-device-sdk</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.4.0</version> | ||
<configuration> | ||
<mainclass>main</mainclass> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<executions> | ||
<execution> | ||
<id>add-source</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>../Utils/CommandLineUtils</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
95 changes: 95 additions & 0 deletions
95
samples/BasicConnect/src/main/java/basicconnect/BasicConnect.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
package basicconnect; | ||
|
||
import software.amazon.awssdk.crt.CRT; | ||
import software.amazon.awssdk.crt.CrtResource; | ||
import software.amazon.awssdk.crt.CrtRuntimeException; | ||
import software.amazon.awssdk.crt.io.ClientBootstrap; | ||
import software.amazon.awssdk.crt.mqtt.MqttClientConnection; | ||
import software.amazon.awssdk.crt.mqtt.MqttClientConnectionEvents; | ||
import software.amazon.awssdk.iot.iotjobs.model.RejectedError; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import utils.commandlineutils.CommandLineUtils; | ||
|
||
public class BasicConnect { | ||
|
||
// When run normally, we want to exit nicely even if something goes wrong | ||
// When run from CI, we want to let an exception escape which in turn causes the | ||
// exec:java task to return a non-zero exit code | ||
static String ciPropValue = System.getProperty("aws.crt.ci"); | ||
static boolean isCI = ciPropValue != null && Boolean.valueOf(ciPropValue); | ||
|
||
static CommandLineUtils cmdUtils; | ||
|
||
static void onRejectedError(RejectedError error) { | ||
System.out.println("Request rejected: " + error.code.toString() + ": " + error.message); | ||
} | ||
|
||
/* | ||
* When called during a CI run, throw an exception that will escape and fail the exec:java task | ||
* When called otherwise, print what went wrong (if anything) and just continue (return from main) | ||
*/ | ||
static void onApplicationFailure(Throwable cause) { | ||
if (isCI) { | ||
throw new RuntimeException("BasicConnect execution failure", cause); | ||
} else if (cause != null) { | ||
System.out.println("Exception encountered: " + cause.toString()); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
cmdUtils = new CommandLineUtils(); | ||
cmdUtils.registerProgramName("BasicConnect"); | ||
cmdUtils.addCommonMQTTCommands(); | ||
cmdUtils.addCommonProxyCommands(); | ||
cmdUtils.registerCommand("key", "<path>", "Path to your key in PEM format."); | ||
cmdUtils.registerCommand("cert", "<path>", "Path to your client certificate in PEM format."); | ||
cmdUtils.registerCommand("client_id", "<int>", "Client id to use (optional, default='test-*')."); | ||
cmdUtils.registerCommand("port", "<int>", "Port to connect to on the endpoint (optional, default='8883')."); | ||
cmdUtils.sendArguments(args); | ||
|
||
MqttClientConnectionEvents callbacks = new MqttClientConnectionEvents() { | ||
@Override | ||
public void onConnectionInterrupted(int errorCode) { | ||
if (errorCode != 0) { | ||
System.out.println("Connection interrupted: " + errorCode + ": " + CRT.awsErrorString(errorCode)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onConnectionResumed(boolean sessionPresent) { | ||
System.out.println("Connection resumed: " + (sessionPresent ? "existing session" : "clean session")); | ||
} | ||
}; | ||
|
||
try { | ||
|
||
// Create a connection using a certificate and key | ||
// Note: The data for the connection is gotten from cmdUtils. | ||
// (see buildDirectMQTTConnection for implementation) | ||
MqttClientConnection connection = cmdUtils.buildDirectMQTTConnection(callbacks); | ||
if (connection == null) | ||
{ | ||
onApplicationFailure(new RuntimeException("MQTT connection creation failed!")); | ||
} | ||
|
||
// Connect and disconnect using the connection we created | ||
// (see sampleConnectAndDisconnect for implementation) | ||
cmdUtils.sampleConnectAndDisconnect(connection); | ||
|
||
} catch (CrtRuntimeException | InterruptedException | ExecutionException ex) { | ||
onApplicationFailure(ex); | ||
} | ||
|
||
CrtResource.waitForNoResources(); | ||
System.out.println("Complete!"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.