From 5519b1074db3e2021e48f026dfa4d18b6aa02e73 Mon Sep 17 00:00:00 2001 From: Devis Lucato Date: Wed, 25 Jan 2017 15:52:41 -0800 Subject: [PATCH] Upgrade dependencies and improve demos --- .travis.yml | 2 +- README.md | 20 +++---- build.sbt | 58 ++++++++++++------- run_java_samples.cmd | 18 ++++++ run_java_samples.sh | 20 +++++++ run_scala_samples.cmd | 1 + run_scala_samples.sh | 1 + samples-java/build.sbt | 3 + samples-java/pom.xml | 2 +- samples-java/project/build.properties | 1 + samples-java/run_samples.cmd | 2 - samples-java/run_samples.sh | 2 - .../DisplayMessages/{Demo.java => Main.java} | 5 +- .../DisplayMessages/ReactiveStreamingApp.java | 4 +- .../{Demo.java => Main.java} | 3 +- .../ReactiveStreamingApp.java | 1 - .../src/main/resources/application.conf | 6 +- samples-scala/build.sbt | 20 ++----- samples-scala/project/build.properties | 2 +- samples-scala/run_samples.cmd | 1 - samples-scala/run_samples.sh | 1 - samples-scala/setup-env-vars.bat | 41 ------------- samples-scala/setup-env-vars.ps1 | 41 ------------- samples-scala/setup-env-vars.sh | 41 ------------- .../src/main/resources/application.conf | 2 +- .../src/main/scala/A_APIUSage/Demo.scala | 2 +- .../setup-env-vars.bat => setup-env-vars.bat | 0 .../setup-env-vars.ps1 => setup-env-vars.ps1 | 0 .../setup-env-vars.sh => setup-env-vars.sh | 0 .../iot/iothubreact/MessageFromDevice.scala | 5 +- .../iot/iothubreact/MessageToDevice.scala | 2 +- .../azure/iot/iothubreact/StreamManager.scala | 13 +++-- .../iot/iothubreact/scaladsl/IoTHub.scala | 2 +- .../sinks/MessageToDeviceSink.scala | 2 +- src/test/scala/it/helpers/Device.scala | 2 +- 35 files changed, 127 insertions(+), 199 deletions(-) create mode 100644 run_java_samples.cmd create mode 100755 run_java_samples.sh create mode 100644 run_scala_samples.cmd create mode 100755 run_scala_samples.sh create mode 100644 samples-java/build.sbt create mode 100644 samples-java/project/build.properties delete mode 100755 samples-java/run_samples.cmd delete mode 100755 samples-java/run_samples.sh rename samples-java/src/main/java/DisplayMessages/{Demo.java => Main.java} (96%) rename samples-java/src/main/java/SendMessageToDevice/{Demo.java => Main.java} (96%) delete mode 100755 samples-scala/run_samples.cmd delete mode 100755 samples-scala/run_samples.sh delete mode 100644 samples-scala/setup-env-vars.bat delete mode 100644 samples-scala/setup-env-vars.ps1 delete mode 100644 samples-scala/setup-env-vars.sh rename samples-java/setup-env-vars.bat => setup-env-vars.bat (100%) rename samples-java/setup-env-vars.ps1 => setup-env-vars.ps1 (100%) rename samples-java/setup-env-vars.sh => setup-env-vars.sh (100%) diff --git a/.travis.yml b/.travis.yml index b418f54..8bbfec5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ jdk: oraclejdk8 language: scala scala: - 2.11.8 - - 2.12.0 + - 2.12.1 cache: directories: - "$HOME/.ivy2" diff --git a/README.md b/README.md index a0edea5..e25295a 100644 --- a/README.md +++ b/README.md @@ -293,8 +293,8 @@ The complete configuration reference (and default value) is available in ## Samples -The project includes multiple demos, showing some of the use cases and how IoThub React API works. -All the demos require an instance of Azure IoT hub, with some devices and messages. +The project includes multiple demos in Java and Scala, showing some of the use cases and how IoThub +React API works. All the demos require an instance of Azure IoT hub, with some devices and messages. 1. **DisplayMessages** [Java]: how to stream Azure IoT hub withing a Java application, filtering temperature values greater than 60C @@ -320,7 +320,7 @@ All the demos require an instance of Azure IoT hub, with some devices and messag connected devices. We provide a [device simulator](tools/devices-simulator/README.md) in the tools section, -which will help simulating some devices sending sample telemetry. +which will help simulating some devices sending sample telemetry messages. When ready, you should either edit the `application.conf` configuration files ([scala](samples-scala/src/main/resources/application.conf) and @@ -328,14 +328,14 @@ When ready, you should either edit the `application.conf` configuration files with your credentials, or set the corresponding environment variables. Follow the instructions in the previous section on how to set the correct values. -The sample folders include also some scripts showing how to setup the environment variables in -[Linux/MacOS](samples-scala/setup-env-vars.sh) and [Windows](samples-scala/setup-env-vars.bat). +The root folder includes also a script showing how to set the environment variables in +[Linux/MacOS](setup-env-vars.sh) and [Windows](setup-env-vars.bat). -* [`samples-scala`](samples-scala/src/main/scala): - You can use `sbt run` to run the demos (or the `run_samples.*` scripts) -* [`samples-java`](samples-java/src/main/java): - You can use `mvn clean compile exec:java -Dexec.mainClass="DisplayMessages.Demo"` to run the - demo app (or the `run_samples.*` scripts) +The demos can be executed using the scripts included in the root folder (`run__samples.sh` +and `run__samples.cmd`): + +* [`run_scala_samples.sh`](run_scala_samples.sh): execute Scala demos +* [`run_java_samples.sh`](run_java_samples.sh): execute Java demos ## Future work (MoSCoW) diff --git a/build.sbt b/build.sbt index 4d8c381..94e78db 100644 --- a/build.sbt +++ b/build.sbt @@ -3,40 +3,54 @@ name := "iothub-react" organization := "com.microsoft.azure.iot" -version := "0.8.0" -//version := "0.8.0-DEV.170106a" +//version := "0.9.0" +version := "0.9.0-DEV.170307a" scalaVersion := "2.12.1" crossScalaVersions := Seq("2.11.8", "2.12.1") libraryDependencies <++= (scalaVersion) { scalaVersion ⇒ - val azureEventHubSDKVersion = "0.9.0" - val azureStorageSDKVersion = "4.4.0" - val iothubDeviceClientVersion = "1.0.15" - val iothubServiceClientVersion = "1.0.10" - val scalaTestVersion = "3.0.1" - val datastaxDriverVersion = "3.1.1" + val json4sVersion = "3.5.0" - val akkaStreamVersion = "2.4.16" Seq( - // Library dependencies - "com.microsoft.azure.iothub-java-client" % "iothub-java-service-client" % iothubServiceClientVersion, - "com.microsoft.azure" % "azure-eventhubs" % azureEventHubSDKVersion, - "com.microsoft.azure" % "azure-storage" % azureStorageSDKVersion, - "com.datastax.cassandra" % "cassandra-driver-core" % datastaxDriverVersion, - "com.typesafe.akka" %% "akka-stream" % akkaStreamVersion, - "org.json4s" %% "json4s-native" % json4sVersion, - "org.json4s" %% "json4s-jackson" % json4sVersion, + // https://github.com/Azure/azure-iot-sdk-java/releases + "com.microsoft.azure.sdk.iot" % "iot-service-client" % "1.0.14", - // Tests dependencies - "org.scalatest" %% "scalatest" % scalaTestVersion % "test", - "com.microsoft.azure.iothub-java-client" % "iothub-java-device-client" % iothubDeviceClientVersion % "test" + // https://github.com/Azure/azure-event-hubs-java/releases + "com.microsoft.azure" % "azure-eventhubs" % "0.11.0", + + // https://github.com/Azure/azure-storage-java/releases + "com.microsoft.azure" % "azure-storage" % "5.0.0", + + // http://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core + "com.datastax.cassandra" % "cassandra-driver-core" % "3.1.4", + + // https://github.com/akka/akka/releases + "com.typesafe.akka" %% "akka-stream" % "2.4.17", + + // https://github.com/json4s/json4s/releases + "org.json4s" %% "json4s-native" % json4sVersion, + "org.json4s" %% "json4s-jackson" % json4sVersion ) } -lazy val root = project.in(file(".")).configs(IntegrationTest) +// Test dependencies +libraryDependencies <++= (scalaVersion) { + scalaVersion ⇒ + Seq( + // https://github.com/scalatest/scalatest/releases + "org.scalatest" %% "scalatest" % "3.0.1" % "test", + + // https://github.com/Azure/azure-iot-sdk-java/releases + "com.microsoft.azure.sdk.iot" % "iot-device-client" % "1.0.19" % "test" + ) +} + +lazy val iotHubReact = project.in(file(".")).configs(IntegrationTest) +lazy val samplesScala = project.in(file("samples-scala")).dependsOn(iotHubReact) +lazy val samplesJava = project.in(file("samples-java")).dependsOn(iotHubReact) /* Publishing options * see http://www.scala-sbt.org/0.13/docs/Artifacts.html @@ -70,7 +84,7 @@ pomExtra := /** Miscs */ -logLevel := Level.Debug // Debug|Info|Warn|Error +logLevel := Level.Warn // Debug|Info|Warn|Error scalacOptions ++= Seq("-deprecation", "-explaintypes", "-unchecked", "-feature") showTiming := true fork := true diff --git a/run_java_samples.cmd b/run_java_samples.cmd new file mode 100644 index 0000000..c2836bc --- /dev/null +++ b/run_java_samples.cmd @@ -0,0 +1,18 @@ +@ECHO OFF + +REM sbt samplesJava/run + +ECHO Select demo to run: +ECHO. +ECHO [1] DisplayMessages.Main +ECHO [2] SendMessageToDevice.Main +ECHO. + +SET /P opt="Enter number: " + +cd samples-java + +if "%opt%"=="1" mvn clean compile exec:java -Dexec.mainClass="DisplayMessages.Main" +if "%opt%"=="2" mvn clean compile exec:java -Dexec.mainClass="SendMessageToDevice.Main" + + diff --git a/run_java_samples.sh b/run_java_samples.sh new file mode 100755 index 0000000..7110ad3 --- /dev/null +++ b/run_java_samples.sh @@ -0,0 +1,20 @@ +#sbt samplesJava/run + +echo "Select demo to run:" +echo +echo " [1] DisplayMessages.Main" +echo " [2] SendMessageToDevice.Main" +echo +read -p "Enter number: " -r opt + +cd samples-java + +if [ "$opt" = "1" ]; then + mvn clean compile exec:java -Dexec.mainClass="DisplayMessages.Main" +fi + +if [ "$opt" = "2" ]; then + mvn clean compile exec:java -Dexec.mainClass="SendMessageToDevice.Main" +fi + + diff --git a/run_scala_samples.cmd b/run_scala_samples.cmd new file mode 100644 index 0000000..7530155 --- /dev/null +++ b/run_scala_samples.cmd @@ -0,0 +1 @@ +sbt samplesScala/run diff --git a/run_scala_samples.sh b/run_scala_samples.sh new file mode 100755 index 0000000..7530155 --- /dev/null +++ b/run_scala_samples.sh @@ -0,0 +1 @@ +sbt samplesScala/run diff --git a/samples-java/build.sbt b/samples-java/build.sbt new file mode 100644 index 0000000..c0e60b6 --- /dev/null +++ b/samples-java/build.sbt @@ -0,0 +1,3 @@ +// Copyright (c) Microsoft. All rights reserved. + +scalaVersion := "2.12.1" diff --git a/samples-java/pom.xml b/samples-java/pom.xml index 1583feb..88f393c 100644 --- a/samples-java/pom.xml +++ b/samples-java/pom.xml @@ -19,7 +19,7 @@ com.microsoft.azure.iot iothub-react_2.12 - 0.8.0-DEV.161101a + 0.8.0 com.fasterxml.jackson.core diff --git a/samples-java/project/build.properties b/samples-java/project/build.properties new file mode 100644 index 0000000..27e88aa --- /dev/null +++ b/samples-java/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.13 diff --git a/samples-java/run_samples.cmd b/samples-java/run_samples.cmd deleted file mode 100755 index 87f66a0..0000000 --- a/samples-java/run_samples.cmd +++ /dev/null @@ -1,2 +0,0 @@ -mvn clean compile exec:java -Dexec.mainClass="DisplayMessages.Demo" - diff --git a/samples-java/run_samples.sh b/samples-java/run_samples.sh deleted file mode 100755 index 87f66a0..0000000 --- a/samples-java/run_samples.sh +++ /dev/null @@ -1,2 +0,0 @@ -mvn clean compile exec:java -Dexec.mainClass="DisplayMessages.Demo" - diff --git a/samples-java/src/main/java/DisplayMessages/Demo.java b/samples-java/src/main/java/DisplayMessages/Main.java similarity index 96% rename from samples-java/src/main/java/DisplayMessages/Demo.java rename to samples-java/src/main/java/DisplayMessages/Main.java index 9c394c8..94ab853 100644 --- a/samples-java/src/main/java/DisplayMessages/Demo.java +++ b/samples-java/src/main/java/DisplayMessages/Main.java @@ -8,8 +8,8 @@ import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import com.fasterxml.jackson.databind.ObjectMapper; import com.microsoft.azure.iot.iothubreact.MessageFromDevice; -import com.microsoft.azure.iot.iothubreact.javadsl.PartitionList; import com.microsoft.azure.iot.iothubreact.javadsl.IoTHub; +import com.microsoft.azure.iot.iothubreact.javadsl.PartitionList; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -22,7 +22,7 @@ import static java.lang.System.out; /** * Retrieve messages from IoT hub and display the data in the console */ -public class Demo extends ReactiveStreamingApp +public class Main extends ReactiveStreamingApp { static ObjectMapper jsonParser = new ObjectMapper(); @@ -56,6 +56,7 @@ public class Demo extends ReactiveStreamingApp }); } + @SuppressWarnings("unchecked") public static Temperature parseTemperature(MessageFromDevice m) { try diff --git a/samples-java/src/main/java/DisplayMessages/ReactiveStreamingApp.java b/samples-java/src/main/java/DisplayMessages/ReactiveStreamingApp.java index 227000b..ed87e17 100644 --- a/samples-java/src/main/java/DisplayMessages/ReactiveStreamingApp.java +++ b/samples-java/src/main/java/DisplayMessages/ReactiveStreamingApp.java @@ -9,8 +9,8 @@ import akka.stream.Materializer; /** * Initialize reactive streaming */ -public class ReactiveStreamingApp { - +public class ReactiveStreamingApp +{ private static ActorSystem system = ActorSystem.create("Demo"); protected final static Materializer streamMaterializer = ActorMaterializer.create(system); diff --git a/samples-java/src/main/java/SendMessageToDevice/Demo.java b/samples-java/src/main/java/SendMessageToDevice/Main.java similarity index 96% rename from samples-java/src/main/java/SendMessageToDevice/Demo.java rename to samples-java/src/main/java/SendMessageToDevice/Main.java index 33d6954..bea6664 100644 --- a/samples-java/src/main/java/SendMessageToDevice/Demo.java +++ b/samples-java/src/main/java/SendMessageToDevice/Main.java @@ -22,7 +22,7 @@ import static java.lang.System.out; /** * Retrieve messages from IoT hub and display the data in the console */ -public class Demo extends ReactiveStreamingApp +public class Main extends ReactiveStreamingApp { static ObjectMapper jsonParser = new ObjectMapper(); @@ -63,6 +63,7 @@ public class Demo extends ReactiveStreamingApp }); } + @SuppressWarnings("unchecked") public static Temperature parseTemperature(MessageFromDevice m) { try diff --git a/samples-java/src/main/java/SendMessageToDevice/ReactiveStreamingApp.java b/samples-java/src/main/java/SendMessageToDevice/ReactiveStreamingApp.java index aaa2f27..0adeccc 100644 --- a/samples-java/src/main/java/SendMessageToDevice/ReactiveStreamingApp.java +++ b/samples-java/src/main/java/SendMessageToDevice/ReactiveStreamingApp.java @@ -11,7 +11,6 @@ import akka.stream.Materializer; */ public class ReactiveStreamingApp { - private static ActorSystem system = ActorSystem.create("Demo"); protected final static Materializer streamMaterializer = ActorMaterializer.create(system); diff --git a/samples-java/src/main/resources/application.conf b/samples-java/src/main/resources/application.conf index db8715e..71c88f3 100644 --- a/samples-java/src/main/resources/application.conf +++ b/samples-java/src/main/resources/application.conf @@ -3,7 +3,7 @@ // @see http://doc.akka.io/docs/akka/2.4.10/scala/logging.html akka { # Options: OFF, ERROR, WARNING, INFO, DEBUG - loglevel = "INFO" + loglevel = "DEBUG" } iothub-react { @@ -51,7 +51,7 @@ iothub-react { // Checkpoints frequency (best effort), for each IoT hub partition // Min: 1 second, Max: 1 minute - frequency = 10s + frequency = 5s // How many messages to stream before saving the position, for each IoT hub partition. // Since the stream position is saved in the Source, before the rest of the @@ -62,7 +62,7 @@ iothub-react { // Store a position if its value is older than this amount of time, ignoring the threshold. // For instance when the telemetry stops, this will force to write the last offset after some time. // Min: 1 second, Max: 1 hour. Value is rounded to seconds. - timeThreshold = 30s + timeThreshold = 10s storage { diff --git a/samples-scala/build.sbt b/samples-scala/build.sbt index 12d7b84..e6daed3 100644 --- a/samples-scala/build.sbt +++ b/samples-scala/build.sbt @@ -1,18 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. -scalaVersion := "2.12.0" -crossScalaVersions := Seq("2.11.8", "2.12.0") +scalaVersion := "2.12.1" -scalacOptions ++= Seq("-deprecation", "-explaintypes", "-unchecked", "-feature") - -// This repository contains development snapshots. Production releases are in Maven Central. -resolvers += "Dev Snapshots" at "https://dl.bintray.com/microsoftazuretoketi/toketi-repo" - -libraryDependencies ++= { - val prodVersion = "0.7.0" - val devVersion = "0.8.0-DEV.161101a" - - Seq( - "com.microsoft.azure.iot" %% "iothub-react" % devVersion - ) +libraryDependencies <++= (scalaVersion) { + scalaVersion ⇒ + Seq( + "com.microsoft.azure" % "azure-eventhubs-eph" % "0.11.0" + ) } diff --git a/samples-scala/project/build.properties b/samples-scala/project/build.properties index 13d3ee7..27e88aa 100644 --- a/samples-scala/project/build.properties +++ b/samples-scala/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.12 \ No newline at end of file +sbt.version=0.13.13 diff --git a/samples-scala/run_samples.cmd b/samples-scala/run_samples.cmd deleted file mode 100755 index 7c9cf44..0000000 --- a/samples-scala/run_samples.cmd +++ /dev/null @@ -1 +0,0 @@ -sbt run diff --git a/samples-scala/run_samples.sh b/samples-scala/run_samples.sh deleted file mode 100755 index 7c9cf44..0000000 --- a/samples-scala/run_samples.sh +++ /dev/null @@ -1 +0,0 @@ -sbt run diff --git a/samples-scala/setup-env-vars.bat b/samples-scala/setup-env-vars.bat deleted file mode 100644 index 62dfdbd..0000000 --- a/samples-scala/setup-env-vars.bat +++ /dev/null @@ -1,41 +0,0 @@ -:: Populate the following environment variables, and execute this file before running -:: IoT Hub to Cassandra. -:: -:: For more information about where to find these values, more information here: -:: -:: * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal#endpoints -:: * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-java-java-getstarted -:: -:: -:: Example: -:: -:: SET IOTHUB_EVENTHUB_NAME = "my-iothub-one" -:: -:: SET IOTHUB_EVENTHUB_ENDPOINT = "sb://iothub-ns-myioth-75186-9fb862f912.servicebus.windows.net/" -:: -:: SET IOTHUB_EVENTHUB_PARTITIONS = 4 -:: -:: SET IOTHUB_IOTHUB_ACCESS_POLICY = "service" -:: -:: SET IOTHUB_ACCESS_KEY = "6XdRSFB9H61f+N3uOdBJiKwzeqbZUj1K//T2jFyewN4=" -:: -:: SET IOTHUB_ACCESS_HOSTNAME = "my-iothub-one.azure-devices.net" -:: - -:: see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible name" -SET IOTHUB_EVENTHUB_NAME = "" - -:: see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible endpoint" -SET IOTHUB_EVENTHUB_ENDPOINT = "" - -:: see: Endpoints ⇒ Messaging ⇒ Events ⇒ Partitions -SET IOTHUB_EVENTHUB_PARTITIONS = "" - -:: see: Shared access policies, we suggest to use "service" here -SET IOTHUB_IOTHUB_ACCESS_POLICY = "" - -:: see: Shared access policies ⇒ key name ⇒ Primary key -SET IOTHUB_ACCESS_KEY = "" - -:: see: Shared access policies ⇒ key name ⇒ Connection string ⇒ HostName -SET IOTHUB_ACCESS_HOSTNAME = "" diff --git a/samples-scala/setup-env-vars.ps1 b/samples-scala/setup-env-vars.ps1 deleted file mode 100644 index 0e8fa7a..0000000 --- a/samples-scala/setup-env-vars.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -# Populate the following environment variables, and execute this file before running -# IoT Hub to Cassandra. -# -# For more information about where to find these values, more information here: -# -# * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal#endpoints -# * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-java-java-getstarted -# -# -# Example: -# -# $env:IOTHUB_EVENTHUB_NAME = 'my-iothub-one' -# -# $env:IOTHUB_EVENTHUB_ENDPOINT = 'sb://iothub-ns-myioth-75186-9fb862f912.servicebus.windows.net/' -# -# $env:IOTHUB_EVENTHUB_PARTITIONS = 4 -# -# $env:IOTHUB_IOTHUB_ACCESS_POLICY = 'service' -# -# $env:IOTHUB_ACCESS_KEY = '6XdRSFB9H61f+N3uOdBJiKwzeqbZUj1K//T2jFyewN4=' -# -# SET IOTHUB_ACCESS_HOSTNAME = "my-iothub-one.azure-devices.net" -# - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible name" -$env:IOTHUB_EVENTHUB_NAME = '' - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible endpoint" -$env:IOTHUB_EVENTHUB_ENDPOINT = '' - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ Partitions -$env:IOTHUB_EVENTHUB_PARTITIONS = '' - -# see: Shared access policies, we suggest to use "service" here -$env:IOTHUB_IOTHUB_ACCESS_POLICY = '' - -# see: Shared access policies ⇒ key name ⇒ Primary key -$env:IOTHUB_ACCESS_KEY = '' - -# see: Shared access policies ⇒ key name ⇒ Connection string ⇒ HostName -$env:IOTHUB_ACCESS_HOSTNAME = '' diff --git a/samples-scala/setup-env-vars.sh b/samples-scala/setup-env-vars.sh deleted file mode 100644 index b9a5717..0000000 --- a/samples-scala/setup-env-vars.sh +++ /dev/null @@ -1,41 +0,0 @@ -# Populate the following environment variables, and execute this file before running -# IoT Hub to Cassandra. -# -# For more information about where to find these values, more information here: -# -# * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal#endpoints -# * https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-java-java-getstarted -# -# -# Example: -# -# export IOTHUB_EVENTHUB_NAME="my-iothub-one" -# -# export IOTHUB_EVENTHUB_ENDPOINT="sb://iothub-ns-myioth-75186-9fb862f912.servicebus.windows.net/" -# -# export IOTHUB_EVENTHUB_PARTITIONS=4 -# -# export IOTHUB_IOTHUB_ACCESS_POLICY="service" -# -# export IOTHUB_ACCESS_KEY="6XdRSFB9H61f+N3uOdBJiKwzeqbZUj1K//T2jFyewN4=" -# -# export IOTHUB_ACCESS_HOSTNAME="my-iothub-one.azure-devices.net" -# - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible name" -export IOTHUB_EVENTHUB_NAME="" - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ "Event Hub-compatible endpoint" -export IOTHUB_EVENTHUB_ENDPOINT="" - -# see: Endpoints ⇒ Messaging ⇒ Events ⇒ Partitions -export IOTHUB_EVENTHUB_PARTITIONS="" - -# see: Shared access policies, we suggest to use "service" here -export IOTHUB_IOTHUB_ACCESS_POLICY="" - -# see: Shared access policies ⇒ key name ⇒ Primary key -export IOTHUB_ACCESS_KEY="" - -# see: Shared access policies ⇒ key name ⇒ Connection string ⇒ HostName -export IOTHUB_ACCESS_HOSTNAME="" diff --git a/samples-scala/src/main/resources/application.conf b/samples-scala/src/main/resources/application.conf index 51ef0df..a1ae534 100644 --- a/samples-scala/src/main/resources/application.conf +++ b/samples-scala/src/main/resources/application.conf @@ -22,7 +22,7 @@ iothub-react { // see: Endpoints ⇒ Messaging ⇒ Events ⇒ Partitions hubPartitions = ${?IOTHUB_EVENTHUB_PARTITIONS} - // see: Shared access policies + // see: "IoT Hub" ⇒ your hub ⇒ "Shared access policies" // e.g. you should use the predefined "service" policy accessPolicy = ${?IOTHUB_ACCESS_POLICY} diff --git a/samples-scala/src/main/scala/A_APIUSage/Demo.scala b/samples-scala/src/main/scala/A_APIUSage/Demo.scala index e2fe464..cadb762 100644 --- a/samples-scala/src/main/scala/A_APIUSage/Demo.scala +++ b/samples-scala/src/main/scala/A_APIUSage/Demo.scala @@ -9,7 +9,7 @@ import com.microsoft.azure.iot.iothubreact.ResumeOnError._ import com.microsoft.azure.iot.iothubreact.filters._ import com.microsoft.azure.iot.iothubreact.scaladsl._ import com.microsoft.azure.iot.iothubreact.{MessageFromDevice, MessageToDevice} -import com.microsoft.azure.iot.service.sdk.DeliveryAcknowledgement +import com.microsoft.azure.sdk.iot.service.sdk.DeliveryAcknowledgement import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration._ diff --git a/samples-java/setup-env-vars.bat b/setup-env-vars.bat similarity index 100% rename from samples-java/setup-env-vars.bat rename to setup-env-vars.bat diff --git a/samples-java/setup-env-vars.ps1 b/setup-env-vars.ps1 similarity index 100% rename from samples-java/setup-env-vars.ps1 rename to setup-env-vars.ps1 diff --git a/samples-java/setup-env-vars.sh b/setup-env-vars.sh similarity index 100% rename from samples-java/setup-env-vars.sh rename to setup-env-vars.sh diff --git a/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageFromDevice.scala b/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageFromDevice.scala index 11737b8..63871dd 100644 --- a/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageFromDevice.scala +++ b/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageFromDevice.scala @@ -8,6 +8,9 @@ import java.util import com.microsoft.azure.eventhubs.EventData import com.microsoft.azure.servicebus.amqp.AmqpConstants +import scala.collection.JavaConverters._ +import scala.language.{implicitConversions, postfixOps} + /* MessageFromDevice factory */ private object MessageFromDevice { @@ -48,7 +51,7 @@ class MessageFromDevice(data: Option[EventData], val partition: Option[Int]) { private[this] lazy val systemProps = data.get.getSystemProperties() // Meta properties set by the device - lazy val properties: util.Map[String, String] = data.get.getProperties() + lazy val properties: util.Map[String, String] = data.get.getProperties().asScala.map(x ⇒ (x._1, x._2.toString)).asJava // Whether this is a keep alive message generated by the stream and not by IoT hub val isKeepAlive: Boolean = (partition == None) diff --git a/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageToDevice.scala b/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageToDevice.scala index 4ce83be..b04ad12 100644 --- a/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageToDevice.scala +++ b/src/main/scala/com/microsoft/azure/iot/iothubreact/MessageToDevice.scala @@ -6,7 +6,7 @@ import java.nio.charset.StandardCharsets import java.time.Instant import java.util.Date -import com.microsoft.azure.iot.service.sdk.{DeliveryAcknowledgement, Message} +import com.microsoft.azure.sdk.iot.service.sdk.{DeliveryAcknowledgement, Message} import scala.collection.JavaConverters._ import scala.collection.mutable.Map diff --git a/src/main/scala/com/microsoft/azure/iot/iothubreact/StreamManager.scala b/src/main/scala/com/microsoft/azure/iot/iothubreact/StreamManager.scala index 7ca05e8..40fc55a 100644 --- a/src/main/scala/com/microsoft/azure/iot/iothubreact/StreamManager.scala +++ b/src/main/scala/com/microsoft/azure/iot/iothubreact/StreamManager.scala @@ -5,11 +5,11 @@ package com.microsoft.azure.iot.iothubreact import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler} import akka.stream.{Attributes, FlowShape, Inlet, Outlet} -private[iothubreact] class StreamManager[A] - extends GraphStage[FlowShape[A, A]] { +private[iothubreact] class StreamManager + extends GraphStage[FlowShape[MessageFromDevice, MessageFromDevice]] { - private[this] val in = Inlet[A]("StreamCanceller.Flow.in") - private[this] val out = Outlet[A]("StreamCanceller.Flow.out") + private[this] val in = Inlet[MessageFromDevice]("StreamCanceller.Flow.in") + private[this] val out = Outlet[MessageFromDevice]("StreamCanceller.Flow.out") private[this] var closeSignal = false override val shape = FlowShape.of(in, out) @@ -20,7 +20,10 @@ private[iothubreact] class StreamManager[A] new GraphStageLogic(shape) { setHandler(in, new InHandler { - override def onPush(): Unit = push(out, grab(in)) + override def onPush(): Unit = { + val message: MessageFromDevice = grab(in) + push(out, message) + } }) setHandler(out, new OutHandler { diff --git a/src/main/scala/com/microsoft/azure/iot/iothubreact/scaladsl/IoTHub.scala b/src/main/scala/com/microsoft/azure/iot/iothubreact/scaladsl/IoTHub.scala index 8e54e26..d5c0c53 100644 --- a/src/main/scala/com/microsoft/azure/iot/iothubreact/scaladsl/IoTHub.scala +++ b/src/main/scala/com/microsoft/azure/iot/iothubreact/scaladsl/IoTHub.scala @@ -20,7 +20,7 @@ case class IoTHub() extends Logger { // TODO: Provide ClearCheckpoints() method to clear the state - private[this] val streamManager = new StreamManager[MessageFromDevice] + private[this] val streamManager = new StreamManager private[this] def allPartitions = Some(PartitionList(0 until Configuration.iotHubPartitions)) diff --git a/src/main/scala/com/microsoft/azure/iot/iothubreact/sinks/MessageToDeviceSink.scala b/src/main/scala/com/microsoft/azure/iot/iothubreact/sinks/MessageToDeviceSink.scala index 2f6efbf..fdbf75e 100644 --- a/src/main/scala/com/microsoft/azure/iot/iothubreact/sinks/MessageToDeviceSink.scala +++ b/src/main/scala/com/microsoft/azure/iot/iothubreact/sinks/MessageToDeviceSink.scala @@ -9,7 +9,7 @@ import akka.japi.function.Procedure import akka.stream.javadsl.{Sink ⇒ JavaSink} import akka.stream.scaladsl.{Sink ⇒ ScalaSink} import com.microsoft.azure.iot.iothubreact.{Configuration, Logger, MessageToDevice} -import com.microsoft.azure.iot.service.sdk.{IotHubServiceClientProtocol, ServiceClient} +import com.microsoft.azure.sdk.iot.service.sdk.{IotHubServiceClientProtocol, ServiceClient} /** Send messages from cloud to devices */ diff --git a/src/test/scala/it/helpers/Device.scala b/src/test/scala/it/helpers/Device.scala index 5e9c686..04b6db9 100644 --- a/src/test/scala/it/helpers/Device.scala +++ b/src/test/scala/it/helpers/Device.scala @@ -2,7 +2,7 @@ package it.helpers -import com.microsoft.azure.iothub._ +import com.microsoft.azure.sdk.iot.device._ /* Test helper to send messages to the hub */ class Device(deviceId: String) extends Logger {