Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsocket-kotlin-scripting target #128

Open
yschimke opened this issue Dec 17, 2020 · 10 comments
Open

rsocket-kotlin-scripting target #128

yschimke opened this issue Dec 17, 2020 · 10 comments
Assignees

Comments

@yschimke
Copy link
Member

What could we do to optimise the kotlin scripting experience?

https://github.com/yschimke/okurl-scripts/blob/master/commands/rsocketTcpProxy.main.kts

  1. single maven dependency to import to bring in JVM scripting dependencies

Collapse the DependsOn to a single line

  1. Utility functions for use in ascripting environments based around common operations, with lower barrier than normal public API. Make this a one liner.
val httpClient = HttpClient(ClientCIO) {
        install(ClientWebSockets)
        install(ClientRSocketSupport) {
          connector = RSocketConnector {
            loggerFactory = PrintLogger.withLevel(LoggingLevel.DEBUG)
            connectionConfig {
              payloadMimeType = config.payloadMimeType
            }
          }
        }
      }
@whyoleg
Copy link
Member

whyoleg commented Dec 17, 2020

  1. 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

  1. 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).

  • with possibility to define extensions in kotlin, anyone can create smth like this:
fun RSocketHttpClient(block: RSocketConnectorBuilder.() -> Unit): HttpClient = HttpClient {
  install(WebSockets)
  install(RSocketSupport) {
    connector = RSocketConnector(block)
  }
}

val client = RSocketHttpClient {
  connectionConfig {
    payloadMimeType = config.payloadMimeType
  }
}

@yschimke
Copy link
Member Author

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.

@yschimke
Copy link
Member Author

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

@yschimke
Copy link
Member Author

Any objection if I put up a sample PR for debate?

@yschimke
Copy link
Member Author

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.

@whyoleg
Copy link
Member

whyoleg commented Dec 17, 2020

Any objection if I put up a sample PR for debate?

yes! That's what I was thinking to ask you

@whyoleg
Copy link
Member

whyoleg commented Dec 17, 2020

With future serialisation support (#112) such scripting functionality will be better than testing APIs through some CLI. Really look forward on it!

@yschimke yschimke self-assigned this Dec 17, 2020
@yschimke
Copy link
Member Author

I'm unlikely to take the on any time soon, so closing off

https://gist.github.com/yschimke/9b5d36790478a37776c97b7a73331578

@whyoleg
Copy link
Member

whyoleg commented Dec 28, 2020

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

@whyoleg whyoleg reopened this Dec 28, 2020
@yschimke
Copy link
Member Author

yschimke commented Dec 28, 2020

The rocket-cli command for the server above is

$ rsocket-cli --setup 'wss://rsocket-demo.herokuapp.com/rsocket'  tcp://localhost:9000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants