Skip to content

Commit

Permalink
Merge pull request #1 from sazzeo/zuul
Browse files Browse the repository at this point in the history
zuul filter 추가
  • Loading branch information
sazzeo authored Aug 2, 2022
2 parents a748822 + d31c9ed commit 09e6c86
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion user-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
#유레카 클라이언트 역할 기능 켜기
eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} #인스턴스 id 부여해주기
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} #인스턴스 id 부여해주기 (포트가 같을 때)
client:
register-with-eureka: true
fetch-registry: true #서버로부터 인스턴스들의 정보를 주기적으로 가져올 것인지?
Expand Down
4 changes: 2 additions & 2 deletions zuul-client-first-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} #인스턴스 id 부여해주기
client:
register-with-eureka: true
fetch-registry: true #서버로부터 인스턴스들의 정보를 주기적으로 가져올 것인지?
register-with-eureka: false
fetch-registry: false #서버로부터 인스턴스들의 정보를 주기적으로 가져올 것인지?
4 changes: 2 additions & 2 deletions zuul-client-second-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} #인스턴스 id 부여해주기
client:
register-with-eureka: true
fetch-registry: true #서버로부터 인스턴스들의 정보를 주기적으로 가져올 것인지?
register-with-eureka: false
fetch-registry: false #서버로부터 인스턴스들의 정보를 주기적으로 가져올 것인지?
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.jy.study.zuul.zuulservice.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;


//zuul 게이트웨이 필터
@Slf4j //롬복이 만들어주는 log객체 Logger log = LoggerFactory.getLogger(현재 클래스명.class)
@Component
public class ZuulLoggingFilter extends ZuulFilter {

//실제 동작할 메소드 지정
@Override
public Object run() throws ZuulException {
log.info("********** printing logs: ");

//현재 request 객체를 얻어오는 방법
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
log.info("********** " + request.getRequestURI());

return null;
}

//사전인지, 사후인지 필터 지정
@Override
public String filterType() {
return "pre";
}

//필터 순서 지정
@Override
public int filterOrder() {
return 1;
}


//필터 사용 여부 지정
@Override
public boolean shouldFilter() {
return true;
}



}

0 comments on commit 09e6c86

Please sign in to comment.