Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into add-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli authored Mar 13, 2024
2 parents 4b5a412 + b9c0485 commit 66c5a35
Show file tree
Hide file tree
Showing 34 changed files with 418 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aws-cloudwatch-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-kinesis-consumer-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-kinesis-producer-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-secretmanager-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-ses-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-sns-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aws-sqs-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK
uses: actions/setup-java@v4.1.0
uses: actions/setup-java@v4.2.0
with:
java-version: 21
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions aws-cloudwatch-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

<java.version>21</java.version>
<spring-cloud-aws.version>3.1.0</spring-cloud-aws.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
<springdoc-openapi.version>2.4.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.43.0</spotless.version>
<dependency-check-maven.version>9.0.9</dependency-check-maven.version>
<properties-maven-plugin.version>1.2.1</properties-maven-plugin.version>
<sonar-maven-plugin.version>3.10.0.2594</sonar-maven-plugin.version>
<sonar-maven-plugin.version>3.11.0.3922</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<jacoco.minimum.coverage>0.80</jacoco.minimum.coverage>
<jacoco.utReportFolder>${project.build.directory}/jacoco/test</jacoco.utReportFolder>
Expand Down
4 changes: 2 additions & 2 deletions aws-dynamodb-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

<java.version>21</java.version>
<spring-cloud-aws.version>3.1.0</spring-cloud-aws.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
<springdoc-openapi.version>2.4.0</springdoc-openapi.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.43.0</spotless.version>
<dependency-check-maven.version>9.0.9</dependency-check-maven.version>
<properties-maven-plugin.version>1.2.1</properties-maven-plugin.version>
<sonar-maven-plugin.version>3.10.0.2594</sonar-maven-plugin.version>
<sonar-maven-plugin.version>3.11.0.3922</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<jacoco.minimum.coverage>0.80</jacoco.minimum.coverage>
<jacoco.utReportFolder>${project.build.directory}/jacoco/test</jacoco.utReportFolder>
Expand Down
18 changes: 11 additions & 7 deletions aws-kinesis-project/consumer/.localstack/init-aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ awslocal kinesis create-stream --stream-name my-test-stream --shard-count 1

awslocal dynamodb create-table \
--table-name spring-stream-lock-registry \
--attribute-definitions AttributeName=lockKey,AttributeType=S AttributeName=sortKey,AttributeType=S \
--key-schema AttributeName=lockKey,KeyType=HASH AttributeName=sortKey,KeyType=RANGE \
--attribute-definitions AttributeName=lockKey,AttributeType=S \
--key-schema AttributeName=lockKey,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--tags Key=Owner,Value=localstack
--tags Key=Owner,Value=localstack \
--billing-mode PROVISIONED

awslocal dynamodb create-table \
--table-name spring-stream-metadata \
--attribute-definitions AttributeName=KEY,AttributeType=S \
--key-schema AttributeName=KEY,KeyType=HASH \
--attribute-definitions AttributeName=metadataKey,AttributeType=S \
--key-schema AttributeName=metadataKey,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--tags Key=Owner,Value=localstack
--tags Key=Owner,Value=localstack \
--billing-mode PROVISIONED

awslocal dynamodb list-tables
awslocal kinesis list-streams
awslocal kinesis list-streams

echo "LocalStack initialized successfully"
65 changes: 48 additions & 17 deletions aws-kinesis-project/consumer/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
version: '3.8'
services:

localstack:
image: localstack/localstack:3.2.0
ports:
- "4566:4566"
environment:
- SERVICES=cloudwatch, dynamodb, kinesis
- DEFAULT_REGION=us-east-1
- EDGE_PORT=4566
volumes:
# - "../.localstack/init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh" # ready hook
- localstack:/tmp/localstack

volumes:
localstack:
version: '3.8'
services:

localstack:
image: localstack/localstack:3.2.0
ports:
- "4566:4566"
environment:
- SERVICES=cloudwatch, dynamodb, kinesis
- DEFAULT_REGION=us-east-1
- EDGE_PORT=4566
volumes:
- "../.localstack/init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh" # ready hook

postgresqldb:
image: postgres:16.2-alpine
hostname: postgresqldb
extra_hosts: [ 'host.docker.internal:host-gateway' ]
environment:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
ports:
- "5432:5432"

pgadmin:
image: dpage/pgadmin4
extra_hosts: [ 'host.docker.internal:host-gateway' ]
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=admin
- PGADMIN_CONFIG_SERVER_MODE=False
- PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False
ports:
- "5050:80"
depends_on:
postgresqldb:
condition: service_started
volumes:
- ./docker_pgadmin_servers.json:/pgadmin4/servers.json
entrypoint:
- "/bin/sh"
- "-c"
- "/bin/echo 'postgresqldb:5432:*:appuser:secret' > /tmp/pgpassfile && chmod 600 /tmp/pgpassfile && /entrypoint.sh"
restart: unless-stopped

volumes:
localstack:
14 changes: 14 additions & 0 deletions aws-kinesis-project/consumer/docker/docker_pgadmin_servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Servers": {
"1": {
"Name": "Docker Compose DB",
"Group": "Servers",
"Port": 5432,
"Username": "appuser",
"Host": "postgresqldb",
"SSLMode": "prefer",
"MaintenanceDB": "appdb",
"PassFile": "/tmp/pgpassfile"
}
}
}
53 changes: 38 additions & 15 deletions aws-kinesis-project/consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<java.version>21</java.version>
<spring-cloud.version>2023.0.0</spring-cloud.version>
<springdoc-openapi.version>2.4.0</springdoc-openapi.version>
<commons-io.version>2.15.1</commons-io.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.43.0</spotless.version>
Expand Down Expand Up @@ -72,41 +71,65 @@
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>${springdoc-openapi.version}</version>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>r2dbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.learning.aws.spring.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.ReactiveAuditorAware;
import org.springframework.data.r2dbc.config.EnableR2dbcAuditing;
import reactor.core.publisher.Mono;

@Configuration(proxyBeanMethods = false)
@EnableR2dbcAuditing
public class AuditingDatabaseConfig {

@Bean
ReactiveAuditorAware<String> auditorAware() {
return () -> Mono.just("App");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.aws.spring.entities.IpAddressEvent;
import com.learning.aws.spring.model.IpAddressDTO;
import com.learning.aws.spring.repository.IpAddressEventRepository;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,6 +23,7 @@
public class IpConsumer {

private final ObjectMapper objectMapper;
private final IpAddressEventRepository ipAddressEventRepository;

// As we are using useNativeDecoding = true along with the listenerMode = batch,
// there is no any out-of-the-box conversion happened and a result message contains a payload
Expand Down Expand Up @@ -56,7 +60,28 @@ public Consumer<Flux<List<Record>>> consumeEvent() {
"IpAddress processed at {} and value is:{}",
LocalDateTime.now(),
ipAddressDTOsList);
this.processEvents(ipAddressDTOsList);
})
.subscribe();
}

private void processEvents(List<IpAddressDTO> ipAddressDTOsList) {
for (IpAddressDTO ipAddressDTO : ipAddressDTOsList) {
insertToDB(ipAddressDTO);
}
}

private void insertToDB(IpAddressDTO ipAddressDTO) {
IpAddressEvent ipAddressEvent = new IpAddressEvent(ipAddressDTO.ipAddress());
// adds artificial latency
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
ipAddressEventRepository
.save(ipAddressEvent)
.subscribe(savedEvent -> log.info("Saved Event :{}", savedEvent));
}
}
Loading

0 comments on commit 66c5a35

Please sign in to comment.