An open API service indexing awesome lists of open source software.

https://github.com/leonchen83/redis-rdb-cli-api


https://github.com/leonchen83/redis-rdb-cli-api

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# redis-rdb-cli-api

This project used as API in project [redis-rdb-cli](https://github.com/leonchen83/redis-rdb-cli).

# Usage

## 1. Create a maven project with pom.xml

```java

4.0.0

com.your.company
your-service
1.0.0


UTF-8
1.8
1.8



com.moilioncircle
redis-rdb-cli-api
1.8.0
provided


com.moilioncircle
redis-replicator
[3.6.4, )
provided


org.slf4j
slf4j-api
1.7.25
provided









maven-assembly-plugin
3.1.0


jar-with-dependencies




make-assembly
package

single





org.apache.maven.plugins
maven-compiler-plugin
3.8.1

${maven.compiler.source}
${maven.compiler.target}
${project.build.sourceEncoding}



```

## 2. Implement sink service

* create `YourSinkService` implement `SinkService`

```java

public class YourSinkService implements SinkService {

@Override
public String sink() {
return "your-sink-service";
}

@Override
public void init(File config) throws IOException {
// parse your external sink config
}

@Override
public void onEvent(Replicator replicator, Event event) {
// your sink business
}
}

```

* register this service using Java SPI

```java
# create com.moilioncircle.redis.rdb.cli.api.sink.SinkService file in src/main/resources/META-INF/services/

|-src
|____main
| |____resources
| | |____META-INF
| | | |____services
| | | | |____com.moilioncircle.redis.rdb.cli.api.sink.SinkService

# add following content in com.moilioncircle.redis.rdb.cli.api.sink.SinkService

your.package.YourSinkService

```

## 3. Implement formatter service

* create `YourFormatterService` extend `AbstractFormatterService`

```java

public class YourFormatterService extends AbstractFormatterService {

@Override
public String format() {
return "test";
}

@Override
public Event applyString(Replicator replicator, RedisInputStream in, int version, byte[] key, int type, ContextKeyValuePair context) throws IOException {
byte[] val = new DefaultRdbValueVisitor(replicator).applyString(in, version);
getEscaper().encode(key, getOutputStream());
getEscaper().encode(val, getOutputStream());
getOutputStream().write('\n');
return context;
}
}

```

* register this formatter using Java SPI

```java
# create com.moilioncircle.redis.rdb.cli.api.format.FormatterService file in src/main/resources/META-INF/services/

|-src
|____main
| |____resources
| | |____META-INF
| | | |____services
| | | | |____com.moilioncircle.redis.rdb.cli.api.format.FormatterService

# add following content in com.moilioncircle.redis.rdb.cli.api.format.FormatterService

your.package.YourFormatterService

```

## 4. Package and deploy

```java

mvn clean install

cp ./target/your-service-1.0.0-jar-with-dependencies.jar /path/to/redis-rdb-cli/lib
```
## 5. Run

* run your sink service

```java

ret -s redis://127.0.0.1:6379 -c config.conf -n your-sink-service
```

* run your formatter service

```java

rct -f test -s redis://127.0.0.1:6379 -o ./out.csv -t string -d 0 -e json
```

## 6. Debug sink service

```java

public static void main(String[] args) throws Exception {
Replicator replicator = new RedisReplicator("redis://127.0.0.1:6379");
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Replicators.closeQuietly(replicator);
}));
replicator.addExceptionListener((rep, tx, e) -> {
throw new RuntimeException(tx.getMessage(), tx);
});
SinkService sink = new YourSinkService();
sink.init(new File("/path/to/your-sink.conf"));
replicator.addEventListener(new AsyncEventListener(sink, replicator, 4, Executors.defaultThreadFactory()));
replicator.open();
}

```