eureka-wiki bash
POM依賴:<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.1</version>
</dependency>
複製代碼
實現抽象類ClientFilter的handle方法app
public class IpCilentFilter extends ClientFilter {
@Override
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
//響應對象的處理
ClientResponse response = this.getNext().handle(clientRequest);
return response;
}
}
複製代碼
注入clientFilteride
@Bean
public DiscoveryClientOptionalArgs discoveryClientOptionalArgs() {
DiscoveryClientOptionalArgs discoveryClientOptionalArgs = new DiscoveryClientOptionalArgs();
discoveryClientOptionalArgs.setAdditionalFilters(Collections.singletonList(new IpCilentFilter()));
return discoveryClientOptionalArgs;
}
複製代碼
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registration = new FilterRegistrationBean(new ServerRequestAuthFilter());
registration.addUrlPatterns("/*");
return registration;
}
public class ServerRequestAuthFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
//業務實現,根據請求的IP或者參數判斷是否能夠執行註冊或者訪問
filterChain.doFilter(request, response);
}
}
複製代碼
攔截具體客戶端註冊、續約、下線請求,請參考 /eureka/appsfetch
com.netflix.eureka.resources.ApplicationResource
複製代碼
eureka:
client:
fetch-registry: true
複製代碼