How to send routing information in metadata?
yuri-li opened this issue · comments
how to use RSocketTCPClient#requestResponse?
Steps to Reproduce
import { RSocketClient, JsonSerializers } from "rsocket-core"
import RSocketTCPClient from "rsocket-tcp-client"
const route = "login"
const MIME_TYPE = "application/json"
const client = new RSocketClient({
serializers: JsonSerializers,
setup: {
keepAlive: 10000,
lifetime: 86400000,
dataMimeType: MIME_TYPE,
metadataMimeType: MIME_TYPE,
},
transport: new RSocketTCPClient({
host: "47.101.196.18",
port: 7000,
}),
})
client.connect().subscribe({
onError: error => console.error(error),
onSubscribe: cancel => {
console.log("onSubscribe")
console.log(cancel)
},
onComplete: rsocket => {
rsocket.requestResponse({
data: JSON.stringify({
username: "admin",
password: "123456",
}),
metadata: route,
}).subscribe({
onComplete: data => console.log(data),
onError: e => console.error(e),
})
console.log("onComplete")
}
})
My Environment
- RSocket version(s) used:
"rsocket-core": "^0.0.27",
"rsocket-tcp-client": "^0.0.27"
- node version:v14.17.3
Hi @yuri-li,
Can you provide some more details about what issues you are encountering? In which way is the observed result differing from your expectations? Is there an error thrown that you do not expect? If so, can you be more specific?
Hi @yuri-li,
Can you provide some more details about what issues you are encountering? In which way is the observed result differing from your expectations? Is there an error thrown that you do not expect? If so, can you be more specific?
hi, @viglucci ,
I am a Java development engineer, good at cloud native. I am afraid of misunderstanding, so the server (springboot.jar) is deployed on the cloud server, the host is real, and the front-end code(typescript) I gave can be run directly(throw exception).
I ran the back-end code (kotlin coroutines+rsocket+kotest) first, and the test code is as follows:
@viglucci
hi, I found the solution
The front-end code after fixing the bug is as follows:
import { RSocketClient, BufferEncoders, encodeAndAddWellKnownMetadata, MESSAGE_RSOCKET_COMPOSITE_METADATA, MESSAGE_RSOCKET_ROUTING, encodeRoute } from "rsocket-core"
import RSocketTCPClient from "rsocket-tcp-client"
const route = "login"
const client = new RSocketClient({
setup: {
keepAlive: 10000,
lifetime: 86400000,
dataMimeType: "application/json",
metadataMimeType: MESSAGE_RSOCKET_COMPOSITE_METADATA.string,
},
transport: new RSocketTCPClient({
host: "47.101.196.18",
port: 7000,
}, BufferEncoders),
})
client.connect().subscribe({
onError: error => console.error(error),
onComplete: rsocket => {
const routeMetadata = encodeRoute(route)
const metadata = encodeAndAddWellKnownMetadata(
Buffer.alloc(0),
MESSAGE_RSOCKET_ROUTING,
routeMetadata
)
rsocket.requestResponse({
data: Buffer.from(JSON.stringify({
username: "admin",
password: "123456",
})),
metadata,
}).subscribe({
onError: e => console.error(e),
onComplete: payload => console.log((payload.data as Buffer).toString()),
})
console.log("onComplete")
}
})
Hi @yuri-li,
Thanks for following up and providing the solution you found. I believe this issue could be avoided if we had more extensive documentation around composite metadata, as well as more centralized and extensive examples. I'll keep this in mind as we improve the documentation and APIs moving forward.
I'll close this issue since you've come to a solution.
@yuri-li you have incorrect client configurations. Please see these examples to see how to utilize composite metadata -> https://github.com/rsocket/rsocket-js/blob/master/packages/rsocket-examples/src/CompositeMetadataExample.js
Also, here is a working js -> spring-boot-rsocket example https://github.com/OlegDokuka/rsocket-crosslanguage-example