Can multi module maven project be considered a Microservice? - java

I have a question to ask. Some time ago I was working on a project as a junior Java developer. It was a Java Enterprise Web App which uses Spring and Hibernate frameworks. I didn't completely understand the architecture of the project and I had only a small contribution to the project. But it was a multi module maven project and each module was built and deployed as a WAR file separately in the Oracle Web logic 12c. They didn't use docker and I don't know how the modules interact with each other (it might be REST or something). My question is: can we consider this type of multi module maven project that each module is deployed separately a microservice architecture?
Also, could you please inform me about a good book to start learning microservice architecture in Java?

Yes. Not using docker (or any other containers) does not necessarily mean that the architecture is not a micro-services based one. It can perfectly be as you are describing: multiple "WARs" (modules) communicating through REST APIs or gRPC or similar.

I agree, this is certainly microservice architecture, as a single overall application is broken out into seperate running instanes. Spring makes it very easy for separate microservices to communicate with each other via REST APIs, Eureka and Feign Clients. Idk about a book on microservices, but a simple project is always a good way to learn. Those might not sound meaningful to you but i recommend finding a simple eureka feign client tutorial online, and doing your own version of it. I did that and was able to deploy the same spring service to both my laptop and a pi, call these microservices repeatedly from another microservice on my laptop (the method i was calling just returned the environment hostname) and see that eureka was passing the call to each one in turn, giving me alertnating results. This demonstrates how easy you can horizontally scale using this architecture (i.e. if i need more power i can just keep deploying new instances of that getHostname microservice and no matter what device they are on eureka can link them up)

It is difficult to say about architecture style with given information.
Docker or without docker is not a constraint for microservice architecture style.
If you want to study microservice in Java than I suggest that you may refer to "Microservice Patterns - Chris Richardson".

Related

How to work on single gateway based microservice in a team?

We are developing microservice based application using Jhipster. For that, there are different components should run at the same time i.e, service registry, UAA server, Gateway, and other different services. To run all these components on my PC it consumes all the resources (16 GB of Ram). However, other developers, they don't have sufficient resources on their PC, which is the reason we are facing the problems continues development in the team.
So we are seeking some options for this problem to get efficiency over our development team.
Currently, if someone wants to add/change features on the application, he needs to work with both microservice and gateway(for the frontend).
So, in this case, what happen? suppose multiple developers are working on gateway and service at the same time in the development environment.
How are they going to debug/test? do they have to deploy gateway individually?
We are planning to deploy microservices on our own VPS server and in near future for the production heroku, kubernetes, jenkins, cloudfoundry can be used.
Correct me if I am wrong and is there any better option for smooth development?
I had read Sam Neuman's Microservice book that the problem of the single gateway based application while development.Now I am very curious about how Jhipster came to resolve this problem.
It seems to me that you are trying to work with your microservices as it was a monolith. One of the most important features in the microservice architecture is the ability to work on each microservice independently, which means that you do not need to run the whole infrastructure to develop a feature. Imagine a developer at Netflix who needs to run several hundreds of microservices on their PC to develop a feature - that would be crazy.
Microservices is all about ownership. Usually, different teams work on different microservices or some set of microservices which makes it really important to build good test design to make sure that whenever all the microservices are up and running as one cohesive system everything works as expected.
All that said, when you are developing your microservice you don't have to rely on other microservices. Instead, you better mock all the interactions with other microservices and write tests to check whether your microservice is doing what it has to do. I would suggest you wiremock as it has out-of-the-box support for Spring Boot. Another reason is that it is also supported by Spring Cloud Contract that enables you to use another powerful technique called Consumer Driven Contracts which makes it possible to make sure that contract between two microservices is not broken at any given time.
These are the integration tests (they run on a microservice level) and they have a very fast feedback because of the mocks, on the other hand, you can't guarantee that your application works fine after running all of them. That's why there should be another category of more coarse grained tests, aka end-to-end tests. These tests should be running against the whole application, meaning that all the infrastructure must be up and running and ready to serve your requests. This kind of tests is usually performed automatically by your CI, so you do not need all the microservices running on your PC. This is where you can check whether you API gateway works fine with other services.
So, ideally, your test design should follow the following test pyramid. The more coarse grained tests you have the less amount of them should be kept within the system. There is no silver bullet if to speak about proportions, rough numbers are:
Unit tests - 65%
Integration tests - 25%
End-to-end tests - 10%
P.S: Sorry for not answering your question directly, I had to use the analogy with tests to make it more clear. All I wanted to say is that in general, you don't need to take care of the whole system while developing. You need to take care of your particular microservice and mock out all the interactions with other services.
Developing using a shared gateway makes little sense as it means that you cannot use webpack dev server to hot reload your UI changes. Gateways and microservices can run without the registry just use local application properties and define static zuul routes. If your microservices are well defined, most developers will only need to run a small subset of them to develop new features or fix bugs.
The UAA server can be shared but alternatively you can create a security configuration simulating authentication that you would activate through a specific profile. This way when a developer works on one single web service, she can test it with a simple REST client like curl or swagger without having to worry about tokens.
Another possibility if you want to share the registry is to assign a spring profile per developer but it might be overkill compared to above approach.

Microservice architecture, what is a service in this case

I'm reading some documentation about the micro-services architecture (through this link for example) and I was wondering what is exactly a service in this case.
In IT, everything could be called a service:
- a SPRING REST application launched through the java command like:
java -jar build/libs/gs-rest-service-0.1.0.jar
It could also be a classes corresponding to the business layer in a DDD
It could be simply something related to the domain studied, like providing something to somebody
and many others... (android background running services etc...)
But in microservices, what does it mean? And what kind of technologies / tools are used to create a "service running by himself" in the Java EE stack for example? It's only related to webservices?
Exactly, that's the beauty of microservices model! You can start thinking about microservices when you design your maven multi-module project, for example. Low coupling, clear separation of concerns, may be even asynchronous communication. When you feel more confident you extract them in into apps and run in a one host, next step - run in different hosts. It's up to you to decide how exactly they should be deployed, it's related to goals you want to achieve (fault-tolerance vs low latency, etc.) and DevOps resources you have (because more separation you have more maintenance you need).
Regarding Java EE stack - nothing specific, just usual jar or war file running using java -jar or application servers like Tomcat.
Another direction is to use tools like Docker + CoreOs / kubernetes / ..., Mesos + Marathon, etc., but they are suitable for any languages / frameworks in microservices.
Edit:
Microservices can use a combination of synchronous (REST, SOAP) and asynchronous protocols (messaging queues like ActiveMQ, RabbitMQ, etc). It's up to you to decide how to combine them. My example: labs.bench.co/2014/12/10/microservices-at-bench-intro
Previous answers are great.
Microservices architecture is just a functional decomposition design.
I suggest you to read this blog post : Microservice Design Patterns
From a technical point of view, there is a a lot of tools like Docker (to run each microservice as a linux container) and Kubernetes to orchestrate them as a service (here is a Kubernetes sample).
My own definition:
A microservice is a stand-alone, decoupled component that handles a single business concern, and is consumable from other services.
Others might agree or disagree, and there is a lot of interesting discussion on this topic that make it a great study point for software engineers.
From a technical standpoint:
You can create microservices in almost any technology: Java EE, Java + Spring, Python, Rails, Grails, Node.js and so forth. From what I have seen, it seems most commonly applied in the domain of web apps and back-end service-oriented ecosystems. In the article you reference, the NetFlix model is a very interesting thing to study, because you can see all the elements of a microservice architecture in depth: service discovery, circuit-breaking, monitoring, dynamic configuration, and so on.
Some things you might want to check out, if you are Java-oriented:
Spring Cloud allows you to use some of these same NetFlix components with a minimum of hand-coding: http://cloud.spring.io/spring-cloud-netflix/
An actual operational example on github (not mine, but I have used it in my own learning on the topic): https://github.com/ewolff/microservice
From a conceptual point of view, your question hints at a notorious microservice design dilemma. There is not necessarily a "correct" level of granularity for a microservice. The idea is to choose a level of granularity that has meaning within your business domain. If you implement microservices at a very low level of granularity, (e.g. the CRUD level), then you will almost certainly end up with very chatty services and you will probably have to build more meaningful composite services over top. If you choose too high a level of granularity, you could end up with a more monolithic application which may require refactoring into microservice-sized pieces later.
I would start with Your last question - It's only related to webservices?
That's debatable. I would say, NO. It's related to webservice (but not only to it.)
Martin fowler describes microservices as a small subset of SOA, after all microservices are services, and SOA is a very generic and broad term.
Below are some of the important aspects of Microservices:
Each service (or a set of few) should have it's own data store.
Services are organized around the business needs or functionality.
Each service is independent so they can be implemented in any language. Leads to polyglot programming culture in team.
Service can take request from client or from other services as well.
They are usually event driven and asynchronous so scaling becomes easier.
Services are dumb as they only do one thing (but they should be self sufficient to monitor themselves)
They can be helpful in continuous deployment or delivery as implement to deploy cycle is really small.
They are very small so there is not much of network overhead in deploying them. So they can be deployed across a cluster of nodes in few minutes.
Also, I want to stress that, above are NOT only true about microservices. Companies like google, netflix, and Amazon have been doing similar thing even before the term was coined.
Service to microservice is Java is to JavaScript. Don't think about it that way. Instead microservice can be thought of as the following:
A small problem domain.
Built and deployed by itself.
Runs in its own process.
Integrates via well-known interfaces.
Owns its own data storage.
A Microservice is basically a self contained process that provides a unique and single business capability. We don't create web Microservice, business logic Microservice, or datebase Microservice.
Why Microservice?
Microservice make our system loosely coupled, i.e. if we need to update, repair, or replace a Microservice, we don't need to rebuild our entire application, just swap out the part that needs it.
To built each Microservice can use different languages and tools. Microservices communicate with well defined interface
The communication should be stateless for scalability(copies of Microservice) and reliability(one copy fail other copy can serve), the most common methods for communication between Microservices are HTTP and messaging.
Each Microservice should have it's own datastore.
Small team capable to work on design, web development, coding, database admin and operations.
source
Microservices is a software architectural style that require functional decomposition of an application.
Usually, it involves a monolithic application is broken down into multiple smaller services, each deployed in its own archive, and then composed as a single application using standard lightweight communication, such as REST over HTTP or some async communication (of course, at some point micro services are written from scratch).
The term “micro” in microservices is no indication of the line of code in the service, it only indicates the scope is limited to a single functionality.
Each service is fully autonomous and full-stack. Thus changing a service implementation has no impact to other services as they communicate using well-defined interfaces. There are several advantages of such an application, but its not a free lunch and requires a significant effort in NoOps.
It's important to focus on that that each service must have the properties of:
Single purpose — each service should focus on one single purpose and do it well.
Loose coupling — services know little about each other. A change to one service should not require changing the others. Communication between services should happen only through public service interfaces.
High cohesion — each service encapsulates all related behaviors and data together. If we need to build a new feature, all the changes should be localized to just one single service.

How to split my project into modules to be used in multiple platforms?

I have a college project that manages bookmarks, a CRUD with folder structure. The project uses swing and hibernate all in the client. Now I want to make both a web and an android application version, but I don't know how to split the modules. For example, I thought about creating a web application with websockets and hibernate, and connect the swing, web and android in the websocket server.
Is that a good choice? If not, what better options are there?
Please note that the project has to be synchronized between the platforms and
I wonder about the technologies that can be used also, and not just the pattern.
I can use Spring too if necessary.
just an opinion, the project module structure should look like this:
android client (androidUI)
web client (webUI)
service part
db
integration tests

What is an ideal way to organize a Spring 3 web application and its components?

I'm developing an application which has two main 'parts' to it...
The public facing website
The RESTful API for the mobile application.
I'm developing the application with Spring 3 using Spring Tool Suite as my IDE. At first I thought that the API would be part of the same project as the public website. But then I tried to mix basic auth in with my form based auth for the public website things started to get a little confusing with Spring Security.
So I thought it might be best to develop the API as a separate project and share my domain objects, services and DAOs between the API and website projects. My question(s) now are:
Is this a dumb idea?
Should create a 'core' project with the shared domain objects, services, etc?
Should I use Maven and add the 'core' project as a dependency for the API and website projects?
Is there a better way to do all this?
It very much depends on what your needs are. I am currently working on a fairly large GWT application (using SpringSource Toolsuite and Maven).
We make extensive use of Maven modules and profiles. It can get a bit messy at times but it does enforce separation, which I think is generally a good thing.
I would say, if your front end and back end code are going to be completely separate, it might not be a bad idea to create them as separate modules. You can then set up your Spring Security as you wish for each project etc.
So, to summarise, I would say modular is a good way to go, but do investigate Maven modules as this may help you with dependencies.
I have the same specs as you
The public facing website
The RESTful API for the mobile application.
I have to separate web projects one for my RESTFULL services based on JSON and a database dependency. For my frontend project I don't have a dependency to the database but only to my restfull services.
With this strategy it is possible to use the same codebase for webprojects and mobile applications.

Is it possible to reference a Java app from a Grails app?

We have a Java/Spring/Hibernate codebase which is the core to our pretty large platform. We also have quite a few separate Java webapps (Struts or Spring MVC) running alongside which reference the core system, pulling in the applicationContext and services from it.
We have a requirement to build another webapp that also references the same core system, so I was hoping to do this with Grails. From what I've found it appears you can easily jar up legacy Java code, place it in your Grails project lib directory and reference it that way.
http://www.itexto.net/devkico/?p=333
Unfortunately this will not work for me as I need to reference the running core system and its services from my Grails app, as you would reference a Java app from another Java app. Is there any way to do this or is it just not possible with Grails?
Any information would really help...
Thanks,
Justin.
I would look into building a Service Layer on top of your Spring services/beans. This is a pattern documented in Martin Fowler's Patterns of Enterprise Application Architecture book. Essentially you want a thin layer that wraps your Spring services (your business logic) that can be called by a web service or a remote call of some sort from your web-apps. This will allow you to host your applications in different processes but still be able to communicate between them without trying to hack everything into the same web container and figure out how to reference the same running processes.
See documentation on Grails+Spring integration. When you have gotten Spring working inside Grails, next steps should already be standard Spring.
As you have not detailed, how your existing Struts and Spring MVC applications "pull in applicationContext and services" I cannot comment on the details. However, it should be similar to the way your existing applications do it.
EDIT: check also answers to this question on how to organize your Spring beans.

Categories

Resources