Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-anderson committed Nov 14, 2024
1 parent 10e1a8d commit f0b31cc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static void main(String[] args) throws Exception {

try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080)
.appendClientFilter(resilienceFilter)
.build().asBlockingClient()) {
.build()
.asBlockingClient()) {
// Will use breakerForPathA
client.request(client.get("/A"));
// Will use breakerForNonAPaths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.http.api.BlockingHttpClient;
import io.servicetalk.http.netty.HttpClients;
import io.servicetalk.traffic.resilience.http.ClientPeerRejectionPolicy;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpClientFilter;
Expand All @@ -29,7 +30,7 @@
* client.
*/
public final class TrafficResilienceClientPeerRejectionsPassthroughExample {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
final TrafficResilienceHttpClientFilter resilienceFilter =
new TrafficResilienceHttpClientFilter.Builder(() -> CapacityLimiters.dynamicGradient().build())
.rejectionPolicy(ClientPeerRejectionPolicy.ofPassthrough(metaData ->
Expand All @@ -38,8 +39,11 @@ public static void main(String[] args) {
metaData.status().code() == SERVICE_UNAVAILABLE.code()))
.build();

HttpClients.forSingleAddress("localhost", 8080)
try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080)
.appendClientFilter(resilienceFilter)
.build();
.build()
.asBlockingClient()) {
client.request(client.get("/foo"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.http.api.BlockingHttpClient;
import io.servicetalk.http.netty.HttpClients;
import io.servicetalk.http.netty.RetryingHttpRequesterFilter;
import io.servicetalk.traffic.resilience.http.ClientPeerRejectionPolicy;
Expand All @@ -32,7 +33,7 @@
* A client which configures the resilience filters to signal an appropriate delay to the retry filter.
*/
public final class TrafficResilienceClientPeerRejectionsRetryExample {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
final TrafficResilienceHttpClientFilter resilienceFilter =
new TrafficResilienceHttpClientFilter.Builder(() -> CapacityLimiters.dynamicGradient().build())
.rejectionPolicy(ClientPeerRejectionPolicy.ofRejectionWithRetries(DEFAULT_CAPACITY_REJECTION_PREDICATE,
Expand All @@ -44,9 +45,12 @@ public static void main(String[] args) {
ofExponentialBackoffDeltaJitter(retry.delay(), ofMillis(500), ofSeconds(2), 2))
.build();

HttpClients.forSingleAddress("localhost", 8080)
try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080)
.appendClientFilter(retryingHttpRequesterFilter)
.appendClientFilter(resilienceFilter)
.build();
.build()
.asBlockingClient()) {
client.request(client.get("/foo"));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;

Expand All @@ -33,7 +32,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;

Expand All @@ -32,7 +31,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.servicetalk.capacity.limiter.api.CapacityLimiter;
import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;

Expand All @@ -38,7 +37,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.servicetalk.capacity.limiter.api.CapacityLimiter;
import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;

Expand All @@ -44,7 +43,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.ServiceRejectionPolicy;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;
Expand All @@ -38,7 +37,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.servicetalk.examples.http.traffic.resilience;

import io.servicetalk.capacity.limiter.api.CapacityLimiters;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.netty.HttpServers;
import io.servicetalk.traffic.resilience.http.TrafficResilienceHttpServiceFilter;

Expand All @@ -41,7 +40,7 @@ public static void main(String[] args) throws Exception {

HttpServers.forPort(8080)
.appendNonOffloadingServiceFilter(resilienceFilter)
.listenAndAwait((ctx, request, responseFactory) -> Single.succeeded(responseFactory.ok()))
.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())
.awaitShutdown();
}
}

0 comments on commit f0b31cc

Please sign in to comment.