MSAプロジェクト1(下書き)
18419 ワード
マイクロサービスに対応するため、Discovery、ApiGateway、Config-Serviceが設置されています.
Discovery:クライアントからの要求としてEurekaサーバで実行します.
ApiGateway:ロードバランサロールとマイクロサービスルーティングロール
≪サービスの構成|Configure Service|emdw≫:各マイクロ・サービスのプリファレンス・パラメータを1つの場所から外部サービスに移動します.
依存性はロムフォードとユリカサーバのみ登録されています
Spring Securityを使用して、後でユーザー・サービスの有効性の検証を行います.
クライアント->ユーザー-サービス(会員入力)->ログイン->JWTリリース->リクエスト->ApiGatewayでのトークン検証->ルーティング順序
デフォルトでは、ymlファイルを作成してグローバルフィルタを指定し、メッセージを出力します.
ルーティング:サブアイテムにルーティング情報を作成するには
id:ルーティングするサービスname
述語:条件
フィルター:条件が合えば、対応するフィルターを通ります.
RewritePath:要求がサービス内部に入ると、サービス内部は削除を宣言してprefixセクションを使用します.
すなわち、初期要求が->/user-service/loginに入ると、ユーザ-サービス内部で/loginによって要求を受信して処理することができる.
グローバルフィルタは、すべてのフィルタで最初に呼び出され、最後に呼び出されます.
ログ出力のみが書かれていますが、後でサービスを変更するときは、ここに追加の内容が書かれます.
Discovery:クライアントからの要求としてEurekaサーバで実行します.
ApiGateway:ロードバランサロールとマイクロサービスルーティングロール
≪サービスの構成|Configure Service|emdw≫:各マイクロ・サービスのプリファレンス・パラメータを1つの場所から外部サービスに移動します.
Discovery
依存性はロムフォードとユリカサーバのみ登録されています
server:
port: 8761
spring:
application:
name: discoveryservice
eureka:
client:
register-with-eureka: false
fetch-registry: false
これは、自分がユリカサーバーに登録するかどうかを確認するオプションです.falseに設定し、サーバとしてのみ使用package esanghaesee.discovery;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
}
ユリカサーバとして@EnableEurekaServerを指定ApiGateway
Spring Securityを使用して、後でユーザー・サービスの有効性の検証を行います.
クライアント->ユーザー-サービス(会員入力)->ログイン->JWTリリース->リクエスト->ApiGatewayでのトークン検証->ルーティング順序
デフォルトでは、ymlファイルを作成してグローバルフィルタを指定し、メッセージを出力します.
ルーティング:サブアイテムにルーティング情報を作成するには
id:ルーティングするサービスname
述語:条件
フィルター:条件が合えば、対応するフィルターを通ります.
RewritePath:要求がサービス内部に入ると、サービス内部は削除を宣言してprefixセクションを使用します.
すなわち、初期要求が->/user-service/loginに入ると、ユーザ-サービス内部で/loginによって要求を受信して処理することができる.
server:
port: 8000
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: apigateway-service
cloud:
gateway:
default-filters:
- name: GlobalFilter
args:
baseMessage: GlobalFilter
preLogger: true
postLogger: true
routes:
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/login
- Method=POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
ルーティング情報は次のように指定されます.グローバルフィルタは、すべてのフィルタで最初に呼び出され、最後に呼び出されます.
ログ出力のみが書かれていますが、後でサービスを変更するときは、ここに追加の内容が書かれます.
@Component
@Slf4j
public class GlobalFilter extends AbstractGatewayFilterFactory<GlobalFilter.Config> {
public GlobalFilter() {
super(Config.class);
}
@Data
public static class Config {
private String baseMessage;
private boolean preLogger;
private boolean postLogger;
}
@Override
public GatewayFilter apply(Config config) {
return ((exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse response = exchange.getResponse();
if (config.isPreLogger()) {
log.info("Global filter prelogger -> {}", request.getId());
}
return chain.filter(exchange).then(Mono.fromRunnable(()-> {
if (config.isPreLogger()) {
log.info("Global filter post -> {}", response.getStatusCode());
}
}));
});
}
}
Config Service
package esanghaesee.configservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
@Configurationアクションを追加して、デリバリサーバの構成に使用します.server:
port: 8888
spring:
application:
name: config-service
profiles:
active: native
cloud:
config:
server:
native:
search-locations: file:///Users/pupu/Desktop/study/java/msa-config
ローカルファイルで設定した値を読み込むように指定します.後でRabbitMqまたはGitに変更しますReference
この問題について(MSAプロジェクト1(下書き)), 我々は、より多くの情報をここで見つけました https://velog.io/@kurikuri/MSA-프로젝트-1テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol