How would I integrate Wire with Spring Boot? #3636
Replies: 2 comments
-
|
Yes, it’s possible, but not as a drop-in replacement for Spring Boot’s default gRPC setup. Spring Boot gRPC is fundamentally built around What Spring Boot expectsSpring gRPC is designed around:
This is what Spring auto-detects and registers into its Netty gRPC server. Wire does not generate any of these. Instead, it generates Kotlin data classes and service interfaces, so Spring cannot consume them directly. What Wire changesWith Wire, your
So the compatibility gap is at the codegen boundary, not at the transport level. How to integrate Wire with Spring BootYou keep Spring Boot for lifecycle and DI, and replace only the gRPC codegen layer. 1. Replace protobuf codegen with WireConfigure Wire in Gradle: plugins {
id("com.squareup.wire")
}
wire {
kotlin {
rpcRole = "server"
rpcCallStyle = "suspending"
}
}At this point, you are no longer using Spring’s protobuf-based generation for those modules. 2. Bridge Wire services into SpringSpring still requires Wire does not natively produce
Example pattern: @Service
class RouteGuideService : RouteGuideServer {
override suspend fun GetFeature(request: Point): Feature {
// implementation
}
}Then expose it to Spring: @Configuration
class GrpcConfig {
@Bean
fun routeGuideBindable(service: RouteGuideService): BindableService {
return GeneratedRouteGuideGrpcService(service)
}
}This 3. Client-side integrationYou do not use Instead, you build clients directly: val client = GrpcClient.Builder()
.baseUrl("https://localhost:9090")
.build()
val routeGuide = client.create(RouteGuideClient::class)Then optionally wrap it in a Spring 4. Important limitationWire and protobuf cannot safely coexist for the same Mixing TradeoffsSpring gRPC (protobuf) is more mature and fully integrated with Spring Boot auto-configuration. Wire gives you:
But requires:
Bottom lineYes, it works with Spring Boot, but only by treating Spring as a runtime container and Wire as the full gRPC abstraction layer. You lose Spring’s automatic gRPC wiring ( It’s a valid architecture, just not a plug-and-play substitution. |
Beta Was this translation helpful? Give feedback.
-
|
https://github.com/square/wire-grpc-server could generate the BindableService that Spring could use but this repo isn't maintained by the Wire team, and is probably not maintained at all |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Spring boot has this gRPC integration but it's based on the stock google impl https://docs.spring.io/spring-boot/reference/io/grpc.html which gives the bad kotlin ergonomics. I'd therefore like to use Wire.
Is that possible?
Beta Was this translation helpful? Give feedback.
All reactions