This commit is contained in:
lxy 2020-08-22 11:52:21 +08:00
parent 17b28a9124
commit 23365ae237
3 changed files with 44 additions and 38 deletions

View File

@ -21,6 +21,9 @@ public interface IConsumer<T extends Event> {
String _value = value.split("\"value\":")[1];
_value = _value.substring(0, _value.length() - 1);
Event t = JsonConvert.root().convertFrom(getTypeToken().getType(), value.replace(_value, ""));
if (_value.startsWith("\"") && _value.endsWith("\"")) {
_value = _value.substring(1, _value.length() -1);
}
t.setValue(_value);
accept((T) t);
} else {

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.CompletableFuture;
public abstract class RedisConsumer<T extends Event> implements IConsumer<T>, Service {
@ -27,6 +28,7 @@ public abstract class RedisConsumer<T extends Event> implements IConsumer<T>, Se
@Override
public void init(AnyValue config) {
CompletableFuture.runAsync(() -> {
try {
Socket client = new Socket();
client.connect(new InetSocketAddress(host, port));
@ -70,5 +72,6 @@ public abstract class RedisConsumer<T extends Event> implements IConsumer<T>, Se
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

View File

@ -33,10 +33,10 @@ public class AppTest {
try {
RedisProducer producer = Application.singleton(RedisProducer.class);
Event<Map> event = new Event<>();
Event event = new Event<>();
event.setTopic("c");
event.setKey("abx");
event.setValue(Map.of("A", "a"));
event.setValue(1f);
producer.send(event);