The document discusses SOA and NServiceBus. SOA aims to reduce coupling between systems through messaging and pub/sub. NServiceBus is a .NET messaging solution that uses an asynchronous distributed bus to enable loose coupling between services. It allows services to publish and subscribe to messages to communicate. NServiceBus provides benefits like scalability, durability, and improved developer productivity compared to traditional n-tier architectures. The document provides examples of how services can use events and handlers with NServiceBus to integrate and communicate asynchronously.
10. In practice [cont.]
• Following principles (best thinking):
• Explicit intentions [naming, context]
• Single Responsibility
• Command Query Separation
• Drive your design and decision making to
address all aspects of coupling
• Backwards compatibility
11. Why NServiceBus?
• .Net Solution
• Distributed bus (not a broker)
• Messaging pub/sub (asynchronous)
• Durable and Transactional (if you want)
• Sagas
12. Why NServiceBus? [cont.]
• A Message
[Serializable]
public class EventMessage : IMyEvent
{
public Guid EventId { get; set; }
public DateTime? Time { get; set; }
}
public interface IMyEvent
{
Guid EventId { get; set; }
DateTime? Time { get; set; }
TimeSpan Duration { get; set; }
}
var m = new EventMessage();
// Or:
var m = Bus.CreateInstance<IMyEvent>();
13. Why NServiceBus? [cont.]
• Handler
public IBus Bus { get; set; }
public class EventMessageHandler : IHandleMessages<EventMessage>
{
public void Handle(EventMessage message)
{
// do stuff...
IMyEvent anotherEventMessage;
anotherEventMessage = Bus.CreateInstance<IMyEvent>();
anotherEventMessage = Guid.NewGuid();
anotherEventMessage = DateTime.Now.Second;
anotherEventMessage = TimeSpan.FromSeconds(99999D);
Bus.Publish(anotherEventMessage);
}
}
14. Service Examples
Place Order
Sales
Save status locally Save pricing locally
Subscribe to Product Pricing
Subscribe to Customer Status Updated
Updated
Publish
Product Pricing Updated
Publish
Customer Customer Status Updated Marketing
Care Publish Order Accepted