/** * Constructor for a ModuleClient instance. * @param connectionString The connection string for the edge module to connect to. Must be in format * HostName=xxxx;deviceId=xxxx;SharedAccessKey= * xxxx;moduleId=xxxx; * * or * * HostName=xxxx;DeviceId=xxxx;SharedAccessKey= * xxxx;moduleId=xxxx;HostNameGateway=xxxx * @param protocol The protocol to use when communicating with the module * @throws ModuleClientException if an exception is encountered when parsing the connection string * @throws UnsupportedOperationException if using any protocol besides MQTT, if the connection string is missing * the "moduleId" field, or if the connection string uses x509 * @throws IllegalArgumentException if the provided connection string is null or empty, or if the provided protocol is null * @throws URISyntaxException if the connection string cannot be parsed for a valid hostname */ public ModuleClient(String connectionString, IotHubClientProtocol protocol) throws ModuleClientException, IllegalArgumentException, UnsupportedOperationException, URISyntaxException { //Codes_SRS_MODULECLIENT_34_006: [This function shall invoke the super constructor.] super(new IotHubConnectionString(connectionString), protocol, SEND_PERIOD_MILLIS, getReceivePeriod(protocol)); //Codes_SRS_MODULECLIENT_34_007: [If the provided protocol is not MQTT, AMQPS, MQTT_WS, or AMQPS_WS, this function shall throw an UnsupportedOperationException.] //Codes_SRS_MODULECLIENT_34_004: [If the provided connection string does not contain a module id, this function shall throw an IllegalArgumentException.] commonConstructorVerifications(protocol, this.config); }
/** * Create a module client instance that uses x509 authentication. * * <p>Note! Communication from a module to another EdgeHub using x509 authentication is not currently supported and * the service will always return "UNAUTHORIZED"</p> * * <p>Communication from a module directly to the IotHub does support x509 authentication, though.</p> * @param connectionString The connection string for the edge module to connect to. Must be in format * HostName=xxxx;deviceId=xxxx;SharedAccessKey= * xxxx;moduleId=xxxx; * * or * * HostName=xxxx;DeviceId=xxxx;SharedAccessKey= * xxxx;moduleId=xxxx;HostNameGateway=xxxx * @param protocol The protocol to communicate with * @param publicKeyCertificate The PEM formatted string for the public key certificate or the system path to the file containing the PEM. * @param isCertificatePath 'false' if the publicKeyCertificate argument is a path to the PEM, and 'true' if it is the PEM string itself, * @param privateKey The PEM formatted string for the private key or the system path to the file containing the PEM. * @param isPrivateKeyPath 'false' if the privateKey argument is a path to the PEM, and 'true' if it is the PEM string itself, * @throws URISyntaxException If the connString cannot be parsed * @throws ModuleClientException if any other exception occurs while building the module client */ public ModuleClient(String connectionString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath) throws ModuleClientException, URISyntaxException { super(new IotHubConnectionString(connectionString), protocol, publicKeyCertificate, isCertificatePath, privateKey, isPrivateKeyPath, SEND_PERIOD_MILLIS, getReceivePeriod(protocol)); //Codes_SRS_MODULECLIENT_34_008: [If the provided protocol is not MQTT, AMQPS, MQTT_WS, or AMQPS_WS, this function shall throw an UnsupportedOperationException.] //Codes_SRS_MODULECLIENT_34_009: [If the provided connection string does not contain a module id, this function shall throw an IllegalArgumentException.] commonConstructorVerifications(protocol, this.getConfig()); }
ModuleClient moduleClient = new ModuleClient(iotHubAuthenticationProvider, protocol, SEND_PERIOD_MILLIS, getReceivePeriod(protocol));