![](https://camo.githubusercontent.com/1eaf561b7f2cc3e110830bbc4ebddd563d12ac2344d52e7c40d94491501ba242/68747470733a2f2f6a69747061636b2e696f2f762f626973686f79626173696c792f73746f6d702e737667)
lateinit var stompConnection: Disposable
lateinit var topic: Disposable
val url = "ws://example.com/endpoint"
val intervalMillis = 1000L
val client = OkHttpClient()
val stomp = StompClient(url, intervalMillis, client)
// connect
stompConnection = stomp.connect().subscribe {
when (it.type) {
Event.Type.OPENED -> {
}
Event.Type.CLOSED -> {
}
Event.Type.ERROR -> {
}
}
}
// subscribe
topic = stomp.subscribe("/destination").subscribe { Log.i(TAG, it) }
// unsubscribe
topic.dispose()
// send
stomp.send("/destination", "dummy message").subscribe {
if (it) {
}
}
// disconnect
stompConnection.dispose()