如何通过 micronaut Http 客户端将 grails 应用程序连接到 Consul?
How to connect a grails app to Consul through micronaut Http Client?
我有一个 grails 3.2.0 网络配置文件应用程序。我想连接到一个单独的 micronaut 应用程序,该应用程序 运行 很好,并且已正确连接到本地 consul。
这是我的 micronaut 控制器:
@Controller("/test")
class TestController {
@Get("/")
def index(){
return "Welcome to micronaut"
}
@Get("/test")
Single<String> test() {
return Single.just("Hello There")
}
}
这是我的 grails 控制器:
class CardClientController {
@Autowired
NewCardClient newCardClient
def index() {
def result = newCardClient.getCards()
respond result
}
}
NewCardClient 界面:
@Client("firstmicroservice")
public interface NewCardClient {
@Get("/test/test")
Single<String> getCards();
}
我在 grails 应用程序中添加的依赖项:
compile 'io.micronaut:inject-java:1.0.0.M1'
compile 'io.micronaut:discovery-client:1.0.0.M1'
compile 'io.micronaut:spring:1.0.0.M1'
runtime 'io.micronaut:runtime:1.0.0.M1'
当我以 /cardClient/ 访问 grails 控制器时,出现以下错误:
2019-05-03 18:20:30.333 ERROR --- [nio-8200-exec-1] i.m.retry.intercept.RecoveryInterceptor : Type [grailsmono.NewCardClient$Intercepted] executed with error: Cannot convert publisher into target type: class io.reactivex.Flowable
java.lang.UnsupportedOperationException: Cannot convert publisher into target type: class io.reactivex.Flowable
at io.micronaut.cache.interceptor.CacheInterceptor.interceptPublisher(CacheInterceptor.java:352)
at io.micronaut.cache.interceptor.CacheInterceptor.intercept(CacheInterceptor.java:120)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at io.micronaut.discovery.client.$CachingCompositeDiscoveryClientDefinition$Intercepted.getInstances(Unknown Source)
at io.micronaut.discovery.client.CachingCompositeDiscoveryClient.getInstances(CachingCompositeDiscoveryClient.java:38)
at io.micronaut.http.client.loadbalance.DiscoveryClientRoundRobinLoadBalancer.select(DiscoveryClientRoundRobinLoadBalancer.java:58)
at io.micronaut.http.client.DefaultHttpClient.resolveRequestURI(DefaultHttpClient.java:720)
at io.micronaut.http.client.DefaultHttpClient.exchange(DefaultHttpClient.java:410)
at io.micronaut.http.client.DefaultHttpClient.exchange(DefaultHttpClient.java:154)
at io.micronaut.http.client.HttpClient.retrieve(HttpClient.java:125)
at io.micronaut.http.client.RxHttpClient.retrieve(RxHttpClient.java:60)
at io.micronaut.http.client.RxHttpClient.retrieve(RxHttpClient.java:33)
at io.micronaut.http.client.interceptor.HttpClientIntroductionAdvice.intercept(HttpClientIntroductionAdvice.java:331)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at io.micronaut.retry.intercept.RecoveryInterceptor.intercept(RecoveryInterceptor.java:74)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at grailsmono.NewCardClient$Intercepted.getCards(Unknown Source)
...
无法连接到 consul,无法调试原因。请帮忙!!!
在@JeffScottBrown 的帮助下,我的解决方法变得简单,只需更改每个依赖项版本,如下所示:
添加了 mavenCentral() 存储库作为依赖项:
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
以及所需的 micronaut 依赖项如下:
compile 'io.micronaut:micronaut-inject-java:1.1.0'
compile 'io.micronaut:micronaut-discovery-client:1.1.0'
compile 'io.micronaut:micronaut-spring:1.1.0'
runtime 'io.micronaut:micronaut-runtime:1.1.0'
我有一个 grails 3.2.0 网络配置文件应用程序。我想连接到一个单独的 micronaut 应用程序,该应用程序 运行 很好,并且已正确连接到本地 consul。
这是我的 micronaut 控制器:
@Controller("/test")
class TestController {
@Get("/")
def index(){
return "Welcome to micronaut"
}
@Get("/test")
Single<String> test() {
return Single.just("Hello There")
}
}
这是我的 grails 控制器:
class CardClientController {
@Autowired
NewCardClient newCardClient
def index() {
def result = newCardClient.getCards()
respond result
}
}
NewCardClient 界面:
@Client("firstmicroservice")
public interface NewCardClient {
@Get("/test/test")
Single<String> getCards();
}
我在 grails 应用程序中添加的依赖项:
compile 'io.micronaut:inject-java:1.0.0.M1'
compile 'io.micronaut:discovery-client:1.0.0.M1'
compile 'io.micronaut:spring:1.0.0.M1'
runtime 'io.micronaut:runtime:1.0.0.M1'
当我以 /cardClient/ 访问 grails 控制器时,出现以下错误:
2019-05-03 18:20:30.333 ERROR --- [nio-8200-exec-1] i.m.retry.intercept.RecoveryInterceptor : Type [grailsmono.NewCardClient$Intercepted] executed with error: Cannot convert publisher into target type: class io.reactivex.Flowable
java.lang.UnsupportedOperationException: Cannot convert publisher into target type: class io.reactivex.Flowable
at io.micronaut.cache.interceptor.CacheInterceptor.interceptPublisher(CacheInterceptor.java:352)
at io.micronaut.cache.interceptor.CacheInterceptor.intercept(CacheInterceptor.java:120)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at io.micronaut.discovery.client.$CachingCompositeDiscoveryClientDefinition$Intercepted.getInstances(Unknown Source)
at io.micronaut.discovery.client.CachingCompositeDiscoveryClient.getInstances(CachingCompositeDiscoveryClient.java:38)
at io.micronaut.http.client.loadbalance.DiscoveryClientRoundRobinLoadBalancer.select(DiscoveryClientRoundRobinLoadBalancer.java:58)
at io.micronaut.http.client.DefaultHttpClient.resolveRequestURI(DefaultHttpClient.java:720)
at io.micronaut.http.client.DefaultHttpClient.exchange(DefaultHttpClient.java:410)
at io.micronaut.http.client.DefaultHttpClient.exchange(DefaultHttpClient.java:154)
at io.micronaut.http.client.HttpClient.retrieve(HttpClient.java:125)
at io.micronaut.http.client.RxHttpClient.retrieve(RxHttpClient.java:60)
at io.micronaut.http.client.RxHttpClient.retrieve(RxHttpClient.java:33)
at io.micronaut.http.client.interceptor.HttpClientIntroductionAdvice.intercept(HttpClientIntroductionAdvice.java:331)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at io.micronaut.retry.intercept.RecoveryInterceptor.intercept(RecoveryInterceptor.java:74)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:41)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:155)
at grailsmono.NewCardClient$Intercepted.getCards(Unknown Source)
...
无法连接到 consul,无法调试原因。请帮忙!!!
在@JeffScottBrown 的帮助下,我的解决方法变得简单,只需更改每个依赖项版本,如下所示:
添加了 mavenCentral() 存储库作为依赖项:
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
以及所需的 micronaut 依赖项如下:
compile 'io.micronaut:micronaut-inject-java:1.1.0'
compile 'io.micronaut:micronaut-discovery-client:1.1.0'
compile 'io.micronaut:micronaut-spring:1.1.0'
runtime 'io.micronaut:micronaut-runtime:1.1.0'