Can you create too many instances with Ktor - ktor

Coming from OkHttp if you created too many instances of the OkHttp client you would you would eventually get OutOfMemoryException from having too many clients created.
Is this also something that you would have to worry about when using Ktor?
I am trying to migrate from okhttp to ktor to support KMM and have only a little experience with Ktor

You can create as many HttpClient as you want, like you could do with OkHttp.
It's up to you to make it singleton so that to have only one client instance.
You can do it by yourself or use a DI library.

Related

Quarkus Jax-rs clients with external interfaces

I started playing around with Quarkus and its REST client. According to the documentation a Jax-RS annotated interface should be created and annotated further with #RegisterRestClient.
My issue is that I already have the JaxRS interfaces for the services I need to connect to, in an artifact provided by the server, which I can just import. Is there a way to use an already created external Jax-RS interface to create a service with? It seems so wrong to copy-paste the code for a perfectly good interface, when it has been so nicely served for me.
There's RestClientBuilder, which allows programmatic usage of JAX-RS interfaces. Assuming the JAX-RS interface is called HelloClient, you can do this:
HelloClient client = RestClientBuilder.newBuilder()
.baseUri(URI.create("http://localhost:8080"))
.build(HelloClient.class);

http requests with Kotlin multiplatform for desktop

I'm new to kotlin multiplatform and I'm using compose for desktop, how can I make HTTP requests?
is there any resources to learn from?
Ktor is the best supported multiplatform HTTP client currently, as it is maintained by Jetbrains There are also projects that put together many open source tools for kotlin multiplatform such as: AAkira
There is not a specific place currently that goes over HTTP communication, as it would be specific per tool you choose.

Websocket client in Kotlin

I was wondering why there is no Websocket client native object in Kotlin like it is in javascript.
How does one connect to a Websocket server in kotlin as I created a Node.js websocket server and want to connect to it using an Android client.
Can someone please elaborate on this.
Thanks.
There is. If your question is about Kotlin native/multiplatform, you can use ktor client:
https://ktor.io/clients/websockets.html.
On the Android side, you would need to use CIO or OKHttp engines. On the javascript side, Js engine. On the iOS side, there is currently no support available out of the box, but it's supposed to be coming soon.
If your question is not about Kotlin native/multiplaform, you can still use the above or org.java_websocket.client.WebSocketClient, or any of the third party libs.

How to use request and session scopes in spring-webflux (as of latest releases)

I am developing a rest web service using reactive programming through spring-webflux(Spring Boot 2.1 and Spring Framework 5.1). I need to create components having request level scope. #Scope annotation is suggested for spring MVC applications. But I found that the same doesn't work with webflux application.
Is there an equivalent feature available in webflux, as of latest release?
If not, what shall be the workaround here to create a new instance of a component on every incoming request?
I am trying to avoid use of new operator.
Thank you for the suggestions.
Unfortunately you cannot use request scopes in spring-webflux like in spring MVC applications. The main reason being, they use ThreadLocals which cannot be used by spring-webflux as work can be done on any thread at any time.
Spring webflux uses project-reactor at its core. So you can use Reactor Context which allows you to share data in your reactive pipeline.

how to consume meteor API call

I need to write a Java web application to call a function Meteor APP. One way is through API call. Are there any other means to call Meteor function from 3rd party application.
Thanks
Murali
It all depends on what your requirements are, how your Meteor app is structured, and what sort of integration you desire.
If you are wanting your Java web application to be able to natively call Meteor methods or subscribe to publications, then you will have to use a Java DDP Client to do this. Fortunately, there is at least one documented Java DDP client that you can use for this (and probably many others out there is you search). For your reference, here is a compiled list of DDP clients for other languages/technologies.
If on the other hand you don't want to interface with you meteor app using DDP, then you could always implement a REST API in your meteor app. There are several packages available to do this, but I would highly recommend the simple:rest package.
This package automatically creates a REST API for all your existing publications and methods without any extra code (just simply add the package to your meteor app). If you do need to configure or modify the REST API, the package also provides several options that you can use in your publication or meteor method definition. The package also enforces all your app's security rules and authorization.
For example, if your app had a publication called openTasks, then the corresponding REST endpoint would be.
GET /publications/openTasks
There are quite a few packages at https://atmospherejs.com/?q=rest that can expose your Meteor methods as RESTful API points which your Java app can consume.