MicroProfile

Transition has happened from Oracle Java EE to Jakarta EE (Eclipse Foundation). It has evolved Java EE to MicroProfile API (May be a next step of Java EE). Nothing has changed, learning Java EE is enough to know about MicroProfile. MicroProfile is a bunch of libraries for developing enterprise application.

If Java EE knowledge is enough to know about MicroProfile, why should you know about MicroProfile? The reason is you should know about MicroProfile because of microservice architecture things.

“The MicroProfile is a baseline platform definition that optimizes Enterprise Java for a microservices architecture and delivers application portability across multiple MicroProfile runtimes.”

https://microprofile.io/faq/

World is moving towards microservice architecture. Java EE previously did great work on building monolith application. MicroProfile helps enterprise move into developing microservice applications. It provides Java components build upon core Java EE therefore knowledge for Java EE is not lost too. It is needed to stay update to date with MicroProfile version, since component version are rapidly changing. Chance of new component in the MicroProfile are also expect in future.

To simply get started and take advantage of all the libraries, you can add just one dependencies, and it will take care all the component with its stable and compatible versions itself.

Just Import 

<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.0.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>

We will be using just JAX-RS component for simplicity. Create a class which is extend from Application. This Application class is the abstract class which is used to provide configuration and registration to JAX-RS component.

@ApplicationPath("/resources")
@ApplicationScoped
public class EmployeeConfig extends Application {
}

Create another class for handling HTTP Request

@Path("employee")
@Counted
@RequestScoped
public class EmployeeHTTP
{

@Inject
private EmployeeService employeeService;

@GET
public List<Employee> getAllEmployee()
{
return employeeService.getEmployee();
}

@GET
@Path("/{id}")
public Employee getEmployeeById(long id)
{
return employeeService.getEmployeeById(id);
}

@POST
public Employee saveEmployee(@RequestBody Employee employee)
{
return employeeService.saveEmployee(employee);
}
}

Let’s ignore EmployeeService class implementation. Now, to deploy the above application. We can run the Maven install command. This install command generates the war file. Use the war file to deploy on the server like Payara.

java -jar payara-micro target/employee-service.war

By default the war file will be deployed on port 8080. You can obviously add multiple war file in different port. The PacktPub article is more mircoservice style architecture using Payara.

In a nutshell, there is nothing new in MicroProfile. These are all the libraries and concept, you have already learned but in optimized form.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: