You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This optional exercise implements the detailed design depicted in Chapter 11 of Programming the Internet of Things, where a factory class is used to create ICloudClient instances - based on a configuration file entry - that allow connectivity to multiple cloud service providers' hosted MQTT brokers.
Objective
Create a factory class that can create instances of ICloudClient specific to a given cloud service provider.
Create an abstract base class that contains the generic functionality of any ICloudClient to be used as the super class of cloud service provider specific ICloudClient instances that use MQTT / TLS for connectivity.
Review the README
Please see README.md for further information on, and use of, this content.
License for embedded documentation and source codes: PIOT-DOC-LIC
Estimated effort may vary greatly
The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.
Actions
Create a new class named CloudClientFactory. If you prefer, you can create this as a Singleton via the following method signature: public static final CloudClientFactory getInstance(). If you choose this approach, your constructor should be private, and the instance can be declared as follows: private static final CloudClientFactory _Instance = new CloudClientFactory();.
Update your CSP specific ICloudClient implementation to use the appropriate configuration section from the next set of instructions (e.g., Cloud.GatewayService.AWS, which you can also add as a constant in ConfigConst)
Update your configuration file (PiotConfig.props) to support configuration sections for multiple, using Cloud.GatewayService as the generic properties with the entry specifying the actual cloud service configuration section to load. An example follows:
NOTE 2: For students of Connected Devices, I show a coding sample during class that allows you to enter multiple 'cloudServiceName' entries - comma delimited - and implement the CloudClientFactory to return a List of ICloudClient implementations. You can choose to implement this on your own, or as shown below. The below example shows how you can have multiple CSP configurations, but use only one at a time based on the configuration.
[Cloud.GatewayService]
cloudServiceName = {TODO: enter 'AWS', 'Ubidots', or other - must match ending text of the next section}
[Cloud.GatewayService.AWS]
credFile = ./cred/AwsCloudCred.props
certFile = ./cert/AwsCloudCert.pem
privateKeyFile = ./cert/AwsCloudKey.key
cloudServiceName = AWS
host = {TODO: hostname}
securePort = {TODO: secure port}
defaultQoS = {TODO: select 0 or 1}
keepAlive = {TODO: select keep alive seconds}
enableAuth = True
enableCrypt = True
baseUrl = {WARNING: for AWS, do NOT enter here - use your credFile and do NOT commit to your repo}
baseTopic = {blank}
[Cloud.GatewayService.Ubidots]
credFile = ./cred/UbidotsCloudCred.props
certFile = ./cert/UbidotsCloudCert.pem
cloudServiceName = Ubidots
host = {TODO: hostname}
securePort = {TODO: secure port}
defaultQoS = {TODO: select 0 or 1}
keepAlive = {TODO: select keep alive seconds}
enableAuth = True
enableCrypt = True
baseUrl = {blank}
baseTopic = {TODO: verify with CSP}
Create the method createCloudClient() method using the following signature: public ICloudClient createCloudClient()
Implement the method by including the following:
Retrieve the value of cloudServiceName from the Cloud.GatewayService section of the configuration file
Use the value to determine which specific ICloudClient instance to create.
Create - then return - the appropriate ICloudClient instance.
Be sure to handle any exceptions, such as an invalid configuration entry that does not specify the appropriate (or existing) ICloudClient implementation
NOTE: You may need to update MqttClientConnector if you're using it as the MQTT connection logic to integrate with your selected CSP. If so, you can simply do the following:
Add a new contructor to MqttClientConnector that accepts the String cloudGatewaySectionName parameter, and - once verified as a valid CSP entry - simply pass it to the initClientParameters() method. If not a valid CSP entry, simply pass the ConfigConst.MQTT_GATEWAY_SERVICE name to initClientParameters().
Estimate
Medium
Tests
In the src/test/java path within the 'programmingtheiot.part04.integration.connection' package, add the CloudClientFactoryTest test case by creating a new JUnit test class named CloudClientFactoryTest.
Add your integration tests within the class - these tests should allow you to verify that CloudClientFactory can create an ICloudClient instance for the target CSP based on the configuration file (PiotConfig.props).
Example Test:
Name: testCreateAndTestCloudClient
Purpose: Use CloudClientFactory to create a valid (non-null) and usable instance of ICloudClient based on settings within PiotConfig.props.
Acceptance: ICloudClient instance is non-null and connect / disconnect succeeds. This can be verified via Wireshark and through your CSP IoT connection console.
The text was updated successfully, but these errors were encountered:
Description
Objective
Review the README
Estimated effort may vary greatly
Actions
CloudClientFactory
. If you prefer, you can create this as a Singleton via the following method signature:public static final CloudClientFactory getInstance()
. If you choose this approach, your constructor should be private, and the instance can be declared as follows:private static final CloudClientFactory _Instance = new CloudClientFactory();
.ICloudClient
implementation to use the appropriate configuration section from the next set of instructions (e.g.,Cloud.GatewayService.AWS
, which you can also add as a constant inConfigConst
)Cloud.GatewayService
as the generic properties with the entry specifying the actual cloud service configuration section to load. An example follows:CloudClientFactory
to return aList
ofICloudClient
implementations. You can choose to implement this on your own, or as shown below. The below example shows how you can have multiple CSP configurations, but use only one at a time based on the configuration.createCloudClient()
method using the following signature:public ICloudClient createCloudClient()
cloudServiceName
from theCloud.GatewayService
section of the configuration fileICloudClient
instance to create.ICloudClient
instance.ICloudClient
implementationMqttClientConnector
if you're using it as the MQTT connection logic to integrate with your selected CSP. If so, you can simply do the following:MqttClientConnector
that accepts theString cloudGatewaySectionName
parameter, and - once verified as a valid CSP entry - simply pass it to theinitClientParameters()
method. If not a valid CSP entry, simply pass theConfigConst.MQTT_GATEWAY_SERVICE
name toinitClientParameters()
.Estimate
Tests
CloudClientFactoryTest
test case by creating a new JUnit test class namedCloudClientFactoryTest
.CloudClientFactory
can create anICloudClient
instance for the target CSP based on the configuration file (PiotConfig.props).testCreateAndTestCloudClient
CloudClientFactory
to create a valid (non-null) and usable instance ofICloudClient
based on settings within PiotConfig.props.ICloudClient
instance is non-null and connect / disconnect succeeds. This can be verified via Wireshark and through your CSP IoT connection console.The text was updated successfully, but these errors were encountered: