gpt4 book ai didi

java - Feign Client 从 Jhipster UAA 到微服务网关应用程序

转载 作者:行者123 更新时间:2023-11-30 10:20:08 25 4
gpt4 key购买 nike

我的网关 (gw-app) 应用程序中有一个联系人实体,每次在 UAA 应用程序中注册新用户时,我都想创建一个条目。我一直在尝试使用 inter service communication在 Jhipster 微服务文档中有描述。

  • 我遇到的第一个问题是我在 UAA 应用程序中没有此接口(interface) @AuthorizedFeignClient
  • 其次,我从未使用 @FeignClient 从 uaa 成功创建到 gw-app。

除了与假客户端的通信/配置问题之外,我还担心在没有建立 session (新用户注册)时这将如何工作,然后我有另一个用例,我有一个来自用户的现有 session -管理屏幕(当管理员正在创建新用户时)

UAA配置

{
"generator-jhipster": {
"promptValues": {
"packageName": "com.uaa.auth",
"nativeLanguage": "es"
},
"jhipsterVersion": "4.13.3",
"baseName": "UAA",
"packageName": "com.agriket.auth",
"packageFolder": "com/uaa/auth",
"serverPort": "9999",
"authenticationType": "uaa",
"cacheProvider": "hazelcast",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": false,
"serviceDiscoveryType": "eureka",
"buildTool": "gradle",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"jwtSecretKey": "8e4167f67e9f8d85cc35b70181a828c691374e58",
"enableTranslation": true,
"applicationType": "uaa",
"testFrameworks": [],
"jhiPrefix": "jhi",
"nativeLanguage": "es",
"languages": [
"es",
"en"
],
"clientPackageManager": "yarn",
"skipClient": true
}
}

网关应用配置

{
"generator-jhipster": {
"promptValues": {
"packageName": "com.app.gw",
"nativeLanguage": "es"
},
"jhipsterVersion": "4.13.3",
"baseName": "gwApp",
"packageName": "com.agriket.chat",
"packageFolder": "com/app/gw",
"serverPort": "9085",
"authenticationType": "uaa",
"uaaBaseName": "UAA",
"cacheProvider": "hazelcast",
"enableHibernateCache": true,
"websocket": "spring-websocket",
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": false,
"serviceDiscoveryType": "eureka",
"buildTool": "gradle",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"clientFramework": "angularX",
"useSass": false,
"clientPackageManager": "yarn",
"applicationType": "gateway",
"testFrameworks": [],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "es",
"languages": [
"es",
"en"
]
}
}

客户端代码

package com.uaa.auth.service.restClient;

import com.uaa.auth.service.restClient.Contact;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "gwApp")
@RequestMapping("/api")
public interface ContactClient {

@PostMapping("/contacts")
Contact createContact(@RequestBody Contact contact);

@GetMapping("/contacts/{id}")
Contact getContact(@PathVariable(name = "id") Long id);

}

联系方式

public class Contact {

private Long id;

private String login;

private String firstName;

private String lastName;


public Contact(User user) {
this.id = user.getId();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
}

public Long getId() {
return id;
}

public String getLogin() {
return login;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}
}

最佳答案

要在您的项目中包含 Feign,请使用组 org.springframework.cloud 和工件 ID spring-cloud-starter-openfeign 的启动器。

我想 Feign 客户端最适合微服务之间的服务间通信,而不是网关和微服务之间的通信。希望这对您有所帮助。

https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html

关于java - Feign Client 从 Jhipster UAA 到微服务网关应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48349726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com