Event Sourcing-enode (ii)

Source: Internet
Author: User

Continue to the next article

Http://www.cnblogs.com/dopeter/p/4899721.html

Distributed Systems

The previous article talked about why we use distributed systems, because Enode itself is a distributed framework. Look at a lot of ddd, CQRS framework, the general situation is a context of a system, multi-system instances can be distributed deployment, but need to mix with the distributed infrastructure. Enode has provided a more complete distributed DDD solution.

1. Distributed Communications infrastructure

RPC, Mom, and rest are generally used, but recently rest has been weakened especially in the interior of a large system, or in a scenario with high performance requirements, the author himself implemented and open source MOM component Equeue as an infrastructure collocation enode, there are kfaka design concepts, But join in their own ideas, can go to the author's blog to learn about.

Http://www.cnblogs.com/netfocus/category/496012.html

2. Distributed granularity

This is Enode biggest bright spot, from the current industry development direction, is also enode can be put into production environment test run one of the reasons. Enode is a distributed design using command, Event, Application Message, exception as the base granularity. At present, most of the other CQRS frameworks are still system instance-level distributed, if you want to achieve this granularity of distributed, need to do their own design, in the long run, if really into the production environment, the framework after the upgrade of the incompatibility caused by the problem is very possible, Of course Enode can be a popular framework for our current OLTP system, but we have to be careful later to be kidnapped by authors.

relational database

In fact, the author has been using the relational database in the framework, because of the front granularity, plus the writing barrier feature of ES itself, the consistency of similar relational database is realized, and only the persistence of relational database and the checking mechanism are used. Of course, the author still uses the transaction in the implementation, as well as the relational database when the distributed lock to use, somewhat similar to zookeeper, these are based on the granularity of the reduction, so the performance is greatly improved. But these are the default implementations of the authors, and we can implement the other ourselves.

In fact, should start from the sample, but if interested friends can directly download the author's source code, the author's sample written very well, so the direct opening of the section.

Full view

This is the code for Enode.

We can think of it as a 2-tier developer Application layer (dedicated to business developers) and infrastructure (architecture developers only).

Commanding,domain,eventing,snapshoting belong to the application layer. is a special term for ES.

Infrastructure and configurations are infrastructure layers.

Commanding

We can think of this as the commanding assembly diagram, as the name implies.

ICommand, a command.

Inherited the imessage, which is the previously mentioned distributed message.

The other interfaces are as the name implies.

Icommandhandler Command processor

Icommandhandlerprovider Isolation Command Processor assembly

Icommandhandlerproxy Command Processor Agent

Async is a representation of asynchronous

Not a brief introduction. The focus is on the default components that the author implements.

Interface-oriented is the abstract height and angle of the author, and the class that really represents the idea of its landing is the default implementation.

Content a bit more, and will be very jumping, this is not enough to talk about, we still slowly. Mainly typing is a bit tired, the hand can't keep up with the brain. First look at the Defaultprocessingcommandhandler class that the author implements,

This is the core of the class that can also be thought of as the core processing command logic.

It implements the Iprocessingmessagehandler interface, which has only one method

void Handleasync (X processingmessage);

So we look at the author's realization.

The screen is too small, cut 2 pictures, the first one nothing special, the second, here used 2 different handler, one is synchronous, one is asynchronous. There are some differences in their logic.

Of course, the command handling method is definitely executed. What is the difference?

In the Handlecommand method, after execution, there are some logic to determine whether the command is merely a modification of a single aggregate root, which embodies the individual aggregation root isolation in the author's design thinking, that is, the granularity of the transaction isolation granularity in the relational database mentioned in the previous article to the aggregation root. After verification, the event is submitted directly, ready to persist the event, follow-up, event follow-up.

In the ProcessCommand method, Commandstore is used, there are 2 implementations in the Commandstore of the author's default implementation, and InMemory and sqlserver,inmemory are stored in the dictionary. SQL Server is the command ID as the primary key, where the logic is to first go to the Commandstore to retrieve the command with the same ID, if so, it has been proved to be executed. If not, the command is saved to Commandstore after the Command,command execution succeeds, the event is committed after the save succeeds, and the event is ready to persist. Here is actually the power of the elimination command, the first optimistic locking organ appeared.

Why does the first method publish an event directly without using an optimistic lock?

The aggregation root corresponding to the command in the Handlecommand method is not actually updated, but the dirty aggregation root data is pre-submitted to EventHandler, and there will be an optimistic locking authority again at EventHandler.

Why the ProcessCommand method to use optimistic lock, in fact, I do not have a complete answer, guess the following points

1. See if, else if, for a command, there can be multiple handler, whether in the system instance inside or other parallel system instances, or other context of the system instance, there may be synchronous and asynchronous processing of handler.

2. The ProcessCommand method is the corresponding asynchronous CommandHandler, which, since it is asynchronous, is used by the author. NET task, although a command is a single-threaded run, but if in asynchronous, for example, we and other system communication also use asynchronous, then this thread will return, execute the next command, if the next command is the same, this is not theoretically possible.

3. The repeated sending of messages in MOM, which is likely to occur.

Event Sourcing-enode (ii)

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.