You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project already supports the creation of different GRPC stub types (Blocking, Future, etc.). However GRPC Kotlin is and will be increasingly popular. When GRPC code is generated with grpc-kotlin the client stub extends AbstractCoroutineStub. It's currently not possible to instantiate instances of these stubs with this project.
The solution
The suggested solution is:
Create an optional dependency on io.grpc:grpc-kotlin-stub:0.2.0
Create a new stub factory - something like
public class CoroutineStubFactory implements StubFactory {
@Override
public AbstractStub<?> createStub(Class<? extends AbstractStub<?>> stubType, Channel channel) {
try {
final Constructor<? extends AbstractStub<?>> constructor = stubType.getConstructor(Channel.class, CallOptions.class);
return constructor.newInstance(channel, CallOptions.DEFAULT);
} catch (Exception e) {
throw new BeanInstantiationException(stubType, "Failed to create gRPC client via CoroutineStubFactory", e);
}
}
@Override
public boolean isApplicable(Class<? extends AbstractStub<?>> stubType) {
return AbstractCoroutineStub.class.isAssignableFrom(stubType);
}
}
Add an auto-configuration @Bean of CoroutineStubFactory guarded by @ConditionalOnClass(AbstractCoroutineStub.class)
NOTE: That unlike the other stubs already supported, Kotlin stubs that extend AbstractCoroutineStub are generated to use constructor based instantiation, as opposed to be being instantiated via a static method.
The text was updated successfully, but these errors were encountered:
The problem
This project already supports the creation of different GRPC stub types (Blocking, Future, etc.). However GRPC Kotlin is and will be increasingly popular. When GRPC code is generated with grpc-kotlin the client stub extends
AbstractCoroutineStub
. It's currently not possible to instantiate instances of these stubs with this project.The solution
The suggested solution is:
Create an
optional
dependency onio.grpc:grpc-kotlin-stub:0.2.0
Create a new stub factory - something like
Add an auto-configuration
@Bean
ofCoroutineStubFactory
guarded by@ConditionalOnClass(AbstractCoroutineStub.class)
NOTE: That unlike the other stubs already supported, Kotlin stubs that extend
AbstractCoroutineStub
are generated to use constructor based instantiation, as opposed to be being instantiated via a static method.The text was updated successfully, but these errors were encountered: