Event Sourcing-enode (iii)

Source: Internet
Author: User

Pick up an article

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

The boss yesterday in the second introduction of the reply code and text can not correspond. In order to better let the boss for everyone's doubts, the second final guessing question to clear up, then fill in the other text description of the code map.

In the above article general introduction of commanding, compare jump, at present is to think of where to write, follow-up sorting.

In the follow-up will complement the whole Enode Framework assembly relationship, in fact, the author's interface naming is very clear.

Regardless of the design pattern of the assembly used by the author, the purpose is to better extend and maintain. Generally direct combination of direct combination, can be isolated on the direct isolation, if you encounter the situation can not be dealt with a classic sentence, when we encounter the problem can not be solved, add an intermediate layer to specifically solve the problem. In fact, and the reality is very matching, or borrowed from the reality of wisdom AH. Colleague A, colleague B, I, when A and b in a dispute, then I act as broker's role, if this matter is very important, there is likely to be a contradiction, so I may turn to others, such as colleagues C or leadership, let them respectively with a, B communication, and perhaps I will focus on the spirit, In front of A and b before the use of different ways to communicate, then is the proxy. Oh, think of it and write it down. Keep to the chase.

Eda

The current very fire architecture model, where the event is not the domain event in ddd, purely refers to this architectural style of event, of course, in some cases we can think so, but this is not applied.

If now in a distributed system, there are 2 subsystem instances, ServiceA and SERVICEB.

If one of the features of ServiceA is to create a ACCOUNT,SERVICEB feature is to send a message.

There is now a system-level feature that sends a message to this account when an account is created.

Then ServiceA will notify ServiceB to send a message when the account is created. They communicate with each other.

Event can be thought of as a model of passing messages between them, for example ServiceA creates an account and publishes an event called Onaccountcreated, which is, of course, described in our actual implementation as a variety of classes, In Enode the event message is defined by the author as Message,message is an event that contains information about the event in an event, such as the Onaccountcreated event that contains the new account's mailbox.

There is another model, is our traditional implementation of the model, you can learn from the CQRS Command/query, for example, ServiceA created an account, call ServiceB the method of sending mail, the call to send a message is a command, ServiceA command serviceb send mail.

Does it feel a bit like pub/sub and request/reply, the corresponding implementation is RPC and MOM.

It can be understood, but it's not exactly.

Generally we use the RPC framework of request/reply, both sides define the contract, if our contract is a function-oriented, such as ServiceB define a SendMail (account account); When ServiceA is finished creating the account, it can call this interface to send messages.

If we can use request/reply to implement the event, it is perfectly possible for ServiceA to send an onaccountcreated event to SERVICEB using the RPC framework, The account information is included in the Onaccountcreated event and SERVICEB begins sending the message. There are many elegant implementations of event handling, and the simplest form of violence is to directly prescribe a common interface, based on the event-handling logic passed over.

The problem is here, using RPC we need to know the other party's contract, even if it is rest we also need to know the URL is the resource address. Through the wrapper of the event we are actually eliminating the contract between the RPC and the resource address on the rest side. What is the angle of our contract, that is decoupling the angle, for example, if our contract is a business contract, is decoupling the business can also be considered as a function, servicea do not need to know SERVICEB have the ability to send mail. ServiceA only need to send an event to ServiceB, perhaps not the onaccountcreated event.

In this way, we realize the decoupling of the message level through the event, which is essentially an abstraction of the message. The event wraps up the real business message and proves once again the applicability of the middle-tier statement. But there's a half-way back here.

But then ServiceA must know ServiceB, MOM can not let servicea don't need to know serviceb.

So Mom+event realized the distributed EDA, for ServiceA, do not need to know what to do next after the account creation, who will do. The master-slave relationship is isolated through mom.

See Request/reply and Pub/sub from a different perspective.

request/reply Send command, or just the scene, ServiceB need to return results or not return results, from the component run level, it is synchronous. We can do this by using event, such as ServiceA sending onaccountcreated events to Serviceb,serviceb sending onmailsendcompleted events to ServiceA, If this business scenario ServiceA must be sent successfully to perform subsequent operations, then it is still synchronous, and another explanation we can think of as synchronous non-blocking.

Pub/sub+event, we can also think of asynchronous non-blocking.

Then the real power of EDA is manifested, scalability, throughput, will rise.

EDA in Enode

Said a lot of EDA topics, or to enode inside to see the author's implementation.

As described earlier, Enode distributed granularity defines 4 types of event:application Message, Command, Domain Event, Exception within the developer application layer, They can be considered as an instance of the event in the CQRS framework scenario in EDA, which in fact is not accurate and should be the framework message type defined by the author in the Enode framework to be wrapped with the event. The combination of EDA will also have a mom, is the author's own implementation and open source Equeue. is not a equeue project, it is actually a proxy equeue in the Enode project.

At a glance, there are 4 kinds of messages pub/sub. Let's take a look at one of the implementations and make it clearer.

First look at the simplest applicationmessage.

Consumer Consumer, Subscribe (string topic); Subscribe to a topic where you can see the presence of MOM.

Iqueuemessagehandler.handle (queuemessage queuemessage, Imessagecontext context) method, consume also acts as a dispatcher role.

Publisher Publisher, Publishasync method, publishes a message, why there is no topic, such as the subject.

The author has split out, and within each subsystem you can define the difference between the 4 message types that are said to start. We are free to combine, for example, to define the application layer in DDD as a project,domain defined as a project, horizontal or vertical extension is feasible, in fact, can correspond to the current comparison of the fire of an architectural model, micro-services.

Let's keep looking at command.

Consumer Consumer

Commandmessage Equeue The information that is passed, as shown in

Note Replyaddress, which is the property that you will use later in this article.

Commandexecutedmessage command messages that have been processed

The commandresultprocessor command result handler here not only includes the result of command processing, but also handles the result of the current command-triggered domain event processing, as shown in.

You can determine whether the receipt is command or domainevent by Commandreplytype.

Executes a command and obtains the result of this command processing, which is specified when executing a command. Such as

This is actually the way the request/reply+event described by EDA can be described earlier, either synchronously or asynchronously, as shown in

Generally abide by the principle of CQRS, command does not return and is asynchronous, the author here through the Fututre way to get command execution of the receipt, is to be sure to get the results before continuing the following logical scenario. Sometimes you may want to get the results directly, as shown in. This is also the author considering a lot of scenes but not mechanically cqrs.

The way the author implements receipts is shown in the following 2 images

Consumer receive the message, after processing, if found in Commandmessage replyaddress exists, then through Sendreplyservice to send a receipt message to this address.

The rest of the domain event and exception are similar to the pub/sub composition. Not a brief introduction.

Event Sourcing-enode (iii)

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.