Skip to content

Commit

Permalink
events api with spring webflux #140
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Apr 15, 2024
1 parent a3eae2a commit 2f28986
Show file tree
Hide file tree
Showing 97 changed files with 888 additions and 176 deletions.
21 changes: 20 additions & 1 deletion core/src/main/java/io/github/oasis/core/EventJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package io.github.oasis.core;

import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -44,6 +45,7 @@ public EventJson() {
}

public EventJson(Map<String, Object> ref) {
this.ref = ref;
this.id = (String) ref.get(Event.ID);
this.type = (String) ref.get(Event.EVENT_TYPE);
this.userName = (String) ref.get(Event.USER_NAME);
Expand All @@ -53,7 +55,24 @@ public EventJson(Map<String, Object> ref) {
this.sourceId = ((Number)ref.get(Event.SOURCE_ID)).intValue();
this.gameId = ((Number)ref.get(Event.GAME_ID)).intValue();
this.tz = (String) ref.get((Event.TIMEZONE));
this.ref = ref;
}

public EventJson duplicate() {
if (this.ref != null) {
return new EventJson(this.ref);
}

var fields = new HashMap<String, Object>();
fields.put(Event.ID, id);
fields.put(Event.EVENT_TYPE, type);
fields.put(Event.USER_NAME, userName);
fields.put(Event.SOURCE_ID, sourceId);
fields.put(Event.GAME_ID, gameId);
fields.put(Event.TEAM_ID, teamId);
fields.put(Event.TIMESTAMP, ts);
fields.put(Event.TIMEZONE, tz);
fields.put(Event.USER_ID, userId);
return new EventJson(fields);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ private void parseDefinitions(Object value, GameDef gameDef, ParserContext parse
engineMessage.setImpl(elementPluginType);
engineMessage.setData(elementDef);
gameDef.addRuleDefinition(engineMessage);
} else if (def instanceof String) {
String refPath = (String) def;

} else if (def instanceof String refPath) {
String fullPath = parserContext.manipulateFullPath(refPath);
parserContext.pushCurrentLocation(fullPath);
InputStream refData = parserContext.loadPath(fullPath);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/github/oasis/core/utils/CacheUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
/**
* @author Isuru Weerarathna
*/
public final class CacheUtils {
public interface CacheUtils {

private static final String DOT = ".";
static final String DOT = ".";

public static String getSourceCacheKey(String sourceToken) {
static String getSourceCacheKey(String sourceToken) {
return ID.EVENT_API_CACHE_SOURCES_KEY + DOT + sourceToken;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;

public final class ReflectionUtils {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.oasis.ext.kafkastream.runners;

public class TestTransaction {




}
File renamed without changes.
162 changes: 162 additions & 0 deletions services/events-api-old/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>oasis-services</artifactId>
<groupId>io.github.oasis</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>events-api</artifactId>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-service-proxy</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-config</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-config-yaml</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-redis-client</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.github.oasis</groupId>
<artifactId>oasis-ext-kafkastream</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<version>${vertx.version}</version>
<classifier>processor</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.104.Final</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>oasis-events-api</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessors>
<annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
</annotationProcessors>
<generatedSourcesDirectory>${project.basedir}/src/main/generated</generatedSourcesDirectory>
<compilerArgs>
<arg>-Acodegen.output=${project.basedir}/src/main</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/generated</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>io.github.oasis.services.events.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

</project>
70 changes: 70 additions & 0 deletions services/events-api-old/src/main/resources/defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
http:
port: 8050
ssl: false

# Set this to true, if you want to disable event integrity check against valid event sources registered
# through admin api. By default, this will be set to false and it means, event integrity will be enforced.
# Setting this to true, will still want to register a event source in admin api for authentication purpose.
# Beware: Disabling integrity check should be done only if you can guarantee that this event api will
# never be exposed as a public api. Otherwise, external users may send events which causes the
# bad impact to the integrity of game play.
skipEventIntegrityCheck: false

oasis:

adminApi:
baseUrl: "http://localhost:8010/api"

eventSourceGet: "/admin/event-source"
playerGet: "/players"

# authentication details of admin api
apiKey: "eventapi"
secretKey: "eventapi"


eventstream:
impl: "oasis:io.github.oasis.ext.kafkastream.KafkaStreamFactory"
configs:
brokerUrls: "localhost:9092"

maxConsumerThreadPoolSize: 4

gameEventsConsumer:
# groupId = ""

# If not specified, this will take engine id
# instanceId = ""

# These props will directly feed to Kafka property configs
# Check kafka consumer documentation for supported props.
props:
#"max.poll.records": 10,
#"session.timeout.ms": 86400000

broadcastConsumer:
# groupId = ""

# These props will directly feed to Kafka property configs
# Check kafka consumer documentation for supported props.
props:

dispatcherConfigs:
props:

engineEventConsumer:
props:

cache:
impl: "oasis:io.github.oasis.services.events.db.RedisVerticle"
configs:
connectionString: "redis://localhost:6379"
maxPoolSize: 16
maxWaitingHandlers: 16

# expiration seconds for once cached event source data.
# Better to have a ttl based on your domain.
# Longer TTLs will suffer from event source updates in admin api.
# Shorter TTLs will suffer from unnecessary invocations to admin api.
# If this value is not set, no expiration will set for cached entries.
eventSourcesTTL: 900
Loading

0 comments on commit 2f28986

Please sign in to comment.