This tutorial walks developers through creating a presence plugin using MigratoryData’s presence extension API and deploying it in the MigratoryData server.
It also provides an example of a presence plugin that demonstrates how to use MigratoryData’s presence extension API to send push notifications to users who are offline, using Firebase Cloud Messaging (FCM).
Create a presence plugin using presence API
Import the Presence API
import com.migratorydata.extensions.presence.MigratoryDataPresenceListener;
Implement the MigratoryDataPresenceListener interface
The MigratoryDataPresenceListener interface is accessible via Maven as part of the MigratoryData Extensions API, which can be found at:
https://mvnrepository.com/artifact/com.migratorydata/server-extensions-api
Creating the JAR for the Presence Plugin
Compile a JAR containing the compiled code of the class defined in the previous step. Additionally, ensure that the JAR includes a
folder named services
within its META-INF
directory. Within the services
folder,
include a file named com.migratorydata.extensions.presence.MigratoryDataPresenceListener
. The content of this file should be the fully qualified name of the class defined in the previous step.
Install the presence plugin
Rename the JAR obtained in the previous step as presence.jar
and copy it to the folder extensions
of the MigratoryData server for each cluster member in the MigratoryData cluster.
Load the presence plugin
To enable the presence plugin, configure each MigratoryData server in your cluster to load the Presence API feature with the Extension.Presence parameter and activate the Guaranteed Message Delivery feature (since the Presence API operates with Guaranteed Message Delivery) with the ClusterDeliveryMode parameter as follows:
ClusterDeliveryMode = Guaranteed
Extension.Presence = true
To ensure presence replication across your MigratoryData cluster, you might need to enhance your implementation of entitlement with a new entitlement rule. Here are two specific parameters:
- Extension.Presence.Subject:
By default, it's set to/__migratorydata__/presence
- Extension.Presence.EntitlementToken:
By default, it takes its value from theEntitlementAllowToken
parameter
After ensuring the above configurations are in place, restart the MigratoryData server.
Example
We provide an example of a presence plugin that demonstrates how to use MigratoryData’s presence extension API to send push notifications to users who are offline, using Firebase Cloud Messaging (FCM):
https://github.com/migratorydata/migratorydata-demo-chat-fcm-plugin