In advanced cases, custom services may need to be called within other Pragma Engine RPC flows. We’ve provided a set of configurable plugins that can be customized and overridden to add in your functionality.
Plugins are classes that can be enabled via configuration. When enabled, they provide an opportunity to inject custom code into existing Pragma Engine services.
It’s possible to call your custom service via a service-to-service RPC call from within a plugin.
Copy over a relevant provided default plugin from platform/2-pragma/game-common/src/main/kotlin/pragma/ into your custom service directory to preserve existing behavior. To add the new service, add a new dependent job line to the listOf().
MyCustom example
During the MatchLifecycle, when a match ends, basic functionality can grant rewards or items on completion. For the MyCustom example, we’ll use a MatchEndPlugin to add additional match-end processes.
Create a file called MyCustomMatchEndPlugin.kt in the 5-ext/src/main/kotlin/myproject/matchlifecycle/ directory, and replicate the DefaultPragmaMatchEndPlugin from platform/2-pragma/game-common/src/main/kotlin/pragma/matchlifecycle/. Add the MyCustomMatchEndDependentJob to the listOf to add the MyCustom service to the MatchEndPlugin.
Using the SERVICE session within a plugin enables communication with other services. This requires building a custom RPC endpoint using the SERVICE session, which needs its own request/response protos.
MyCustom example
The RPC endpoint should look something like this:
valresult=service.requestRpc(MyCustomRpc.MyCustomActionServiceV1Request.newBuilder().setCustomId(customId).setCustomData(customData).build(),MyCustomRpc.MyCustomActionServiceV1Response::class)when(result){isPragmaResultResponse->{logger.info("MyCustomAction returned ${result.response} successfully.")}isPragmaResultError->{logger.error("Something went wrong with MyCustomAction.")}}
The dependent job pattern handles interactions between multiple interdependent RPC service calls.
There are two key pieces: dependenciesMet and makeRequest.
dependenciesMet is called before running this dependent job to determine if prior RPC calls this job depends on have completed.
makeRequest is called when all required dependencies have been found on the context. Within this function you can perform calculations, business logic or send off requests to other services and await their response.
MyCustom example
The MyCustomMatchEndPlugin can trigger multiple interdependent RPC service calls. The MyCustomMatchEndDependentJob handles these interactions.
We use cookies to analyze our traffic. We also share information about your use of our site with our analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.