eureka-wiki
POM依賴:app
<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.19.1</version> </dependency>
實現抽象類ClientFilter的handle方法ide
public class IpCilentFilter extends ClientFilter { @Override public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException { //響應對象的處理 ClientResponse response = this.getNext().handle(clientRequest); return response; } }
注入clientFilterfetch
@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/appsthis
com.netflix.eureka.resources.ApplicationResource
eureka: client: fetch-registry: true