如何解决FeignClient spring boot 无法访问节点服务
节点服务已注册到 eureka,但是当尝试从另一个微服务作为 FeignClient 访问节点服务时,它给出 java.net.UnkNownHostException
使用eureka注册节点服务eureka-js-client(https://www.npmjs.com/package/eureka-js-client)
尤里卡-helper.ts
export async function registerWithEureka(appName,PORT){
const client = new Eureka({
instance: {
app: appName,hostName,ipAddr,port: {
$: PORT,'@enabled': 'true',},vipAddress: appName,dataCenterInfo: {
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',name: 'MyOwn',eureka: {
host: eurekaHost,port: eurekaPort,servicePath: '/eureka/apps/',maxRetries: 3,requestRetryDelay: 2000,});
server.ts
async function run() {
const port = process.env.PORT || 4000;
// Start up the Node server
const server = await app();
server.listen(port,() => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
registerWithEureka('pdf-generator-service-v2',port);
}
FeignClient
@FeignClient(name = PdfGeneratorClientV2.PDF_GENERATION_SERVICE_V2)
public interface PdfGeneratorClientV2 {
String PDF_GENERATION_SERVICE_V2 = "pdf-generator-service-v2";
@GetMapping("api/v2/pdf/job-summary")
byte[] generatePdf(@RequestParam String jobRefId,@RequestParam String orgId,@RequestParam String workflowId);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。