How to improve communication between microservices [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
In our company we use spring boot, microservices, spring cloud and so on... We are happy with this infrastructure, but I still have some concerns:
we use rest as comunication protocoll and even if a I find it great, I still think that we could find something better. With rest:
you need to use a client and a server (restcontroller)
you need to know the server URI, the http method (POST, GET, PUT,...)
you need know where params go (body, querystring)
....
Don't you think It would be much easier if we had something like RMI? I know it's a quite old technology(and it's not language independent), but it made life easier (you just need an interface and its implementation).
Searching around, I found some interesting projects like feign clients or spring cloud stream, but none of them seem to be the silver bullet.
What do you think about this topic? Is that a problem that you feel? If so, how do you approach it?
Thanks in advance.

In my company, we use JMS to add a "intern" communication stack to our microservice stack. It is reliable, simple to use, efficient and very performant.
We use Apache ActiveMQ as implementation, but RabbitMQ is also widely used.

Microservices are not meant to be tightly coupled , RMI requires your code on both end , which was fun when you didnt control the other side eg clients who do not want to upgrade and it was a B!#*! to get through firewalls.
Soap solved most of those things you mention unfortunately Java never had a good Soap stack. That said Rest has other advantages especially when accessing the service from a web page and javascript.

You can use Spring Cloud Netflix and Eureka as Service Discovery and Client-Side Load Balancing with Ribbon.
With the help of those you can communicate between microservice by 'service names' instead of service locations.
Check out this demo. It should be VERY USEFULL for undestanding microservices communications.
Here we have 2 simple microservices and Discovery Service for communications between them.

Related

Spring boot API - How to scale an App as users grow [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am making an API with Spring boot which will maybe have requests peaks.
So let's get into the worst scenario. Imagine that suddenly I have 2 million API requests.
What can I do to be able to handle this?
I read something about queues and workers but I don't know if that's the best way.
Is there some way to do it with something with AWS?
This is always a tricky question to answer. Firstly does your app really need to scale to 2 million API requests at peak? I ask because it is easy to over-engineer a solution 'to deal with future scale' which ends up a bit buggy and not even dealing with current scale very well as a result.
But assuming you really will have massive request peaks, the current microservice approach (or buzzword?) is quite a popular way of dealing with these periods of high demand. Basically you split your application up into smaller, self contained services ('microservices') which can be more-easily scaled as required.
Individual microservices can then be scaled up and down to match the load, using something like Kubernetes or Amazon ECS.
In terms of where Spring ties into this, Spring has a handy set of technologies called Spring Cloud - you'll notice Spring Cloud AWS there, too (although Spring Cloud in general can also work fine on bare metal servers, Docker, Kubernetes etc etc). A year ago I put together a simple Spring cloud/microservices demo on Github which shows how different Spring-powered microservices can fit together, which you may find useful.
The other nice thing with microservices is that you can swap out the language that a particular service is written in fairly easily, especially if the microservices 'speak' to each-other in a general format (such as JSON via REST requests). So if you had 10 different microservices, all powered by Spring Boot, but you find that a couple of them are better written in another language, you can just rewrite them: as long as they send and receive data in the same way, then the other parts of your system don't need to care.
Okay, that's a lot of buzzwords and new concepts. Feel free to ask questions if I can clarify anything, but microservices + kubernetes/AWS is a popular solution.
Other approaches which will probably work equally well, however, are:
Serverless - this is where you use a bunch of cloud-provider's tools and solutions to power your webapp, including things like lambdas, instead of hosting your application on a traditional server/VM. This medium tutorial gives a simple introduction to serverless.
Monoliths - this is a traditional web application which is a single, large, sprawling codebase, but this doesn't mean you can only have one instance of it running (i.e. you can still scale it). This very site is a successfully scalable monolith.
Your question is very broad, as there are lots of different solutions:
1) Use a load balancer and have multiple instances of your application
2) Use a containerization tool like docker and kubernetes to increase the amount of instances depending on current load. You can essentially scale on demand
3) We don't know what your app actually does: is it read heavy, is it write heavy? Will users be downloading content? The answers to this question can change whether or not a specific solution is feasible
4) You can maybe use a messenger queue like RabbitMQ to assist with distributing load across different services. You can have multiple services reading from this queue and performing actions at the same time...but again, this depends on what your app will actually be doing.
Check out AWS EC2 and Elastic Beanstalk. You can also get a simple load balancer up and running with nginx. Good luck

Design strategy for Java web services [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When one wants to set up an API for a webservice with Java EE, what is the best procedure to design and realize such an API?
Having never used persistence before, I always drew out my UML datamodel and structured a database with a SQL client tool then build my application on top of it.
I get the idea that most Java EE applications are built starting from entity classes and services. Or from XSD and WSDL files. Is this true? Is there a difference between how one best creates SOAP and REST apis?
Where is the structure decided and what comes first? How are persistence systems best designed? And on what basis? What tools are helpfull? Any extra information and especially reference is desirable here! I just want to get more feeling with the bigger picture.
It's still a good idea to figure out the correct data model first. The other thing you need to figure out before starting to code is the interface architecture: what calls you are going to support, what arguments the calls will have, and what data will be returned. Once you understand those two things, the actual Java coding can go much more smoothly.
If you are just asking for how to get started with developing a java rest api, I would first look at some of the specifications.
If your question is just about technology to learn, Heres the general stack I use:
RESTful services are provided through the JAX-RS API through the reference implementation Jersey
Object to relational data mapping provided through the Java Persistence API via Apache OpenJPA (almost a reference implementation, little less cruft than hibernate)
Object serialization/deserialization provided through the JAXB API via the Jackson Object Serialization API
Configuration and dependency management provided through JSR-299 via Google Guice
If your question is about API design...
Make sure you write down your api. Make sure the urls make sense, and that you follow best practices when making a url. Your interface between the outside world and your software is that URL. The json you expect and the JSON you return is the most important thing to get right. Even if your software sucks, so long as your api is well thought out and the contract is sound, it will be okay.
Make sure you really understand what you want to input and output before you put it to code.

Cloud Services - EC2 vs. GAE vs. Lunacloud vs. Jelastic vs. [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am planning to program a software (in java), which will be (hopefully) used very much. In the beginning I may run it on my own server, but if it becomes popular my server will most likly crash.
So my plan is to program it for a cloud service like Amazon EC2, Google App Engine, Lunacloud or others.
The application will not have a gui for now. It will concentrate on SOAP or JMS (or something like that) and should store a lot of data in a relational database (PostgreSQL would be nice).
Since I am new to the cloud services, I tried a little bit with GAE. The main use is easy, but as soon as I use JPA and ManyToMany-Relations GAE is shit. Also making a SOAP or JMS Server in GAE is not simple.
Since I lost my weekend with trying GAE, I thought it would be a good idea to ask the community.
Which cloud service will fit best for my requirements? What are the benefits and differences between these services? What else can you recommend?
This is question is too wide open to provide a good answer, but here is some tips that should help.
There is a difference between platform as a service (GAE, Jelastic, Heroku) and Infrastructure as a Service (EC2).
In the platform as a service category, you have more of an automated infrastructure, and often very little visibility of the underlying components. This can make things easier from a developer perspective, but it has its downsides. You are often locked into how a provider works and it may be difficult to switch. You may also have limitations as to what you can do with your application.
In the Infrastructure as a Service category, you get access to virtual machines that you can configure and automate yourself. You have more flexibility on this type of platform, but you are generally expected to handle more of the work yourself. EC2 does have its own version of platform as a service with elastic beanstalk.
i would recoomend also heroku because it does not have a traffic limit and you can run a basic instance for free. if you dont need nosql dbs and extra software it will be very cheap and the unlimited traffic is good for your webservices. Gae has is own filestructure so i can understand your problems with your db structure very good. heroku and ec2 does not restrict your plans but ec2 is generally expensive if you dont plan to scale up and down often. heroku gets also very expensive when you want to add extra software and scale up. i dont know if youre able to scale up as good as with ec2 if you want to use jelastic.
another but complex approach would be renting some normal root servers with unlimited traffic where one instance act as load balancer but you would have to do the configuration by yourseld

HTTP socket programming java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
what would be the good starting point to learn TCP Socket programming using java.
I have reasonably good experience in java software programming but new to netwrk/socket programming.
I am working on to develop a proxy cache server. But not able to read post requests/302/405 requests.
I referred to this below code.
http://blog.edendekker.me/a-java-proxy-server-with-caching-and-validation/
But unable to modify the code to read urls like www.gmail.com that return 302 Moved Permanently Error OR 405 Method Not valid Error. And also not able to read POST requests.
What would be the starting point where I can read about handling errors and handling POST requests.
Any reference links, example codes would be helpful.
My prev question in similar topic:
Handle a POST request and write response to client socket
Thanks
It looks like your problems are more related to HTTP than to TCP as such. Do you want to implement a proxy server in order to learn the HTTP protocol? If not, there are several good proxies freely available, often including source code. If you just want to learn TCP socket programming, try something simpler such as e.g. POP3. Also, if you want to do TCP in Java, be aware that there are 2 major ways to implement them:
One thread per connection
One thread per application, shared between connections (Java NIO and NIO2)
Assuming you really want to tackle the HTTP proxy. HTTP is not trivial if you want to implement all of the functionality that e.g. browsers use, like caching, authentication, etc. plus the additional complexities that incurs when implementing a proxy.
If you really want to bite the bullet, here's a more lightweight version of the HTTP protocol, for all the details, refer to RFC 2616 . But be aware that RFC 2616, the HTTP 1.1 specification, refers to other RFCs that you might have to consult as well for specific areas such as authentication.
Update:
One other thing that might be easier in some cases is using an HTTP proxy to sniff the communication between say a browser and an off-the-shelf proxy to quickly see what others are doing.

how to provide API for our system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have not had much experience with Webservices or API's.
We have a website built on Oracle->Sun App Server->Java->Struts2 framework. We have a requirement to provide an API for our system. This API will be used by other systems outside of our system. API is just for a simple SP that we have on our database. The other system does not want to connect to our DB to gain access to the SP but instead and an API as a 'webservice'
Can the community please shed some light on how to go about this? Will the API be put on our webserver? is that how the other system will connect to it? And how to go about creating a public API?
Some things you'll need to think about are:
SOAP vs REST (Why would one use REST instead of SOAP based services?)
How will you handle authentication?
Does it need to scale?
You might want to take a look at https://jersey.dev.java.net/.
It would also be helpful to look at how another company does it, check http://www.flickr.com/services/api/ for some ideas.
If you are using the Sun App Server, it should be fairly trivial to make an EJB exposed as a web service with the #WebService tag, and then have that EJB call the Stored Proceedure and return the data. The app server gives you tools to publish a WSDL which is what they will use to know how to call you API.
That being said, what sounds easy at 50,000 feet is a real pain to deal with all the details. First, what about security? Second, are WebServices really required, or is there a better communication mechanism that is more obvious, such as (at a minimum) REST, if not some simple servlet communication. And the hardest part: In exactly what format will you return this result set?
Anyway, you could be dealing with a bit of a political football here ("what, you don't know how to do web services, everyone knows that, etc.") so it can be a bit hard to probe the requirements. The good news is that publishing a web service is pretty trivial in the latest Java EE (much easier than consuming one). The bad news is that the details will be a killer. I have seen experienced web service developers spend hours on namespace issues, for example.
Soap or Rest or .. is one side of the medal and depends on what the clients want.
The other (more) important thing is the api design itself. Shall it be stateless or stateful. Are clients co-located in the same VM (Appserver) or remote in the same LAN or even in a Wan.
As soon as the communication goes over the wire, it gets slow due to serialization. So you want API methods to obtain bigger (but not too big) chunks of data at a time.
Or in other words, your question can not really be answered without knowing a lot more about what you want and need to do.

Categories