Onboarding a Micronaut based REST API service
As an API developer, you can onboard a REST service to the Zowe API Mediation Layer using the Micronaut framework. While using the Spring framework to develop a JVM-based service to register to the API ML is the recommended method, you can use the procedure described in this article to onboard a service using the Micronaut framework.
Note: For more information about onboarding API services with the API ML, see the Onboarding Overview.
For Micronaut-related documentation, see the Micronaut website.
- Set up your build automation system
- Configure the Micronaut application
- Validate successful registration
#
Set up your build automation systemCurrently, the only build automation system for use with onboarding a Micronaut based service is Gradle.
Follow these steps:
Create a
gradle.properties
file in the root of your project if one does not already exist.In the
gradle.properties
file, set the URL of the specific Artifactory containing the SpringEnabler artifact.Add the following Gradle code block to the
repositories
section of yourbuild.gradle
file:In the
build.gradle
file, add the micronaut enabler as a dependency:(Optional) Add a shadow plug-in to create a runnable jar file. Update the
gradle.build file
with a plugin:Specify the main class with the following script:
Define the output jar file.
Add the following script to define the output of the jar file:
The following example shows a sample
gradle.build
file:Example:
(Optional) Create a shadow jar.
To create a shadow jar, execute the gradle
shadowJar
task. For this sample, the plugin produces the jarmicronaut-enabler-1.0.jar
inbuild/libs
directory.You can now run your application with the command
java -jar micronaut-enabler-1.0.jar
.Start the application.
From the root directory of your project, start the application with the
gradle run
command.
#
Configure the Micronaut applicationUse a yaml file to configure your Micronaut application. Create the following two sections in your yaml file:
apiml
for API ML configurationmicronaut
for micronaut configuration
#
Add API ML configurationUse the following procedure to add API ML configuration to the application.yaml.
Follow these steps:
Add the following configuration to the
apiml
section in the yaml file:where:
fill.your.service
specifies the ID of your service
Add SSL-resolving properties as shown in the following example. Ensure that you structure the nested objects within
apiml.service
as arrays. Be sure to include-
(hyphen) beforeenabled
thereby indicating the first element of the array.
Example:
Note: For a sample of this configuration, see API ML Onboarding Configuration Sample.
The yaml now contains configuration to register to the API Mediation Layer.
#
Add Micronaut configurationOnce you complete API ML configuration, add configuration to provide correct mapping between API ML and micronaut parameters.
Follow these steps:
Add the following yaml snippet with the micronaut configuration parameters:
where:
apiml.service.serviceId
specifies the ID of your service
apiml.service.port
specifies the port on which the service listens
apiml.service.ssl[0].keyPassword
specifies the password that protects the key in keystore
apiml.service.ssl[0].keyStoreType
specifies the type of the keystore, (Example: PKCS12)
apiml.service.ssl[0].keyStore
specifies the location of the keystore
apiml.service.ssl[0].keyAlias
specifies the alias under which the key is stored in the keystore
apiml.service.ssl[0].trustStorePassword
specifies the password that protects the certificates in the truststore
apiml.service.ssl[0].trustStore
specifies the location of the truststore
apiml.service.ssl[0].trustStoreType
specifies the type of the truststore, (Example: PKCS12)
apiml.service.ssl[0].ciphers
specifies the list of ciphers that user wants to enable for TLS communication
apiml.service.ssl[0].protocol
specifies the type of SSL/TLS protocol (Example: TLSv1.2)
#
(Optional) Set up logging configurationSet up custom logging configuration to have more structured output and better control of logs.
Create a logback.xml
file in the resources
folder and include the application.yml
. Update the logback.xml
file with the following configuration:
#
Validate successful registrationAfter you complete the configuration, ensure that your application is visible within Zowe API ML. For more information, see the article validating the discoverability of your API service by teh Discovery Service, which describes the validation procedure common for all enablers.