Deploying and Managing a Microservice Client Extension Project
Kyle wants to start developing a custom application using a microservice client extension to help keep track of user-submitted feedback.
Here, you’ll start by trying out a sample microservice client extension using Spring Boot from Liferay’s sample workspace.
Download the Sample Workspace
Download and unzip the sample workspace for client extensions on your machine:
curl -o com.liferay.sample.workspace-latest.zip https://repository.liferay.com/nexus/service/local/artifact/maven/content\?r\=liferay-public-releases\&g\=com.liferay.workspace\&a\=com.liferay.sample.workspace\&\v\=LATEST\&p\=zip
unzip com.liferay.sample.workspace-latest.zip
Once you have the workspace unzipped, open the client-extensions/liferay-sample-etc-spring-boot/
folder to proceed.
Configure the Sample Spring Boot Project
The sample Spring Boot project uses an application.properties
file to register important values, including the target Liferay instance’s domain. Configure the Spring Boot project before you deploy it.
-
In the sample Spring Boot project you downloaded, open the
src/main/resources/application.properties
file. -
Add properties for the
com.liferay.lxc.dxp.domains
andcom.liferay.lxc.dxp.mainDomain
using your UAT site’s domain (e.g.,uat.delectablebonsai.com
):com.liferay.lxc.dxp.domains=YOUR DOMAIN com.liferay.lxc.dxp.mainDomain=YOUR DOMAIN
-
Add another property for the
https
protocol:com.liferay.lxc.dxp.server.protocol=https
Now the project is correctly configured for your Liferay SaaS instance and ready to deploy.
Deploying to Your Liferay SaaS Instance
Build and deploy the project to your Liferay SaaS instance from the sample Spring Boot project’s folder.
-
Run this command to build the project into a deployable LUFFA:
../../gradlew clean build
The build first runs the
bootJar
Gradle task (because it’s defined in theclient-extension.yaml
file), and then generates the LUFFA containing all of the necessary components for deployment in thedist/
folder. -
Use the CLI tool to deploy the built LUFFA:
lcp deploy --extension dist/liferay-sample-etc-spring-boot.zip
When prompted, choose the number that corresponds to your UAT client extension environment.
The client extension is deployed to your UAT environment, and it appears in the Cloud console after a delay. The Ready status appears when the service container is running and the Spring Boot application starts.
Add Object Data
Liferay objects are an ideal way to persist and manipulate data in Liferay with your client extensions.
Create an object definition with an action that invokes one of the object action client extensions in the project you deployed.
Create an Object Definition
-
Log into your UAT Liferay instance.
-
Open the Applications menu ( ) → Control Panel → Objects.
-
On the Objects page, click Add ( ), and fill in the New Custom Object form:
-
Label: Feedback Input
-
Plural Label: Feedback Inputs
-
Object Name:
FeedbackInput
-
-
Click Save.
The object definition is created as a draft, but it still needs a field and an action to use the object action client extension.
Add a Boolean Field
-
Click the Feedback Input object definition on the objects list to edit it.
-
Click the Fields tab.
-
Click Add ( ), and fill in the New Field form:
-
Label: Was this helpful?
-
Field Name:
helpful
-
Type: Boolean
-
-
Click Save.
Add an Action Invoking Your Client Extension and Publish
-
Click the Actions tab.
-
Click Add ( ).
-
Fill in the Basic Info form for the action:
-
Action Label: New Feedback
-
Action Name:
NewFeedback
-
-
Click the Action Builder tab.
-
In the Trigger drop-down menu, select On After Add.
-
In the Action drop-down menu, select
object-action-executor[function#liferay-sample-etc-spring-boot-object-action-1]
. -
Click Save.
-
Navigate back to the object definition’s Details tab and click Publish.
Now the object definition is published and you can use it to submit object data.
Submit Some Object Data
Now add a form using your new object definition so you can test the object action.
-
Navigate back to your site’s home page.
-
Click Edit ( ) at the top of the page.
-
In the list of fragments on the left side of the screen, drag the Form Container fragment onto the page.
-
In the Form Container’s drop-down menu, select your new Feedback Input object definition.
-
Click Publish at the top of the page.
The form appears on the page with a single “Was this helpful?” checkbox.
- Click the Submit button.
An object entry is created once you submit the form, and that invokes the object action client extension you deployed.
Examine the Results in the Cloud Console
Now that you’ve triggered the object action, check the Spring Boot application’s logging to see that the call was successful.
-
Log into the Cloud console and navigate to your UAT environment.
-
Click Logs on the left side of the screen.
Now you can see the liferaysampleetcspringboot
service’s logs, and you can see the Spring Boot application logs printing out the object data Liferay sent to it.
Now you can see the object action works successfully.
Delete the Microservice
Kyle plans to try customizing this object action, but doesn’t need this version deployed on the UAT environment while he figures out what to add to it.
Delete the service from the console now that you’re done using the sample microservice.
-
On the service’s page, click Actions ( ) in the top-right corner, and click Delete Service.
-
Enter
liferaysampleetcspringboot
to confirm the impact of the deletion. -
Click Delete Service.
Deleting the client extension service also breaks the link to your object definition’s action. Normally, you’d also remove the object action that’s now not in use, but in this instance you’ll leave it in place to save the step of recreating it for the next exercise.
After a delay, the service is deleted and disappears from the Cloud console.
Now you’ve successfully tested the sample Spring Boot application in UAT.
Next: troubleshoot a problem in the console.