@FeignClient(contextId = "test-feign", value = "mbiolance-service-message", path = "/test-feign",configuration = CommonFeignConfiguration.class)
public interface MessageTestFeignService {
@GetMapping("/test")
Mono<String> test();
}
@RestController
@RequiredArgsConstructor
@RequestMapping("/test-feign")
@Api(tags = "测试服务接口")
public class TestRestful implements MessageTestFeignService {
@GetMapping("/test")
@Override
public Mono<String> test(){
try {
InetAddress localHost = InetAddress.getLocalHost();
return Mono.just("message 连接测试成功:"+localHost);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
}
@Autowired
private MessageTestFeignService messageTestFeignService;
@GetMapping("/test2")
public String test2(){
String block = messageTestFeignService.test().block();
return block;
}
no suitable HttpMessageConverter found for response type
feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter found for response type [reactor.core.publisher.Mono<java.lang.String>] and content type [text/html;charset=UTF-8]
at feign.AsyncResponseHandler.decode(AsyncResponseHandler.java:119)
...
Caused by: org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [reactor.core.publisher.Mono<java.lang.String>] and content type [text/html;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:126)
....
使用 Reactivate-Feign
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-cloud</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-spring-configuration</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<version>2.0.31</version>
</dependency>
@ReactiveFeignClient(url = "http://mbiolance-service-message",name = "mbiolance-service-message-test",path = "/",configuration = ReactiveFeignConfiguration.class)
public interface MessageTestFeignService {
@GetMapping("/test")
Mono<String> test();
}
添加
@EnableReactiveFeignClients(basePackages = "com.mbiolance.cloud.message")
没有添加报下面错误
Field messageTestFeignService in com.bioproj.controller.TestController required a bean of type 'com.mbiolance.cloud.message.rpc.MessageTestFeignService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
接下来会报错如下
Caused by: reactivefeign.client.ReactiveFeignException: java.net.UnknownHostException: mbiolance-service-message: Temporary failure in name resolution
at reactivefeign.webclient.client.WebReactiveHttpClient.lambda$executeRequest$3(WebReactiveHttpClient.java:101)
at reactor.core.publisher.Mono.lambda$onErrorMap$30(Mono.java:3286)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:88)
... 60 common frames omitted
Caused by: java.net.UnknownHostException: mbiolance-service-message: Temporary failure in name resolution
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ Request to GET http://mbiolance-service-message/test [DefaultWebClient]
Stack trace:
解决方案
@Configuration
public class WebClientConfig {
@LoadBalanced
@Bean
public WebClient.Builder register() {
return WebClient.builder();
}
}