Distinguish api pairing server and client, api pairing service registration init

This commit is contained in:
hongqiaowei
2021-10-25 11:20:13 +08:00
committed by GitHub
parent 70b54886c6
commit 5b573310e3
9 changed files with 112 additions and 28 deletions

View File

@@ -105,23 +105,26 @@ refresh-local-cache:
fizz:
aggregate:
writeMapNullValue: false
aggregate:
writeMapNullValue: false
error:
response:
http-status.enable: true
code-field: "msgCode"
message-field: "message"
error:
response:
http-status.enable: true
code-field: "msgCode"
message-field: "message"
api.pairing:
enable: false
web-server.port: 8601
request:
timeliness: 300 # default 300 sec
timeout: 0 # default no timeout
retry-count: 0 # default no retry
retry-interval: 0 # default no retry interval
api.pairing:
server:
enable: false
client:
enable: false
port: 8601
request:
timeliness: 300 # default 300 sec
timeout: 0 # default no timeout
retry-count: 0 # default no retry
retry-interval: 0 # default no retry interval
fizz-trace-id:
header: X-Trace-Id

View File

@@ -112,6 +112,8 @@ public class ApiPairingController {
if (equals) {
List<AppApiPairingDocSet> docs = getAppDocSet(appId);
String docsJson = JacksonUtils.writeValueAsString(docs);
response.setStatusCode(HttpStatus.OK);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
return response.writeWith(Mono.just(response.bufferFactory().wrap(docsJson.getBytes())));
} else {
log.warn("{}request authority: app {}, timestamp {}, sign {} invalid",

View File

@@ -40,7 +40,7 @@ import java.util.*;
* @author hongqiaowei
*/
@ConditionalOnProperty(name = "fizz.api.pairing.enable", havingValue = "true")
@ConditionalOnProperty(name = "fizz.api.pairing.server.enable", havingValue = "true")
@Service
public class ApiPairingDocSetService {

View File

@@ -40,7 +40,7 @@ import java.util.Map;
* @author hongqiaowei
*/
@ConditionalOnProperty(name = "fizz.api.pairing.enable", havingValue = "true")
@ConditionalOnProperty(name = "fizz.api.pairing.client.enable", havingValue = "true")
@Service
public class ApiPairingInfoService {

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package we.api.pairing;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @author hongqiaowei
*/
@Component
public class ApiPairingServiceRegistration implements ApplicationListener<FizzApiPairingWebServerInitializedEvent> {
@Override
public void onApplicationEvent(FizzApiPairingWebServerInitializedEvent event) {
}
}

View File

@@ -19,7 +19,7 @@ package we.api.pairing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -71,7 +71,7 @@ class FizzApiPairingHttpHandler implements HttpHandler {
private FizzWebClient fizzWebClient;
private ApiPairingInfoService apiPairingInfoService;
public FizzApiPairingHttpHandler(ConfigurableApplicationContext applicationContext, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer,
public FizzApiPairingHttpHandler(ReactiveWebServerApplicationContext applicationContext, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer,
LocaleContextResolver localeContextResolver, ForwardedHeaderTransformer forwardedHeaderTransformer) {
this.sessionManager = sessionManager;

View File

@@ -24,8 +24,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
@@ -47,14 +47,14 @@ public class FizzApiPairingWebServer {
private static final Logger log = LoggerFactory.getLogger(FizzApiPairingWebServer.class);
@Resource
private ConfigurableApplicationContext applicationContext;
private ReactiveWebServerApplicationContext applicationContext;
@Resource
private HttpHandler httpHandler;
private HttpHandler httpHandler;
private WebServer server;
private WebServer server;
@Value("${fizz.api.pairing.web-server.port:8601}")
@Value("${fizz.api.pairing.client.port:8601}")
private int port = 8601;
@PostConstruct
@@ -72,6 +72,7 @@ public class FizzApiPairingWebServer {
);
server.start();
log.info("fizz api pairing web server listen on {}", port);
applicationContext.publishEvent(new FizzApiPairingWebServerInitializedEvent(server, applicationContext));
}
@PreDestroy

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package we.api.pairing;
import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationEvent;
/**
* @author hongqiaowei
*/
public class FizzApiPairingWebServerInitializedEvent extends ApplicationEvent {
private final ReactiveWebServerApplicationContext applicationContext;
public FizzApiPairingWebServerInitializedEvent(WebServer webServer, ReactiveWebServerApplicationContext applicationContext) {
super(webServer);
this.applicationContext = applicationContext;
}
@Override
public WebServer getSource() {
return (WebServer) super.getSource();
}
public ReactiveWebServerApplicationContext getApplicationContext() {
return this.applicationContext;
}
}

View File

@@ -94,16 +94,16 @@ public class SystemConfig {
@Value("${fizz.api.pairing.request.timeliness:300}")
@Value("${fizz.api.pairing.client.request.timeliness:300}")
private int fizzApiPairingRequestTimeliness = 300; // unit: sec
@Value("${fizz.api.pairing.request.timeout:0}")
@Value("${fizz.api.pairing.client.request.timeout:0}")
private int fizzApiPairingRequestTimeout = 0; // mills
@Value("${fizz.api.pairing.request.retry-count:0}")
@Value("${fizz.api.pairing.client.request.retry-count:0}")
private int fizzApiPairingRequestRetryCount = 0;
@Value("${fizz.api.pairing.request.retry-interval:0}")
@Value("${fizz.api.pairing.client.request.retry-interval:0}")
private int fizzApiPairingRequestRetryInterval = 0; // mills
public int fizzApiPairingRequestTimeout() {