Open yschimke opened 3 years ago
should work with just:
@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client-jvm:0.12.0")
@file:DependsOn("io.ktor:ktor-client-cio-jvm:1.4.3")
All other are just transitive dependencies
Not sure that we need to include something smaller than that. It's common pattern for ktor to install features like this. Simplest variant is:
HttpClient {
install(WebSockets)
install(RSocketSupport)
}
Engine will be auto-defined on JVM, and Client*
aliases not needed (I was copied them from one of tests, where we have both server and client WS setup in one file).
fun RSocketHttpClient(block: RSocketConnectorBuilder.() -> Unit): HttpClient = HttpClient {
install(WebSockets)
install(RSocketSupport) {
connector = RSocketConnector(block)
}
}
val client = RSocketHttpClient { connectionConfig { payloadMimeType = config.payloadMimeType } }
For 2 the goal here isn't to knowingly configure Ktor. It's to achieve some scripting like task against rsocket APIs as a client or server.
So the suggestion is a scripting library that combines some minimal set of common dependencies from 1. with the utility you defined in 2
fun RSocketHttpClient(block: RSocketConnectorBuilder.() -> Unit): HttpClient = HttpClient {
install(WebSockets)
install(RSocketSupport) {
connector = RSocketConnector(block)
}
}
Get the overall script down to
@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("io.rsocket.kotlin:rsocket-scripting-jvm:0.12.0")
val client = RSocketHttpClient {
connectionConfig {
payloadMimeType = config.payloadMimeType
}
}
val response = client.request(Payload(...json...))
.. do something with response
Any objection if I put up a sample PR for debate?
As I'm not as familiar with the code structure. Dependencies and imports and configuration is making even quite simple examples quite involved to quickly create and iterate on.
Any objection if I put up a sample PR for debate?
yes! That's what I was thinking to ask you
With future serialisation support (#112) such scripting functionality will be better than testing APIs through some CLI. Really look forward on it!
I'm unlikely to take the on any time soon, so closing off
https://gist.github.com/yschimke/9b5d36790478a37776c97b7a73331578
Let's leave it open for now, I can take it on my own some time in future, no hurry. I think, that scripting examples, experience - it's a great opportunity to share even simple rsocket clients / servers in one script, so anyone could try it out
The rocket-cli command for the server above is
$ rsocket-cli --setup 'wss://rsocket-demo.herokuapp.com/rsocket' tcp://localhost:9000
What could we do to optimise the kotlin scripting experience?
https://github.com/yschimke/okurl-scripts/blob/master/commands/rsocketTcpProxy.main.kts
Collapse the DependsOn to a single line