Getting Started
A guide that should kickstart your usage of Proton. Prefer to go through an example? Check out the global chat walkthrough.
Proton as a Dependency
Using Maven
Using Gradle
Setting-up
Setting-up RabbitMQ
If you want to use Proton with RabbitMQ, you will first need to set up an instance of RabbitMQ.
You can do this in one of two ways:
1. Host it yourself
This is for two reasons. One, RabbitMQ restricts the access of the default guest account only to localhost connections. Two, leaving the default username/password leaves you open to attacks.
2. Find an online host
Here are some hosts for RabbitMQ that you may find helpful. One of them actually has a free tier that may fit your needs.
*When choosing a host and plan consider your network's size and needs.
Setting-up Redis
Proton's config.yml
config.yml
Before integrating with Proton, you should configure your servers' Proton configs.
Let's take a look at the config.
There are a lot of options here, but let's look at them in smaller pieces.
The first section is for the configuration of RabbitMQ.
Next we have the Redis
section of the config.
useRedis
sets whether Proton will try to use Redis. (NOTE: Proton only uses one service at a time, if both are selected, Proton will use RabbitMQ)
host
is the ip of your Redis instance.
port
is its port
usePassword
sets whether Proton will try to use a password for the connection
useAuthorization
is the password Proton will try to use.
username
is the username for the connection
password
is the password for the connection
Lastly, we have the identification
section of the config. This is what Proton uses to know which servers are which.
groups
is a list of groups that the current server belongs to. For example, you can have a server that belongs to the group 'hub'. Therefore, when you send a message to the hub group, only servers in that group will receive that message. You can leave groups empty if you don't need it.
checkForUpdates
is a boolean value that enables update checks which will run only once, on server startup.
Your plugin
Proton can run either on Bukkit or Bungeecord
Just make sure that in your plugin.yml
, you include the dependency for Proton.
Proton Usage
Getting an instance to ProtonManager
ProtonManager
To start using Proton, you should first get an instance of ProtonManager
.
Sending your first message
Now that you have a reference to ProtonManager
, you can send your first message.
Let's break down these arguments.
namespace
identifies your organization or plugin. This is what keeps your messages within the scope of your plugin or organizationsubject
is used to identify the type of message you're sending, you can put any value, but we recommend something relevant and descriptive.recipient
is used to define the client or group you wish to send to.data
is the object that you wish to send.
If you want to send a message to all clients that may be listening to a specific namespace
and subject
you can use the broadcast method instead:
The use of .
(period) is not allowed when defining a namespace, subject, recipient, or group. It is a reserved character used for internal processing.
Receiving a message
We tried to model the message receive system similarly to the Event system you probably use regularly.
In any class or object, you can define a MessageHandler
. A MessageHandler
is an annotated method which receives data for a specific MessageContext
.
Let's take a look at the receiving end of the message sent above.
If you want to know the sender of the message, you can attach a second parameter to your MessageHandler
method.
If using bungee, this flag will be ignored and all handlers will be called asynchronously
The final step to actual receive any messages, is to register your MessageHandler(s)
. Similarly to the Event API, you just register your class instance with the ProtonManager
.
If you want, you can register all of your handlers in one call.
Last updated
Was this helpful?