Skip to content

Commit

Permalink
consistent redis configs except event api #85
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Mar 20, 2021
1 parent c0354cd commit 04c049d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ As of initial version, Redis will act as the database for engine operations cons

## Running Modes

### Engine as a service
**Note**: The important thing about Redis.

This is a full deployment with all the components as shown in [Architecture](#architecture-of-oasis).
This provides out-of-the-box components which can be used by your applications.

For testing purpose, a docker compose setup has been provided to up and running locally.

Kubernetes and AWS solution are still pending.
> Redis must be configured in [Replication mode](https://redis.io/topics/replication)
to not losing data. Because all earned game rewards and current processing states are being stored in the Redis.
That means primary database for the engine is the Redis. If you want to store those rewards
in a more durable database like SQL, MongoDB or any NoSQL solution, you can explicitly
intercept through engine by providing a custom signal subscription instance.

### Embedding Engine

Expand Down Expand Up @@ -122,6 +121,16 @@ public static void main(String[] args) throws Exception {

Check the methods of `OasisEngine` class how you can submit your events/rules/game commands.

### Engine as a service

This is a full deployment with all the components as shown in [Architecture](#architecture-of-oasis).
This provides out-of-the-box components which can be used by your applications.

For testing purpose, a docker compose setup has been provided to up and running locally.

Kubernetes and AWS solution are still pending.


## Concepts

This section will introduce you to the concepts around the Oasis framework.
Expand Down
11 changes: 11 additions & 0 deletions engine/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ oasis {
}
}
}

redis = {
host: "localhost"
port: 6379

pool {
max: 16
maxIdle: 8
minIdle: 4
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class RedisDb implements Db {

private static final Logger LOG = LoggerFactory.getLogger(RedisDb.class);

private static final String LOCALHOST = "localhost";
private static final int DEFAULT_PORT = 6379;
private static final int POOL_MAX = 8;
private static final int POOL_MAX_IDLE = 2;
private static final int POOL_MIN_IDLE = 2;

private final JedisPool pool;
private final Map<String, RedisScript> scriptReferenceMap = new ConcurrentHashMap<>();

Expand All @@ -53,12 +59,14 @@ private RedisDb(JedisPool pool) {
}

public static RedisDb create(OasisConfigs configs) {
String host = configs.get("oasis.db.host", "localhost");
int port = configs.getInt("oasis.db.port", 6379);
int poolSize = configs.getInt("oasis.db.pool.max", 5);
int maxIdle = configs.getInt("oasis.db.pool.maxIdle", -1);
int minIdle = configs.getInt("oasis.db.pool.minIdle", -1);

String host = configs.get("oasis.redis.host", LOCALHOST);
int port = configs.getInt("oasis.redis.port", DEFAULT_PORT);
int poolSize = configs.getInt("oasis.redis.pool.max", POOL_MAX);
int maxIdle = configs.getInt("oasis.redis.pool.maxIdle", POOL_MAX_IDLE);
int minIdle = configs.getInt("oasis.redis.pool.minIdle", POOL_MIN_IDLE);

LOG.debug("Connecting to redis in {}:{}...", host, port);
LOG.debug(" - With pool configs max: {}, maxIdle: {}, minIdle: {}", poolSize, maxIdle, minIdle);
JedisPoolConfig poolConfig = new JedisPoolConfig();
if (maxIdle > 0) poolConfig.setMaxIdle(maxIdle);
if (minIdle > 0) poolConfig.setMinIdle(minIdle);
Expand Down
13 changes: 9 additions & 4 deletions services/stats-api/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ oasis = {

defaultApiKey = "root:root"

redis = {
connectionString: "redis://localhost:6379"
maxPoolSize: 4
maxWaitingHandlers: 16
redis {
host: "localhost"
port: 6379

connectionRetries: 5
connectionRetryDelay: 5000

pool = {
max: 16
maxIdle: 16
minIdle: 4
}
}

dispatcher = {
Expand Down
10 changes: 10 additions & 0 deletions simulations/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ oasis {
rule = 5
signal = 10
}
redis = {
host: "localhostxxx"
port: 6379

pool {
max: 16
maxIdle: 8
minIdle: 4
}
}
dispatcher = {
configs = {
host: "localhost"
Expand Down

0 comments on commit 04c049d

Please sign in to comment.