I am making a Minecraft spigot plugin in java using redis to broadcast custom messages accross multiple different servers connected to the same redis instance. I am using the https://github.com/InvisRaidinq/redstone library in order to make handling and coding the jedis functions simpler. This works however if no messages are sent over the channel for a significant time all of the jedis subscription / onRecieve logic just stops working and does nothing. I am still able to publish messages to the channel and they do get sent to the redis instance but all of the subscription logic just does nothing.
This is how I am using the library inside my code for one of the plugin commands:
AlertPacket.java
public class AlertPacket implements RedstonePacket {
private final String alert;
public AlertPacket(String alert) {
this.alert = alert;
}
@Override
public void onReceive() {
Bukkit.getScheduler().runTask(Main.getInstance(), () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(alert);
}
});
}
}
AlertCommand.java
redstone.sendPacket(new AlertPacket(input));
Main.java
redstone = Redstone.builder()
.address(getConfig().getString("redis.address"))
.port(getConfig().getInt("redis.port"))
.withCredentials(AuthCredentials.of(getConfig().getString("redis.username"), getConfig().getString("redis.password")))
.channel("main-channel")
.build();
I have also tried using a fork of the original library with a more up to date code base: https://github.com/PedroMPagani/redstone But i still experience the same issues as before without the fork.
I get this error in the console when the i try using the plugin but the subscription logic doesnt work:
[08:38:50 WARN]: Exception in thread "Thread-7" redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:248)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:47)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.Protocol.process(Protocol.java:136)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.Protocol.read(Protocol.java:222)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:350)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.Connection.getUnflushedObject(Connection.java:316)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.JedisPubSubBase.process(JedisPubSubBase.java:115)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.JedisPubSubBase.proceed(JedisPubSubBase.java:92)
[08:38:50 WARN]: at Main.jar//redis.clients.jedis.Jedis.subscribe(Jedis.java:7941)
[08:38:50 WARN]: at Main.jar//xyz.invisraidinq.redstone.manager.connection.ConnectionManager.lambda$initSubscription$2(ConnectionManager.java:78)
[08:38:50 WARN]: at java.base/java.lang.Thread.run(Thread.java:1583)
I expected it to work and just keep the subscription open and perform the logic until I manually disable the plugin and or stop the server.