Skip to content

Instantly share code, notes, and snippets.

View AlexRogalskiy's full-sized avatar
🛰️
Work on stuff that matters

Alexander AlexRogalskiy

🛰️
Work on stuff that matters
View GitHub Profile
@dhet
dhet / LenientFutureCollector.java
Last active January 15, 2024 17:34
Wait for the completion of multiple Java Futures or time out
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.*;
import java.util.stream.Collector;
@AlexRogalskiy
AlexRogalskiy / links.txt
Last active September 23, 2022 03:14
Data links
public Mono<String> deleteCustomer(@PathVariable String customerId){
return webClient.delete()
.uri("/customers/" + customerId)
.retrieve()
.bodyToMono(String.class)
.transform(it -> {
ReactiveCircuitBreaker rcb = reactiveCircuitBreakerFactory.create("customer-service");
return rcb.run(it, throwable -> Mono.just(customerId));
});
}
@RestController
@Slf4j
@RequiredArgsConstructor
public class CustomerClientController {
private final WebClient webClient;
private final ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory;
@PostMapping("/customers")
public Mono<CustomerVO> createCustomer(CustomerVO customerVO){
resilience4j.circuitbreaker:
instances:
customer-service:
failureRateThreshold: 50
minimumNumberOfCalls: 10
slidingWindowType: TIME_BASED
slidingWindowSize: 10
waitDurationInOpenState: 50s
permittedNumberOfCallsInHalfOpenState: 3
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> customerServiceCusomtizer() {
return factory -> {
factory.configure(builder -> builder
.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build())
.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "customer-service");
};
}
AmazonEventBridge client = AmazonEventBridgeClient.builder()
.withRegion(Regions.US_EAST_1)
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
PutEventsRequestEntry requestEntry = new PutEventsRequestEntry();
requestEntry.withSource("customer-service") //this needs to match the event pattern defined in step 4 below
.withDetailType("customer-created-detail-type") //this needs to match the event pattern defined in step 4 below
.withDetail(toJson(customerWasCreated)) //this converts the event object into JSON string
.withEventBusName("test-event-bus"); //this needs to match the custom event bus name created in step 4 below
---
name: "tagged-release"
on:
push:
tags:
- "v*"
jobs:
gh_tagged_release:
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
@AlexRogalskiy
AlexRogalskiy / .vimrc
Last active July 14, 2022 07:35
Soft tools
"Gotta be first
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'