本文整理汇总了Scala中org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence类的典型用法代码示例。如果您正苦于以下问题:Scala MqttDefaultFilePersistence类的具体用法?Scala MqttDefaultFilePersistence怎么用?Scala MqttDefaultFilePersistence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MqttDefaultFilePersistence类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Publisher
//设置package包名称以及导入依赖的类
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
import org.eclipse.paho.client.mqttv3.{MqttClient, MqttMessage}
import scala.util.{Failure, Random, Success, Try}
object Publisher extends App {
// Global information
val name = "apdl-case-study-from-scratch"
// MQTT Server info to publish
val brokerURL = "tcp://mosquitto-mqtt:1883"
val topicTemperature = s"temp"
val topicLuminosity = s"light"
val persistence = new MqttDefaultFilePersistence("tmp")
Try {
val client = new MqttClient(brokerURL, MqttClient.generateClientId(), persistence)
client.connect()
val topicTemp = client.getTopic(topicTemperature)
val topicLight = client.getTopic(topicLuminosity)
while (true) {
val temp = Random.nextInt(10) + 20
val light = Random.nextInt(40) + 640
val msgTemp = new MqttMessage(s"$temp".getBytes)
val msgLight = new MqttMessage(s"$light".getBytes)
println(s"Publish $temp to $topicTemperature")
println(s"Publish $light to $topicLight")
topicTemp.publish(msgTemp)
topicLight.publish(msgLight)
Thread.sleep(1000)
}
while(true) {
println("OK !")
Thread.sleep(1000)
}
} match {
case Failure(exception) => println(s"ERROR : $exception + ${exception.getCause}")
case Success(_) => println(s"OK !")
}
}
开发者ID:SnipyJulmy,项目名称:APDL-from-scratch-mqtt,代码行数:48,代码来源:Publisher.scala
注:本文中的org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论