Messaging (RabbitMQ)
MessagingService in commons provides RabbitMQ-based inter-server communication with pub/sub and RPC patterns.
Configuration
Set the connection details in plugins/AstralCore/config.yml:
Connection State
The service connects automatically on plugin enable and disconnects on disable. The connection lifecycle emits state change events:
State | Meaning |
|---|---|
| Attempting to establish the AMQP connection |
| Connection is active |
| Graceful shutdown in progress |
| No active connection |
| Connection attempt failed (will retry with backoff) |
Monitor state changes:
Pub/Sub — Publishing a Packet
Pub/Sub — Subscribing to an Exchange
The listener receives the decoded Packet instance and RabbitMQ's Envelope metadata.
RPC — Request with Reply
RPC — Handling Requests
Core Exchanges
Built-in exchanges used by AstralCore internally:
Constant | Exchange name | Purpose |
|---|---|---|
|
| Server registration, heartbeat, status |
|
| Player join/quit network events |
|
| Cross-server teleport requests |
|
| Discord account linking |
Thread Pool
The service uses a fixed thread pool with 6 threads (named AstralCore-RabbitMQ-*) for all AMQP operations. This prevents unbounded thread creation under high traffic.
Traffic level | Recommended pool size |
|---|---|
Low | 4 |
Medium (default) | 6 |
High | 8–10 |
The pool size is defined in commons/src/main/java/com/astralrealms/core/messaging/MessagingService.java:44 as RABBITMQ_THREAD_POOL_SIZE.
Self-message Filtering
Every MessagingService instance generates a random SENDER_ID UUID on startup. Outgoing packets are wrapped with this ID, and incoming packets from the same sender are silently discarded. This prevents a server from processing its own broadcasts.
Packet Registration
Packets are registered by integer ID in PacketRegistry. All built-in packets are pre-registered. To add a custom packet:
Implement the Packet interface with write(BinaryMessage) and read(BinaryMessage) for binary serialisation.