This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
131 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Thu Jun 20 14:22:08 BST 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
plugins { | ||
id 'org.springframework.boot' version '2.1.5.RELEASE' | ||
} | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'org.springframework.boot' | ||
apply plugin: 'io.spring.dependency-management' | ||
|
||
sourceCompatibility = '1.8' | ||
group = 'org.springframework.cloud.gateway' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
ext { | ||
set('springCloudVersion', "Greenwich.SR1") | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway' | ||
implementation 'com.hazelcast:hazelcast' | ||
implementation project(":rate-limiter-hazelcast") | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
samples/cf-hazelcast-p2p/src/main/java/sample/DemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package sample; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.gateway.ratelimiter.HazelcastRateLimiter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.validation.Validator; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
@EnableScheduling | ||
public class DemoApplication { | ||
|
||
@Autowired | ||
private HazelcastRateLimiter hazelcastRateLimiter; | ||
|
||
@Bean | ||
public HazelcastRateLimiter hazelcastRateLimiter(Validator defaultValidator) { | ||
return new HazelcastRateLimiter(defaultValidator); | ||
} | ||
|
||
// super hacky - but DNS records X.peer.apps.internal will only be available shortly after application started | ||
// so InitializingBean or any other option to start cluster during app startup won't work | ||
@Scheduled(initialDelay = 3000, fixedDelay = Integer.MAX_VALUE) | ||
void startHazelcastCluster() { | ||
List<String> members = Arrays.asList("0.peer.apps.internal", "1.peer.apps.internal"); | ||
hazelcastRateLimiter.initialize(members); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
samples/cf-hazelcast-p2p/src/main/java/sample/HeaderKeyResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sample; | ||
|
||
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class HeaderKeyResolver implements KeyResolver { | ||
|
||
@Override | ||
public Mono<String> resolve(ServerWebExchange exchange) { | ||
String apiKey = exchange.getRequest().getHeaders().getFirst("X-API-Key"); | ||
return apiKey == null ? Mono.empty() : Mono.just(apiKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.