everyone.
Question 1
I try to use Rsocket. How does Rsocket server send message to client? Like websocket, the server can send message to one client or all clients. I can not find a way to do it. Maybe I can use Channel? But I do not know what to do.
Question 2
I use Channel like this:
@MessageMapping("channel")
fun channel(settings: Flux<Duration>) =
settings
.doOnNext { setting: Duration -> println("Frequency setting is ${setting.seconds} second(s).") }
.switchMap { setting: Duration ->
Flux.interval(setting).map { index: Long -> Message("Server", "Channel", index) }
}
.log()
And in js, I do this:
const {
RSocketClient
} = require('rsocket-core');
const RSocketTcpClient = require('rsocket-tcp-client').default;
const {Flowable} = require('rsocket-flowable')
const tcpClient = new RSocketTcpClient((host, port))
const client = new RSocketClient({
setup: {
keepAlive,
lifetime,
dataMimeType: "application/json",
metadataMimeType: 'message/x.rsocket.routing.v0'
},
transport: tcpClient,
});
const flowablePayload = new Flowable(subscriber => {
subscriber.onSubscribe({
cancel: () => {},
request: n => {
for (let index = 0; index < n; index++) {
const message = {
message: "requestChannel from JavaScript! #" + index
};
subscriber.onNext(message);
}
subscriber.onComplete();
}
});
});
client.connect().subscribe({
onComplete: socket => {
console.log('onComplete')
socket.requestChannel({
data: flowablePayload,
metadata: String.fromCharCode('channel'.length) + 'channel'
}).subscribe({
onComplete: res => console.log(res),
onError: err => console.error(err),
onSubscribe: cancel => console.log('success')
});
},
onError: error => {
console.log("got error");
console.error(error);
},
onSubscribe: cancel => {
console.log("subscribe!");
}
})
output:
subscribe!
onComplete
success
But I can not get the MessageMapping
channel info and channel
method is not executed.
What should I do?
Thanks!!!