Add MQTT prototype (not tested)
This commit is contained in:
parent
00c66da847
commit
197675fc15
@ -15,6 +15,6 @@ kscience {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
api("space.kscience:dataforge-io:$dataforgeVersion")
|
api("space.kscience:dataforge-io:$dataforgeVersion")
|
||||||
api(npmlibs.kotlinx.datetime)
|
api(spclibs.kotlinx.datetime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ dependencies {
|
|||||||
// implementation("org.jetbrains.xodus:xodus-environment:$xodusVersion")
|
// implementation("org.jetbrains.xodus:xodus-environment:$xodusVersion")
|
||||||
// implementation("org.jetbrains.xodus:xodus-vfs:$xodusVersion")
|
// implementation("org.jetbrains.xodus:xodus-vfs:$xodusVersion")
|
||||||
|
|
||||||
testImplementation(npmlibs.kotlinx.coroutines.test)
|
testImplementation(spclibs.kotlinx.coroutines.test)
|
||||||
}
|
}
|
||||||
|
|
||||||
readme{
|
readme{
|
||||||
|
@ -29,9 +29,13 @@ dependencies {
|
|||||||
implementation("ch.qos.logback:logback-classic:1.2.11")
|
implementation("ch.qos.logback:logback-classic:1.2.11")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin{
|
||||||
|
jvmToolchain(11)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "11"
|
|
||||||
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,12 @@ dependencies {
|
|||||||
// implementation("org.litote.kmongo:kmongo-coroutine-serialization:4.4.0")
|
// implementation("org.litote.kmongo:kmongo-coroutine-serialization:4.4.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin{
|
||||||
|
jvmToolchain(11)
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "11"
|
|
||||||
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class VirtualCarController : Controller(), ContextAware {
|
|||||||
plugin(DeviceManager)
|
plugin(DeviceManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val deviceManager = context.fetch(DeviceManager, Meta {
|
private val deviceManager = context.request(DeviceManager, Meta {
|
||||||
"xodusConfig" put {
|
"xodusConfig" put {
|
||||||
"entityStorePath" put deviceEntityStorePath.toString()
|
"entityStorePath" put deviceEntityStorePath.toString()
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,12 @@ dependencies {
|
|||||||
|
|
||||||
implementation("ch.qos.logback:logback-classic:1.2.11")
|
implementation("ch.qos.logback:logback-classic:1.2.11")
|
||||||
}
|
}
|
||||||
|
kotlin{
|
||||||
|
jvmToolchain(11)
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "11"
|
|
||||||
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all", "-Xopt-in=kotlin.RequiresOptIn")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ dependencies{
|
|||||||
implementation(projects.magix.magixServer)
|
implementation(projects.magix.magixServer)
|
||||||
implementation(projects.magix.magixZmq)
|
implementation(projects.magix.magixZmq)
|
||||||
implementation(projects.magix.magixRsocket)
|
implementation(projects.magix.magixRsocket)
|
||||||
implementation("ch.qos.logback:logback-classic:1.2.3")
|
implementation(spclibs.logback.classic)
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin{
|
kotlin{
|
||||||
|
@ -17,7 +17,7 @@ import ru.mipt.npm.devices.pimotionmaster.PiMotionMasterDevice.Axis.Companion.po
|
|||||||
import space.kscience.controls.manager.DeviceManager
|
import space.kscience.controls.manager.DeviceManager
|
||||||
import space.kscience.controls.manager.installing
|
import space.kscience.controls.manager.installing
|
||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.dataforge.context.fetch
|
import space.kscience.dataforge.context.request
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class PiMotionMasterApp : App(PiMotionMasterView::class)
|
class PiMotionMasterApp : App(PiMotionMasterView::class)
|
||||||
@ -29,7 +29,7 @@ class PiMotionMasterController : Controller() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//initialize deviceManager plugin
|
//initialize deviceManager plugin
|
||||||
val deviceManager: DeviceManager = context.fetch(DeviceManager)
|
val deviceManager: DeviceManager = context.request(DeviceManager)
|
||||||
|
|
||||||
// install device
|
// install device
|
||||||
val motionMaster: PiMotionMasterDevice by deviceManager.installing(PiMotionMasterDevice)
|
val motionMaster: PiMotionMasterDevice by deviceManager.installing(PiMotionMasterDevice)
|
||||||
|
@ -7,4 +7,4 @@ org.gradle.parallel=true
|
|||||||
publishing.github=false
|
publishing.github=false
|
||||||
publishing.sonatype=false
|
publishing.sonatype=false
|
||||||
|
|
||||||
toolsVersion=0.14.3-kotlin-1.8.10
|
toolsVersion=0.14.6-kotlin-1.8.20
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
18
magix/magix-mqtt/build.gradle.kts
Normal file
18
magix/magix-mqtt/build.gradle.kts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
id("space.kscience.gradle.jvm")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
description = """
|
||||||
|
MQTT client magix endpoint
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(projects.magix.magixApi)
|
||||||
|
implementation("com.hivemq:hivemq-mqtt-client:1.3.1")
|
||||||
|
implementation(spclibs.kotlinx.coroutines.jdk8)
|
||||||
|
}
|
||||||
|
|
||||||
|
readme{
|
||||||
|
maturity = space.kscience.gradle.Maturity.PROTOTYPE
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package space.ksceince.magix.mqtt
|
||||||
|
|
||||||
|
import com.hivemq.client.mqtt.MqttClient
|
||||||
|
import com.hivemq.client.mqtt.datatypes.MqttQos
|
||||||
|
import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
|
import kotlinx.coroutines.channels.trySendBlocking
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import kotlinx.coroutines.future.await
|
||||||
|
import space.kscience.magix.api.MagixEndpoint
|
||||||
|
import space.kscience.magix.api.MagixMessage
|
||||||
|
import space.kscience.magix.api.MagixMessageFilter
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
|
public class MqttMagixEndpoint(
|
||||||
|
serverHost: String,
|
||||||
|
clientId: String = UUID.randomUUID().toString(),
|
||||||
|
public val topic: String = DEFAULT_MAGIX_TOPIC_NAME,
|
||||||
|
public val qos: MqttQos = MqttQos.AT_LEAST_ONCE,
|
||||||
|
) : MagixEndpoint, AutoCloseable {
|
||||||
|
|
||||||
|
private val client: Mqtt5AsyncClient by lazy {
|
||||||
|
MqttClient.builder()
|
||||||
|
.identifier(clientId)
|
||||||
|
.serverHost(serverHost)
|
||||||
|
.useMqttVersion5()
|
||||||
|
.buildAsync()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val connection by lazy {
|
||||||
|
client.connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun subscribe(filter: MagixMessageFilter): Flow<MagixMessage> = callbackFlow {
|
||||||
|
connection.await()
|
||||||
|
client.subscribeWith()
|
||||||
|
.topicFilter(topic)
|
||||||
|
.qos(qos)
|
||||||
|
.callback { published ->
|
||||||
|
val message = MagixEndpoint.magixJson.decodeFromString(
|
||||||
|
MagixMessage.serializer(),
|
||||||
|
published.payloadAsBytes.decodeToString()
|
||||||
|
)
|
||||||
|
trySendBlocking(message)
|
||||||
|
}
|
||||||
|
.send()
|
||||||
|
|
||||||
|
awaitClose {
|
||||||
|
client.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun broadcast(message: MagixMessage) {
|
||||||
|
connection.await()
|
||||||
|
client.publishWith().topic(topic).qos(qos).payload(
|
||||||
|
MagixEndpoint.magixJson.encodeToString(MagixMessage.serializer(), message).encodeToByteArray()
|
||||||
|
).send()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
client.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
public companion object {
|
||||||
|
public const val DEFAULT_MAGIX_TOPIC_NAME: String = "magix"
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ dependencies {
|
|||||||
api(projects.magix.magixApi)
|
api(projects.magix.magixApi)
|
||||||
implementation("org.jetbrains.xodus:xodus-entity-store:$xodusVersion")
|
implementation("org.jetbrains.xodus:xodus-entity-store:$xodusVersion")
|
||||||
|
|
||||||
testImplementation(npmlibs.kotlinx.coroutines.test)
|
testImplementation(spclibs.kotlinx.coroutines.test)
|
||||||
}
|
}
|
||||||
|
|
||||||
readme{
|
readme{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
rootProject.name = "controls-kt"
|
rootProject.name = "controls-kt"
|
||||||
|
|
||||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||||
enableFeaturePreview("VERSION_CATALOGS")
|
|
||||||
|
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
versionCatalogs {
|
versionCatalogs {
|
||||||
create("npmlibs") {
|
create("spclibs") {
|
||||||
from("space.kscience:version-catalog:$toolsVersion")
|
from("space.kscience:version-catalog:$toolsVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,6 +55,7 @@ include(
|
|||||||
":magix:magix-java-client",
|
":magix:magix-java-client",
|
||||||
":magix:magix-zmq",
|
":magix:magix-zmq",
|
||||||
":magix:magix-rabbit",
|
":magix:magix-rabbit",
|
||||||
|
":magix:magix-mqtt",
|
||||||
|
|
||||||
// ":magix:magix-storage",
|
// ":magix:magix-storage",
|
||||||
":magix:magix-storage:magix-storage-xodus",
|
":magix:magix-storage:magix-storage-xodus",
|
||||||
|
Loading…
Reference in New Issue
Block a user