WireMock

Some code for WireMock. @Test public void test() throws Exception { String url = “http://localhost:8080/v3”; stubFor(get(urlPathEqualTo(“/v3”)).willReturn(aResponse() .withHeader(“Content-Type”, “application/json”) .withBody(“{ \”id\”: 123, \”name\”: \”John Doe\” }”) .withStatus(200))); stubFor(get(urlPathEqualTo(“/v4”)).willReturn(aResponse() .withHeader(“Content-Type”, “application/json”) .withBody(“{ \”id\”: 123321, \”name\”: \”John Doe\” }”) .withStatus(200))); stubFor(get(urlPathEqualTo(“/v3”)) .withQueryParam(“abc”, equalTo(“5”)) .willReturn(aResponse() .withHeader(“Content-Type”, “application/json”) .withBody(“{ \”id\”: v33, \”name\”: \”John Doe\” }”) .withStatus(200) )); HttpClient client =… Read More »

faceswap

need to use python 3.10. use conda to install: Check current conda envs: conda env list Use an env: source activate myenv quite env: conda deactivate use pyenv to change to python 3.10 to start faceswap python faceswap.py gui usage for faceswap. https://www.youtube.com/watch?v=Xhzf5DsmLu0

surefire, failsafe

surefire, failsafe are maven plugin tools. surefire focus on unit test: mvn surefire:test failsafe focus on integration-test: mvn failsafe:integration-test Also need build-helper-maven-plugin to specify the integration test folder <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>${mojo.build-helper-maven-plugin.version}</version> <executions> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/it/java</source> </sources> </configuration> </execution> <execution> <id>add-test-resource</id> <phase>generate-test-resources</phase> <goals> <goal>add-test-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/it/resources</directory> </resource>… Read More »

Add log4j MDC log tags in webflux

Webflux is async. So log4j with MDC tags may not work correctly natively. So adding below to copy MDC context in each operator changes. Hooks is some advanced usage for customizing action in operators. 1. MdcContextLifterConfiguration @Configuration public class MdcContextLifterConfiguration { private static final String MDC_CONTEXT_REACTOR_KEY = MdcContextLifterConfiguration.class.getName(); @PostConstruct private void contextOperatorHook() { Hooks.onEachOperator( MDC_CONTEXT_REACTOR_KEY, Operators.lift((scannable, coreSubscriber)… Read More »

Adding tags for micrometer in WebFlux

Try WebFluxTagsProvider, DefaultWebFluxTagsProvider. @Component @Primary public class ObserveWebFilter extends DefaultWebClientExchangeTagsProvider implements WebFluxTagsProvider { private static final WebFluxTagsProvider WEB_FLUX_TAGS_PROVIDER = new DefaultWebFluxTagsProvider(); @Override public Iterable<Tag> httpRequestTags(ServerWebExchange exchange, Throwable ex) { HttpHeaders headers = exchange.getRequest().getHeaders(); return Tags.concat(WEB_FLUX_TAGS_PROVIDER.httpRequestTags(exchange, ex), ObserveUtils.tags(headers)); } public Iterable<Tag> tags(ClientRequest request, ClientResponse response, Throwable throwable) { HttpHeaders headers = request.headers(); return Tags.concat(super.tags(request, response, throwable), ObserveUtils.tags(headers)); }… Read More »

Some useful Kafka command

Get the max partition:offset for a topic ./kafka-run-class.sh kafka.tools.GetOffsetShell –broker-list broker-ip:port –topic topic-name Get current partition:offset for a consumer group ./kafka-consumer-groups.sh –bootstrap-server broker-ip:port –group consumer-group-name –describe Get a single record by partition:offset ./kafka-console-consumer.sh –bootstrap-server broker-ip:port –topic topic-name –max-messages 1 –partition 54 –offset 90012464 Tailing Kafka topic in real time ./kafka-console-consumer.sh –bootstrap-server broker-ip:port –topic topic-name Set a ConsumerGroup offset to latest ./kafka-consumer-groups.sh –bootstrap-server server:port… Read More »

DynamodDb access in Java(Code)

Assume we have below data in DynamoDb. All fields are String type. PK is ID, SK is name. We use DynamoDbEnhancedAsyncClient to access DynamoDb data. To get a specific record with (PK, SK): public static void testGetItem() throws Exception { CompletableFuture<Record> recordFuture = table.getItem(Key.builder() .partitionValue(“001”) .sortValue(33) .build()); System.out.println(recordFuture.get()); } To query only on PK: public static… Read More »

DynamoDB access in Java(structure)

1. dynamodb vs dynamodb-enhanced 1). software.amazon.awssdk, dynamodb 2). software.amazon.awssdk, dynamodb-enhanced, a high-level library. Can map class to DynamoDb tables. Introducing enhanced DynamoDB client in the AWS SDK for Java v2 2. Client vs Table DynamoDbClient/DynamoDbEnhancedClient is like databases access. Think you know the username/password to the database. DynamoDbTable/DynamoDbAsyncTable is the table you will operate on.… Read More »