TLS impleamentation on NATS server

This commit is contained in:
Pritimay Sarkar
2024-02-09 13:50:33 +05:30
parent de74da3135
commit f631a273d7

View File

@@ -8,6 +8,7 @@ import io.nats.client.Message
import io.nats.client.NKey
import io.nats.client.Nats
import io.nats.client.Options
import io.nats.client.support.SSLUtils
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.security.GeneralSecurityException
@@ -30,7 +31,8 @@ class NatsManager(datacollector: DashboardActivity) {
val theNKey = NKey.fromSeed(seedBytes) // really should load from somewhere
val options = Options.Builder()
.server("nats://192.168.10.117:4222")
.server("nats://nanodgx.in:4222")
.sslContext(SSLUtils.createOpenTLSContext())
.authHandler(object : AuthHandler {
override fun getID(): CharArray? {
return try {
@@ -84,7 +86,7 @@ class NatsManager(datacollector: DashboardActivity) {
d?.subscribe("device.hpos.HCV-000-3001.update") { msg ->
val response = String(msg.data, StandardCharsets.UTF_8)
datacollector. setResponse(response)
datacollector.setResponse(response)
println("Message received (up to 100 times): $response")
}