Introduction and design ideas of my open source project

Source: Internet
Author: User

First place GitHub address:

Open Source project name: Chipsgateway (because I love to eat French fries)

Project Type: Gateway

The following from my fine points, ask yourself to give you a general introduction about this project

Q: What does this project do?

A: A service gateway, which belongs to half-frame half-service, can be imagined as Netflix Zuul.

Q: What is the difference between this gateway and other gateways?

A: The role of the gateway is much the same, but I will try to add as many default components as possible, and achieve maximum configuration, and I will try to make the service more friendly to developers and more focused on the framework than Zuul.

OK, above is a general introduction, and now I come to you in detail to say that I develop the idea of this service, as well as the process, I will try to give you clear, why I do so, very much look forward to you can give suggestions.

First of all, the motive for the development of this gateway, I would like to write relatively close to the bottom of the open source project in the form of all the knowledge I learned to do a good integration, plainly is practiced hand, because I learned from the programming of the first line of HelloWorld began to now almost a year or more time it, While this period of learning a very large amount of knowledge, but the work of the project can only apply a small part of the knowledge, and most of the knowledge is lack of a real environment, so I would like to write an open source project to learn from this, and why I use the gateway as my second open source project? (The first is a class loader, actually wrote the ORM framework before, but because the single-machine environment is really boring, so write half of it is not written down), and because the gateway is a set of high concurrency, high performance, High expansion of the three-high as one of the services, can be said to involve high concurrency, network programming, load balancing algorithm and other subdivision of the knowledge chain, so I choose to write a gateway out.

Gateway process and architecture design ideas:

Remember Einstein once said (well, it seems to be him), when you want to solve a problem, the first thing is to understand what the problem is. So we have to understand what the gateway is, what it can do?

So, I searched n more data, finally summed up a conclusion, so-called Gateway, is the aggregation of requests, distribution requests, aggregation response, distribution of the response of a middleware, then it can solve what problem? If you search the Internet, you can find a lot, like what load balancer, dynamic routing convenient configuration, Uniform authentication of permissions, etc. balabala.

But these are just phenomena, only the application, not the essence, what is the essence? The essence is that the gateway can intercept requests sent by multiple clients to multiple services, and multiple service-side responses are sent to multiple clients, and a process is made for those requests and responses. As shown in the following figure

When I formed such a picture in my mind, I was the first to think of Logstash, yes, that is the elk in the L, the difference is that the Logstash is point-to-point of the two data source to do the processing, and the gateway is many to many requests to respond to the processing (of course, From a request to a response, it is also a point-to-point),

Think again, like Logstash. What do we do if I want to deal with the data? A: Add a filter as a link in the filter chain.

Is it possible for us to design a gateway using the idea of a filter chain?

After thinking about it, this is completely doable, because I can fully verify the permissions, dynamic routing, and even current limit as a link in the filter chain for processing, but what is the benefit of doing so?

The advantage is that the processing logic is fully atomized and modular, so that all of my logic is pluggable and implements the class modularity advocated in the design pattern.

After thinking about these, I started to work on the process structure diagram, here is my first sketch, of course, this sketch is problematic, I do not say where the problem, we think about it

What's the problem with this sketch? That is, since I have defined the Filterchain class, then my filter chain should not directly contact with the data, so I modified the

Of course, if you look at my project source code, I will find that my current project structure is not as I draw the figure so, specifically, I am ready to wait for the first release after the release of the painting, because in the process of development, I found that things are not so simple, in fact, because to consider the extensibility problem, So my project structure is much more complicated than the one I drew. Here is a scheming, but also please pay attention to my blog, and so I released the first can be formally run the version will be drawn and detailed explanation of each design point

Time back when I finished drawing the second sketch, then I did not immediately get started after the painting, but first saw and I this project type of the same Zuul gateway source code, and analyzed the advantages and disadvantages of its architecture design. Here are some points I summarize:

Pros: Using the Prefilter,routerfilter,postfilter three logical categories to classify filters, this idea coincides with mine.

Cons: Too unfriendly for developers, developers can only get native requestbody,responsebody by RequestContext when adding filters, and prefilter can not be forced to interrupt, even if the interrupt is marked, Also must be prefilter all over, waste resources, not necessary, there is the filter components provided by itself is not too much

So we take its essence to its dross, that is, the same use of the above three logical classification, and Requestbody and responsebody to carry out a packaging and injection, filter chain at any time can be forced to interrupt, and let development can get interrupt information ( For example, in which filter is interrupted, why is interrupted) etc...

Well, these are my general ideas, for the specific design of source code These people can first pull down my code to see, and so I officially released the first version, will be detailed to share with you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: