Hi all, Ktor looks awesome and we’re planning to t...
# ktor
a
Hi all, Ktor looks awesome and we’re planning to try it out with an API endpoint. We have an existing spring app which has a service class with methods that we want to call from Ktor. How should be go about it? RPC? If so what tools do you recommend?
h
Depends a bit on how your architecture looks like.
a
It’s based on spring
h
The “cleanest” cut would be interfacing via REST or messaging. Then again, the use case might demand something else
Yeah, sure. But are we talking services or monolith? Is the application that uses Spring running in a single instance or clustered? What will the “class” do?
a
Single instance
i just does some operation and return a result
h
You shouldn’t look at it as a “class” btw. If it provides a useful functionallity, make it available as a service
a
It’s implemented as service class. I’m just wondering the best way to expose it to an app hosted on the same server
h
Ah, sorry. Spring’s
@Service
classes have nothing to do with a service that is available from the outside world. It is the “service layer”, where the business logic should be implemented
You could create a
@Controller
making it available as a REST service. This brings up the question how to authenticate and authorize.
Then, if you have access to the class itself, you could refactor the actual logic into a little library which your Spring and your Ktor app can then use
As I said, it highly depends on what you are actually trying to implement
“Making it available somehow when it runs on the same server” sounds a bit hacky to me
Also, in order to make things like this possible you need to make sure the apps run on the same JVM instance.
a
I thought RPC was the standard way of doing such things but Controller seems doable too