#Redis pattern pub/sub questions
1 messages ยท Page 1 of 1 (latest)
This is how i initialize the lib, my goal is next:
- If you dont tell the servers
property, it will use the channel pattern<channel>:globalas defauult - In case you give any server via the servers property, it will subscribe to the next pattern
<channel>:<server>
// Redis settings
RedisInfo builder = RedisInfo.builder()
.uri("") // Redis connection uri
.server("proxy-1") // Current server name
.servers("skywars") // All registered servers
.build();
// Creating api instance
RedisAPI redis = new RedisHandler(builder);
redis.connect();
// Creating broker instance
RedisBroker broker = redis.newBroker("plugin-sync"); // We pass the channel we want to use
// Registering listener(s)
broker.getEvents().register(new NetworkListener());
// Registering packet(s)
broker.getPackets().register(new UserPacket());
broker.getPackets().register(new TextPacket());
// Sending packets
broker.publish(packet); // Publish to pattern <channel>:global
broker.publish(packet, server); // Publish to pattern <channel>:<server>
So at the momment i have the next code:
public class RedisListener extends JedisPubSub {
private final BrokerService broker;
public RedisListener(BrokerService broker) {
this.broker = broker;
}
@Override
public void onPMessage(String pattern, String channel, String data) {
if (!channel.equals(broker.getChannel())) return;
Payload payload = broker.getRedis().getInfo().getGson().fromJson(data, Payload.class);
if (payload == null) throw new RedisException("[Redis] An invalid payload was received");
JsonObject packet = broker.getRedis().getInfo().getGson().fromJson(payload.getPacket(), JsonElement.class).getAsJsonObject();
System.out.println("[Jedis-Listener] Received channel=" + channel + " pattern=" + pattern + " packet=" + packet);
}
Which is the question?
So far im sending a packet
But the sout() is never sent
Debug capture from the packet sender
Debug capture from the receiver, if you the data never is received
How/Where are you sending the data?
Right
1m
This how im subscrbing, a subscription into global channel is always done + the servers you input into the settings
Global publisher
Server publisher (specific server)
Do you need something else, or this is enoguht?
At the moment none of the publishers data is sent
Which Redis dependency are you using? So I can see docs
Jedis
I will lok the exact version
Jedis 4.3.1
And to listen for data im using JedisPubSub with pattern
Really thanks man, i have been many hours with this. Before implenting the patters i was using normal onMessahe() method but the data wasnt bein received correctly
I wont lie im really stressed and feeling really idiot because i cant implement such a simple thing ๐ฎโ๐จ
Apparently everything is setup correctly. I guess you already done the
Jedis jedis = new Jedis("address", PORT);
And the jedis.subscribe(LISTENER, "channel")
Yes, instead of subscribe im using the psubscribe whcih allow you to use patterns
Yes the connection is done thru my RedisHandler class, so dont worry about it
Let's try something, subscribe to a "dummy" channel, and try to send data into that dummy channel
Instead of using psubscribe
Yes i did that before
And was working perfect
Just having problems to implement my logic having 1 global channel for all servers and an individual channel per server
Can I see your psubscribe argument?
yes no problem
Also try debugging what is being parsed as the channel argument, maybe it's not the same
public BrokerService(RedisAPI redis, String channel) {
this.redis = redis;
this.channel = channel;
this.events = new EventsManager(redis.getInfo().getExecutor());
this.packets = new PacketsManager();
String[] channels = Collections.add(Stream.of(redis.getInfo().getServers()).map(server -> server = channel + ":" + server).toArray(String[]::new), channel + ":global");
redis.getInfo().getExecutor().execute(() -> redis.getClient().getResource().psubscribe(new RedisListener(this), channels));
System.out.println("[RedisBroker] Subscribed to channels=" + Arrays.toString(channels));
}```
Collections#add is a custom method if you are asking, you give String[] input, then the value is add to the input and return back
Maybe the sender is not actually able to send data, because he's not subscribed to the actual channel. Let me explain.
According to these debugs:
Which I'll guess:
#1 = BungeeCord
#2 = SkyWars
Maybe to send data to plugin-sync:skywars to the SkyWars server, the SkyWars server must be subscribed too into that channel (just as an example)
Basically, both debugs should contain at least 2 same channels (the one for the server, and the one global)
oh okay
I guess you are sending though plugin-sync:skywars
Pretty sure if you switch to global, It may work
okay, and how would do then, because the data wil be self listened ?
Talking individual server channel
Try it and see what happens
But I don't think Redis would send the client who send data the message with the data he just sent
In the worst case, you will see a message received on both clients
Did it work?
1m
I will subscribe the server itself
So each client, must be subscribed to global channel and individual channel right?
At least
Perfect ill modify code and test it
So each client is able to listen on his self channel, and in the global one
right, so from redis xp the client self listen the data he sent, so there i would add some checks
Because my payload is like this sender (string), receiver (string) and packet (json)
What about the destination, does him receive the message?
I couldnt success tho
๐
Lamo shity redis
After some research I found something interesting:
https://stackoverflow.com/questions/26406303/redis-key-expire-notification-with-jedis/26406598#26406598
I am trying to implement a expiry key notification with redis ,when my key expires in the redis data store. The redis website provides some description of how http://redis.io/topics/notifications, ...
This might help you
Oh really thanks man