从Jhipster UAA到微服务网关应用程序的Feign Client [英] Feign Client from Jhipster UAA to microservice gateway app
问题描述
我的网关(gw-app)应用程序中有一个联系人实体,每次在UAA应用程序中注册新用户时,我都想创建一个条目.我一直在尝试使用Jhipster中所述的内部服务通信微服务文档.
I have a Contact Entity in my gateway(gw-app) app and I would like to create a entry every time a new user is registered in the UAA app. I have been trying to use the inter service communication described in Jhipster documentation for microservices.
- 我在这里遇到的第一个问题是,我在UAA应用程序中没有此界面
@AuthorizedFeignClient
. - 第二,我从来没有使用
@FeignClient
从uaa到gw-app取得成功.
- Fist problem I have here is I don't have this interface
@AuthorizedFeignClient
in the UAA app. - Second, I never got a success creation from uaa to gw-app using
@FeignClient
.
除了与假客户端的通信/配置问题外,我还担心在没有会话建立(新用户注册)时这将如何工作,然后又有一个用例,其中有来自用户的现有会话管理屏幕(当管理员创建新用户时)
Beside having the communication/configuration issues with the feign client I have some concerns about how this will work when there is no session stablished(new user registering) and then I have another use case where I have an existing session from the user-management screen (when an admin is creating a new user)
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
的启动器.
To include Feign in your project use the starter with group org.springframework.cloud
and artifact id spring-cloud-starter-openfeign
.
我认为Feign客户端最适合微服务之间而不是网关和微服务之间的服务间通信.希望对您有帮助.
I suppose Feign client is best suited for inter service communication between microservices, not between gateway and microservice. Hope this will help you.
https://cloud.spring.io /spring-cloud-netflix/multi/multi_spring-cloud-feign.html
这篇关于从Jhipster UAA到微服务网关应用程序的Feign Client的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!