Building Microservices with Any Framework
Microservice client extensions are framework agnostic. You can choose the technology that best suits your project and skills provided it can leverage Liferay’s REST APIs. This flexibility accelerates the development cycle, making client extensions work for you, not the other way around.
This lesson explains how to set up microservice client extensions with two common application frameworks: Spring Boot (Java) and NodeJS.
Anatomy of Microservice Client Extensions
All configurations and metadata for a client extension reside in the project's client-extension.yaml
file. There are three key components of this this file:
- The assemble block is used during both the build and deployment phase of the client extension. It specifies the source location for resources that should be included in the build.
- The security block sets up Liferay as the authorization server using OAuth standards. This allows applications in the microservice to call the resource server's secure endpoint.
- The definition block configures one of the four microservice subtypes you learned about in the previous lesson (Object Action, Object Validation, Workflow Action, Notification Type). This block provides metadata for the service and specifies the endpoint that it will invoke. You can add one or more definition blocks to a microservice client extension.
These blocks are common to all microservice client extensions. However, the information you provide will vary based on the framework you are using to develop your application. Next, you'll take a closer look at the sample Spring Boot microservice.
Examining the Spring Boot Microservice
The sample Spring Boot microservice provides an example of how you can implement a microservice client extension for a Java application developed with Spring Boot. See the client-extension.yaml
file to understand how it is configured.
Assemble Block
The assemble block for this microservice specifies an executable JAR file for the Spring Boot application.
assemble:
- fromTask: bootJar
Property | Description |
---|---|
fromTask |
Specifies bootJar , an executable file that uses a gradle plugin to bundle the application in the deployment artifact. |
Security Block
The security block for this microservice configures the authorization server with the OAuth user agent application.
liferay-sample-etc-spring-boot-oauth-application-user-agent:
.serviceAddress: localhost:58081
.serviceScheme: http
name: Liferay Sample Etc Spring Boot OAuth Application User Agent
scopes:
- Liferay.Headless.Admin.User.everything
- Liferay.Headless.Admin.Workflow.everything
type: oAuthApplicationUserAgent
Property | Description |
---|---|
serviceAddress |
Specifies the API server address. |
serviceScheme |
Indicates the communication protocol (http or https ). |
name |
Identifies the security application for this microservice. |
scopes |
Grants permissions for specific API resources. |
type |
Specifies the type of client extension service. For the security block, this is oAuthApplicationUserAgent . |
Using OAuth standards, this block defines what kind of access should be granted to headless API resources. The sample Spring Boot microservice has full create, read, update, and delete (CRUD) access to Liferay.Headless.Admin.User.everything
and Liferay.Headless.Admin.Workflow.everything
. Note that permissions do not necessarily have to be this open. You should scope only resources that your client extension explicitly needs to use.
Definition Block
The sample Spring Boot microservice contains multiple definition blocks, each of which invokes a different REST endpoint. Regardless of the subtype, definition blocks use the same standard structure. Here we'll examine just one of the definition blocks from the sample, an object validation rule.
liferay-sample-etc-spring-boot-object-validation-rule-1:
allowedObjectDefinitionNames:
- C_Employee
name: Liferay Sample Etc Spring Boot Spring Boot Object Validation Rule 1
oAuth2ApplicationExternalReferenceCode: liferay-sample-etc-spring-boot-oauth-application-user-agent
resourcePath: /object/validation/rule/1
type: objectValidationRule
Property | Description |
---|---|
allowedObjectDefinitionNames |
Specifies the objects to which this rule applies. Unique to object validation rule subtype. |
name |
Identifies the client extension service with a user friendly name. |
oAuth2ApplicationExternalReferenceCode |
References the OAuth2 application that defines permissions for this client extension. |
resourcePath |
Specifies the REST API URL that should be invoked when the rule is triggered. |
type |
Specifies the microservice subtype: objectValidationRule . |
Spring Boot is only one of the frameworks you can use with microservice client extensions. Next, let's take a look at the sample NodeJS implementation.
Examining the NodeJS Microservice
The sample NodeJS microservice provides an example of how you can implement a microservice client extension for a NodeJS application. See the client-extension.yaml
file to understand how it is configured.
Assemble Block
The assemble block for this microservice specifies an executable JAR file for the Spring Boot application.
assemble:
- include:
- "**/*.js"
- package.json
Property | Description |
---|---|
include |
Specifies the resources that should be included in the build process. This includes JavaScript files (.js ) along with package.json , which provides dependencies for the NodeJS application. |
Security Block
The security block for this microservice configures the authorization server with the OAuth user agent application.
liferay-sample-etc-spring-boot-oauth-application-user-agent:
.serviceAddress: localhost:58081
.serviceScheme: http
name: Liferay Sample Etc Spring Boot OAuth Application User Agent
scopes:
- Liferay.Headless.Admin.User.everything
- Liferay.Headless.Admin.Workflow.everything
type: oAuthApplicationUserAgent
Property | Description |
---|---|
serviceAddress |
Specifies the API server address. |
serviceScheme |
Indicates the communication protocol (http or https ). |
name |
Identifies the security application for this microservice. |
scopes |
Grants permissions for specific API resources. |
type |
Specifies the type of client extension service. For the security block, this is oAuthApplicationUserAgent . |
The security block for the sample NodeJS microservice is identical to that of the Spring Boot microservice.
Definition Block
The sample NodeJS microservice contains multiple definition blocks, each of which invokes a different REST endpoint. Regardless of the subtype, definition blocks use the same standard structure. Here we'll examine just one of the definition blocks from the sample, an object action.
liferay-sample-etc-node-object-action-1:
name: Liferay Sample Node Object Action 1
oAuth2ApplicationExternalReferenceCode: liferay-sample-etc-node-oauth-application-user-agent
resourcePath: /sample/object/action/1
type: objectAction
Property | Description |
---|---|
name |
Identifies the client extension service with a user friendly name. |
oAuth2ApplicationExternalReferenceCode |
References the OAuth2 application that defines permissions for this client extension. |
resourcePath |
Specifies the REST API URL that should be invoked when the rule is triggered.. |
type |
Specifies the microservice subtype: objectAction . |
Again, this structure is identical to that of the Spring Boot microservice. While the backend service and framework may differ from client extension to client extension, the metadata is configured and wired up the same way.
Conclusion
You can leverage the framework-agnostic nature of microservice client extensions to develop backend applications with the framework of your choice, whether that's Spring Boot, NodeJS, or another framework entirely. Next, you'll see a microservice in action by adding custom business logic to Clarity's distributor management app.
Capabilities
Product
Education
Contact Us