Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zuul filter 추가 #1

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}



}