-
Notifications
You must be signed in to change notification settings - Fork 0
Spring Cloud Zuul
정명주(myeongju.jung) edited this page Feb 26, 2018
·
2 revisions
- 넷플릭스에서 만든 API Gateway
- https://github.com/Netflix/zuul
Zuul is a gateway service that provides dynamic routing, monitoring, resiliency, security, and more.
- 넷플릭스에서 만듬
- java로 되어 있기 때문에 proxy 기능을 사용하면서도 ViewTemplate(ex:FreeMarker)를 이용해서 페이지를 직접 서비스할 수도 있다.
- spring-boot starter이 기본 제공되어서 application.yml에 설정을 통합할 수 있다.
build.gradle
compile('org.springframework.cloud:spring-cloud-starter-zuul') {
exclude group: 'com.google.code.findbugs', module: 'annotations'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
ZuulConfiguration.java
/**
* Zuul api-gw 설정
* 입맛에 맞게 필터들을 추가하면 된다.
* @author myeongju.jung
*/
@Configuration("zuulCustomConfiguration") // Bean명칭 충돌방지
@EnableZuulProxy
public class ZuulConfiguration {
@Bean
Servlet30WrapperFilter servlet30WrapperFilter() {
return new Servlet30WrapperFilter();
}
@Bean
DebugFilter debugFilter() {
return new DebugFilter();
}
@Bean
ApiFirstPreFilter apiFirstPreFilter() {
return new ApiFirstPreFilter();
}
}
application.yml
# zuul api-gw
# zuul api-gw
zuul:
routes:
post:
path: /api/post/**
url: http://www.post.com/api
PostApiRootGwTest.java
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PostApiRootGwTest {
@Autowired
TestRestTemplate restTemplate;
@Ignore("해당 통합 테스트를 진행하기 위해서는 post-api 서버가 기동되어 있어야 합니다.")
@Test
public void samples() throws Exception {
// given
// when
ResponseEntity<Collection<Sample>> responseEntity =
restTemplate.exchange("/api/post/samples", HttpMethod.GET, HttpEntity.EMPTY,
new ParameterizedTypeReference<Collection<Sample>>() {
});
Collection<Sample> samples = responseEntity.getBody();
// then
assertThat(samples.isEmpty(), is(false));
samples.forEach(this::assertSample);
}
private void assertSample(Sample sample) {
System.out.println(sample);
assertThat(sample.getSeq(), is(greaterThan(0L)));
assertThat(sample.getTitle(), is(notNullValue()));
assertThat(sample.getContent(), is(notNullValue()));
assertThat(sample.getHit(), is(greaterThanOrEqualTo(0)));
assertThat(sample.getCreatedAt(), is(lessThan(ZonedDateTime.now())));
}
}
JAVA
JPA
- JPA-Create-And-Update
- Optional-Eager
- QueryDsl-Configuration
- QueryDsl-More-Type-safety
- QueryDsl-SubQuery
DDD
Install
Spring
Spring-Boot
- Swagger2-Configuration
- Spring-Restdocs-Configuration
- Spring-Page-Jackson
- JSR310-Guide
- logback-spring.xml
- WebMvcUtils.java
- Spring-Boot-Properties
- Spring-Boot-Hidden-Gems
- Spring-Boot-Config
Spring-Cloud
- Spring-Cloud-Zuul
- Spring-Cloud-Feign
- Spring-Cloud-Hystrix
- Spring-Cloud-Consul
- Spring-Cloud-Ribbon
- Spring-Cloud-Circuit-Breaker
JavaScript
Gradle
Test
Linux
Etc
TODO http://zoltanaltfatter.com/2017/06/09/publishing-domain-events-from-aggregate-roots/