![]() ![]()
make the call to the service to get the order details hereĬurrentMessage.Respond(details, x => x.ExpiresAt(5.Minutes().FromNow())) Public void Consume(SendOrderDetailsRequest request) public class OrderDetailsWebServiceProxy : The saga uses the external service proxy to perform the actual work, which is shown in the proxy class below. The constructor with the Guid is used to initialize the saga when a new one is created, the protected one is there for NHibernate to be able to persist the saga. The properties are part of the saga and get saved when the saga is persisted (using the NHibernate saga persister, or in the case of the sample the in-memory implementation). The rest of the saga class is shown above for completeness. We will look at some other ways we can enhance the performance of the service later on by using some additional states. We also include the state of the saga to ensure that we do not match to a request that has already completed. Since our request criteria include our customer id and our order id, we use those to correlate the message to the saga. By((saga, message) => saga.CustomerId = message.CustomerId & #MASSTRANSIT REQUEST RESPONSE CODE#The previous code merely defines our class as a saga and calls our saga initialization method (shown below). Our saga state machine uses a static initializer to define the states, events, and transitions of a saga. While the TDD purists might want to call YAGNI at this point, let me assure you that “it will all be… revealed!” So for now, let us take a look at the first pass of our saga definition. Time To Make the SagaĪt this point in the design of our service, the need for a saga to manage the request state is not entirely obvious. ![]() Reliance on a primary key outside of the context of the system storing the order details is a path to friction or outright failure. While SQL purists will point out that numeric primary keys are quicker for retrieving rows in a database, they make for a very fragile interface with other components in the system. The request and response are correlated on identifiers that make sense in the application domain. Notice that no internal values are included - no primary key from the order table and no primary key from the customer table. Created is when the order was created, and Status is an enum representing the status of the order. The CustomerId and OrderId are the same as the values passed in the request. When the order details are received, the following message is published. The message contract representing a request for order details includes the CustomerId and the OrderId. The message contracts are defined using interfaces, allowing the class for the message to be an internal implementation detail. The interface exposed to the application consists of two messages, the first for the command and the second for the response. The second is the saga that provides the interface to the service gateway. The first implements the communication to the external service with a set of messages that are only used internally by the service. The gateway itself consists of two components. In this post, I’m going to share some of the initial code that makes up the gateway service. #MASSTRANSIT REQUEST RESPONSE HOW TO#The past two posts began to explain how to build a service gateway using MassTransit. The implementation will be built in C# using MassTransit, StructureMap, ASP.NET MVC, and NHibernate. #MASSTRANSIT REQUEST RESPONSE SERIES#This post is the third in a series on building a highly available service gateway. Building a Service Gateway Using MassTransit, Part 3 1 November, 2009. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |