A simple framework for communication Services (study together) Java version

Source: Internet
Author: User
Tags zookeeper

Recently studied the Java language, according to the general use situation, wrote a connection Communication service framework;

Frame structure c-manager-s;

To extract all the communication content into three methods interface: Getdata,setdata, with return of get;

All data is processed as byte[]; multiple processing modes for clients and server side and manager and server

Management information:

1. Do not need the center manager; When the server starts, it broadcasts its own bound address to the client, receives the data, broadcasts a request when the client uses it, and obtains the service information to all the server;

2. Management Center: The client requests the service information from the manager, the server registers the address to the manager, and optionally forwards the data that the client passes to the service, or it can forward the address to the client, which needs to be determined by the client.

Service side:

1. The server must be named; the entire structure is subject to the service name, and all requests are subject to the name;

2. When the server has the same name, according to the service configuration, the service is divided into primary slave mode and load Balancing mode, if it is master-slave mode, the manager or client only calls the main service, when it is judged that the primary service is dead, it is enabled from the service, and multiple from the service according to the resulting sequence. In fact, refer to the zookeeper in the election algorithm); If the load Balancing mode (not set the service is the master-slave mode is load-balanced), load balancing using hash consistent algorithm, extraction service use;

Client:

The client is encapsulated directly as a proxy interface, and internally converted, only needs to invoke the interface method, pass in the service name, return a proxy interface, and then transfer the data

Information caching:

The use of multiple local databases (relational, non-relational, in-memory database, are localized);

Transport Layer:

The transport layer now only provides the most basic tcp,udp; I pull the communication layer, extract the interface, through a communication manager to create the interface object (reflection), only need to pass in a name ("TCP", "UDP") to establish communication, easy to modify, can be very flexible to modify the mode of communication, You can also replace familiar third-party communications; You can develop your own communications layer, just to implement the interface, give the communication a name to

Made a simple manager interface

There is a serialization component in the framework: Magpack; the other is localizing the database

Now the network framework components are relatively complex, such as: zookeeper; in fact, many of us are small and medium-sized enterprises or smaller data use, there is no need to be so complex and large, not necessarily good maintenance, I just want to make an easy-to-use, general, very small, fast things, simplified communication processing, highly abstract;

In addition, all network components are selected to handle fast, simple, especially free open source; When designing, consider these components easy to replace, try not to go to complex reference, as far as possible abstract interface;

In addition, a more loaded interface is prepared:

The Java interface is not currently suitable for complex development, but is ready for simple display

The code has been submitted to GitHub;

Framework functions will be gradually updated, may be perfect later will be large, based on the design goals, in use will be as modular as possible, can be separated (such as only the use of encapsulated database connection pool, database operations, communication layer, proxy conversion these), or through the configuration, reflection, interface separation code;

Now the main Java language implementation, in fact, all languages are the same;

The last point: Many people are afraid of the central node when deploying, because it hangs up and it's all over. The server here can have a variety of modes, as for the manager, it is more similar to DNS resolution address, DNS is hung, everyone is not playing, but can discuss there is no other way, I consider the use of multiple, internal replacement (similar to the zookeeper election of a central management services, and then switch), Have the understanding of communication or address resolution of a lot of suggestions;

The next step is to refine the techniques that may be added to the UDP burrow;

A simple framework for communication Services (study together) Java version

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.