Microservice Client Extension using Go

(or any other language)

Caption

Introduction

After playing with Go for the last few days and wanting to check out Microservice Client Extensions (MCEs), I decided to put up this starter project on Github and write my first blog post on liferay.dev.

This is less about how to write code in Go, but about the process to get everything running in my local (Docker) environment. It might be helpful for MCEs written in other languages as well...

Setup

I'm using the liferay/dxp:2025.q1.4-lts Docker Image, but according to the docs, MCE should work on any Liferay 7.4+ version.

  1. The first thing I noticed when checking the Packaging Client Extensions docs and checking the Liferay examples for Spring Boot and  Node.js was the required LCP.json file, which configures the container if the MCE is deployed to Liferay Cloud. The MCE will not compile if the file is missing or empty, but an empty Object {} is enough to compile and I didn't encounter any issues doing this on my local setup. Since I don't have access to a Liferay Cloud instance, I didn't want to add code here that might not work in the Cloud πŸ˜‰

  2. A Dockerfile is also required, even if you might not be making your Microservice available to Liferay via Docker. You can compile and deploy the extension with an empty Dockerfile though.

  3. And of course the client-extension.yaml config file, which should be explained pretty well by the docs and looking at the code.

Go

Since this is just a starter project, there is not much code that needs to be explained if you know the basics of Go. If you don't, I can recommend this short or long Go Tutorial from ​​​​​​​Nana, a fellow Vienna local.
The majority of the time was put into reading up on JWT & JWKS and using the JWx module to verify incoming requests. This will vary depending on your language of choice, but the Liferay examples listed above help to get an overview.
​​​​​​​​​​​​​​From what I could discern, Liferay always sends a POST request with JSON data for the four currently available types (Object Action, Object Validation, Workflow Action, Notification Type), so requests are first validated and return the proper HTTP error status codes.

Running the Microservice

If you're not deploying to Liferay Cloud, you're free to run the Microservice as you see fit. You can use go run .  in the go folder of the MCE during development.
​​​​​​​I am using Docker, so the Dockerfile runs a Multi-Stage build​​​​​​​, which gets the Docker Image down from 400MB to 15MB. More details on this can be found in this blog post.

Since Multi-Stage builds leave behind the larger images, you should run docker image prune from time to time.

The new container just has to be added to the Docker network the Liferay container is in and you're good to go...

 

Liferay

Deploy and configure the required MCE action/type according to the docs. If everything works and Liferay can connect to your microservice, the posted JSON is logged.

​​​​​​​You will have to take it from there to do something with the received data πŸ˜‰