Backend messaging system for Java stuffs
// Set our server IDUUIDserverId = UUID.randomUUID();
// Create a new non-redundant PacketService with 4 sending threads and a packet version of 1.PacketServicepacketService = newPacketService(4, false, (byte) 1);// Create a new messaging handler implementationMessagingHandlerImplhandlerImpl = newMessagingHandlerImpl(packetService);
// Create a new server messaging handler implementation - should extend AbstractServerMessagingHandlerAbstractMessagingHandlerserverHandler = newServerMessagingHandlerImpl(serverId, packetService, handlerImpl);
// Add the server messaging handler to the messaging handler implementationhandlerImpl.addHandler(serverHandler);
// Create your own custom messaging handler - should extend AbstractMessagingHandlerAbstractMessagingHandlercustomHandler = newCustomMessagingHandler(packetService);
// Add the custom messaging handler to the messaging handler implementationhandlerImpl.addHandler(customHandler);// Create a new RabbitMQMessagingService// The name of this service is "engine1" and uses the RabbitMQ channel "my-data" for all packets// This service will have no startup delay (ie. will instantly start receiving packets)// This service will *not* dump packets to disk, although the directory for those dumped packets will be packetDir// Dumping packets is useful for Zstd trainingRabbitMQMessagingServicerabbit = RabbitMQMessagingService.builder(packetService, "engine1", "my-data", handlerImpl, 0L, false, packetDir)
.url("127.0.0.1", 5672, "/") // Connect to 127.0.0.1:5672 @ vhost "/"
.credentials("guest", "guest") // With guest user/pass
.timeout(5000) // With a timeout of 5 seconds
.build();
// Queue a packet through the packetservicepacketService.queuePacket(newKeepAlivePacket(serverId));
// Queue several packets through the packetservicepacketService.queuePackets(
newInitializationPacket(serverId, packetService.getPacketVersion())
newCustomDataPacket()
);
// Flush the packetService queue to actually send any packets that have been previously queuedpacketService.flushQueue();AbstractServerMessagingHandlerwill remove any servers that have not broadcastedKeepAlivePackets in 20 seconds.AbstractServerMessagingHandlerrequiresInitializationPackets to be sent on startup, andPacketVersionPacketresponses toPacketVersionRequestPacketsAbstractServerMessagingHandlerprefers handlingShutdownPackets over a missedKeepAlivePacketon shutdownPacketService#queuePacketandPacketService#queuePacketsdo not actually broadcast packets -PacketService#flushQueuewill perform the broadcasting functionality with any packets queued. This allows for batching packets into aMultiPacketautomatically