Send json message on all servers from spigot server.

Discussion in 'Spigot Plugin Development' started by FailCode, Dec 4, 2019.

  1. Hi. I need Send Json message using TextComponent to all servers.

    Is it possible to implement this on Spigot 1.12.2?
  2. would like to or need?
  3. What do you mean to all servers? On a bungeecord network?
  4. Yes, I mean all servers in bungeecord network.
  5. Okay, some people are going to recommend BungeeCord messaging channels; don’t use those for anything, ever. Here’s why:
    If there are no players on the server you’re sending data to, it will “stack” (it will basically be put in a queue) then, when a player joins that server, all data sent to that server while there were no players online executes all at once, causing very un-intentional side affects. The way these channels were made is that it sends data to a player, not the actual server. Yeah, quite bad.

    Actual solution: use Redis. Redis is, basically, a database that’s made for storing temporary data (it doesn’t read anything from disk, it stores it in RAM on the server where it’s being hosted on) not only this, but it has a feature called “pub/sub” meaning “publish/subscribe”. You can subscribe to channels (which is just a string) and a method that you define will be invoked when data is published to that channel, either by the current server, or any other server that’s publishing data. Basically you’re just publishing a string to a channel name then listening for it everywhere else.

    In your case you can just send your JSON string to that channel and listen for it on every other server.
    #5 Killstreak702, Dec 5, 2019 at 2:41 AM
    Last edited: Dec 5, 2019 at 8:22 AM
    • Agree Agree x 1
  6. Thanks, but I'm using MYSQL.
    I create a plugin on bungeecord which will check every second the database for new data and will output them to all servers in the form of JSON.
    How can I check for data updates in the database?
  7. Every so often, run a mysql query...
  8. How to check whether this element is new, and whether it was previously displayed in messages?
    Simply put, I need to output only new elements from the database to the chat, in order to avoid spam and other problems.
  9. No. Just, no. This is the absolute worst way of doing it and it is plain horrible.

    You do know, you are performing a DISK READ EVERY SECOND when you could use something simpler and faster...I cannot explain how bad this is.
  10. what then will you offer me to do?
  11. There is an option to not queue whatever it is you are trying to send. It all depends on if you need the data when there are no players. For example if you were to chat from one server to another it doesn't need to be queued, it doesn't matter if the server received it. If the data still needs to be sent when there isn't any players online you could possibly just listen for when a player joins and then ask Bungee for the up to date information.