-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/scala/com/github/kimutansk/awsiot/MqttPublisher.scala
This file contains 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 @@ | ||
package com.github.kimutansk.awsiot | ||
|
||
import org.eclipse.paho.client.mqttv3.{MqttMessage, MqttConnectOptions, MqttClient} | ||
|
||
/** MQTT Publish Test Class */ | ||
object MqttPublisher { | ||
def main(args: Array[String]) { | ||
// Connect Target | ||
val brokerURI:String = "ssl://A3869B885YB2CX.iot.ap-northeast-1.amazonaws.com:8883" | ||
|
||
// SocketFactoryGenerate | ||
val socketFactory = SocketFactoryGenerator.generateFromFilePath("/etc/cert/rootCA.pem", "/etc/cert/cert.pem", "/etc/cert/private.pem", "password") | ||
|
||
// MQTT Client generate | ||
val client:MqttClient = new MqttClient(brokerURI, "mqtt-publisher") | ||
client.setCallback(new PublishMqttCallback) | ||
val options:MqttConnectOptions = new MqttConnectOptions() | ||
options.setSocketFactory(socketFactory) | ||
client.connect(options) | ||
|
||
|
||
val message:MqttMessage = new MqttMessage("Test Message".getBytes("UTF-8")) | ||
client.publish("test-topic", message) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/scala/com/github/kimutansk/awsiot/PublishMqttCallback.scala
This file contains 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,13 @@ | ||
package com.github.kimutansk.awsiot | ||
|
||
import org.eclipse.paho.client.mqttv3.{IMqttDeliveryToken, MqttMessage, MqttCallback} | ||
|
||
/** Publish MqttCallBack */ | ||
class PublishMqttCallback extends MqttCallback{ | ||
// Nop | ||
override def deliveryComplete(iMqttDeliveryToken: IMqttDeliveryToken): Unit = ??? | ||
|
||
override def messageArrived(s: String, mqttMessage: MqttMessage): Unit = ??? | ||
|
||
override def connectionLost(throwable: Throwable): Unit = ??? | ||
} |
This file contains 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