Loosely coupled services are the main attraction these days. Can change technology anytime and requirements might change if your service is loosely coupled then its very easy to make changes. And risks are very less.
Exposing everything as a service, all big saas based companies are moving towards this trend. Modularization is very important in the development stage. If we fail to modularize at the beginning stage itself, you will face nightmares while maintaining the code. Too many modularizations might bring heavy burden on the performance.
One of the best way to decouple the services and bringing the communication b/w them is to expose as REST services and consume them. Typical example for the same will be. For any authentication required sites storing the identities/authenticating will be one module, and other operations like posting and commenting or any other business related operations to the other module. Integrated them to the service through the clients. It will be very easy if some other offerings want to consume the services.
What is REST? How to write a REST service? There will be lot questions around. Its better to do the ground work before actually start writing the service. There are loads of the tutorials available outside the world.
First decide what are your resources and define your data model.
Defining data model:
Data model is your data objects, through which you communicate and represents your java object in the string/readable format.
Converting java object to the XML or JSON is important, basically called as serialization/marshalling. Typically we use JaxB marshallers/Unmarshallers. And it is very important to understand the jaxB annotations. For simpler and straight forward tutorial refer this link.
Contract b/w client and server:
How do one communicate to the client what will be the data representation. So it a common practice sharing the data model b/w the client/server as their contract and one shouldn't break the agreed contract. Usually data model will be shared b/w the client and server through XSD for the data model.
Data model can be generate through two methods.
1. Define data object along with JAXB annotations and generate XSD
2. Define XSD and generate java objects
Its easy to generate XSD rather generating the objects from XSD.
Here is the maven plugin to generate the XSD from the objects.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includes>
<include>path/to/your/package/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/schemas/schema</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
And for the sample project refer here:
https://github.com/shiva404/perflogging-SpringProvided
Exposing everything as a service, all big saas based companies are moving towards this trend. Modularization is very important in the development stage. If we fail to modularize at the beginning stage itself, you will face nightmares while maintaining the code. Too many modularizations might bring heavy burden on the performance.
One of the best way to decouple the services and bringing the communication b/w them is to expose as REST services and consume them. Typical example for the same will be. For any authentication required sites storing the identities/authenticating will be one module, and other operations like posting and commenting or any other business related operations to the other module. Integrated them to the service through the clients. It will be very easy if some other offerings want to consume the services.
What is REST? How to write a REST service? There will be lot questions around. Its better to do the ground work before actually start writing the service. There are loads of the tutorials available outside the world.
First decide what are your resources and define your data model.
Defining data model:
Data model is your data objects, through which you communicate and represents your java object in the string/readable format.
Converting java object to the XML or JSON is important, basically called as serialization/marshalling. Typically we use JaxB marshallers/Unmarshallers. And it is very important to understand the jaxB annotations. For simpler and straight forward tutorial refer this link.
Contract b/w client and server:
How do one communicate to the client what will be the data representation. So it a common practice sharing the data model b/w the client/server as their contract and one shouldn't break the agreed contract. Usually data model will be shared b/w the client and server through XSD for the data model.
Data model can be generate through two methods.
1. Define data object along with JAXB annotations and generate XSD
2. Define XSD and generate java objects
Its easy to generate XSD rather generating the objects from XSD.
Here is the maven plugin to generate the XSD from the objects.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includes>
<include>path/to/your/package/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/schemas/schema</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
https://github.com/shiva404/perflogging-SpringProvided
No comments:
Post a Comment