Skip to content

Commit e7cacd7

Browse files
David BritchDavid Britch
authored andcommitted
Merge branch 'master' into xamarin
2 parents c0800ed + 3273d72 commit e7cacd7

53 files changed

Lines changed: 577 additions & 333 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# eShopOnContainers - Microservices Architecture and Containers based Reference Application (**ALPHA state** - VS 2017 and CLI environments compatible)
1+
# eShopOnContainers - Microservices Architecture and Containers based Reference Application (**BETA state** - Visual Studio 2017 and CLI environments compatible)
22
Sample .NET Core reference application, powered by Microsoft, based on a simplified microservices architecture and Docker containers. <p>
33

44
> ### DISCLAIMER
5-
> **IMPORTANT:** The current state of this sample application is **ALPHA**, consider it version a 0.1 foundational version, therefore, many areas could be improved and change significantly while refactoring current code and implementing new features. **Feedback with improvements and pull requests from the community will be highly appreciated and accepted.**
5+
> **IMPORTANT:** The current state of this sample application is **BETA**, consider it version a 0.1 foundational version, therefore, many areas could be improved and change significantly while refactoring current code and implementing new features. **Feedback with improvements and pull requests from the community will be highly appreciated and accepted.**
66
>
7-
> This reference application proposes a simplified microservice oriented architecture implementation to introduce technologies like .NET Core with Docker containers through a comprehensive application. However, this reference application it is not trying to solve all the problems in a large and mission-critical distributed system, it is just a bootstrap for developers to easily get started in the world of Docker containers and microservices with .NET Core.
7+
> This reference application proposes a simplified microservice oriented architecture implementation to introduce technologies like .NET Core with Docker containers through a comprehensive application. The chosen domain is an eShop/eCommerce but simply because it is a well-know domain by most people/developers.
8+
However, this sample application should not be considered as an "eCommerce reference model", at all. The implemented business domain might not be ideal from an eCommerce business point of view. It is neither trying to solve all the problems in a large, scalable and mission-critical distributed system. It is just a bootstrap for developers to easily get started in the world of Docker containers and microservices with .NET Core.
89
> <p>For example, the next step (still not covered in eShopOnContainers) after understanding Docker containers and microservices development with .NET Core, is to select a microservice cluster/orchestrator like Docker Swarm, Kubernetes or DC/OS (in Azure Container Service) or Azure Service Fabric which in most of the cases will require additional partial changes to your application's configuration (although the present architecture should work on most orchestrators with small changes).
9-
> Or moving your databases to HA cloud services, or implementing your EventBus with Azure Service Bus or any other production ready Service Bus in the market.
10+
> Additional steps would be to move your databases to HA cloud services, or to implement your EventBus with Azure Service Bus or any other production ready Service Bus in the market.
1011
> <p> In the future we might fork this project and make multiple versions targeting specific microservice cluster/orchestrators plus using additional cloud infrastructure. <p>
1112
> <img src="img/exploring-to-production-ready.png">
1213
> Read the planned <a href='https://github.com/dotnet/eShopOnContainers/wiki/01.-Roadmap-and-Milestones-for-future-releases'>Roadmap and Milestones for future releases of eShopOnContainers</a> within the Wiki for further info about possible new implementations and provide feedback at the <a href='https://github.com/dotnet/eShopOnContainers/issues'>ISSUES section</a> if you'd like to see any specific scenario implemented or improved. Also, feel free to discuss on any current issue.
@@ -32,7 +33,7 @@ Additional miroservice styles with other frameworks and No-SQL databases will be
3233
> <p> However, in a real production environment it is recommended to have your databases (SQL Server and Redis, in this case) in HA (High Available) services like Azure SQL Database, Redis as a service or any other clustering system. If you want to change to a production configuration, you'll just need to change the connection strings once you have set up the servers in a HA cloud or on-premises.
3334
3435
## Related documentation and guidance
35-
While developing this reference application, we are creating a reference Guide/eBook named <b>"Architecting and Developing Containerized and Microservice based .NET Applications"</b> which explains in detail how to develop this kind of architectural style (microservices, Docker containers, Domain-Driven Design for certain microservices) plus other simpler architectural styles, like monolithic apps that can also live as Docker containers.
36+
While developing this reference application, we've been creating a reference <b>Guide/eBook</b> focusing on <b>architecting and developing containerized and microservice based .NET Applications</b> (download link available below) which explains in detail how to develop this kind of architectural style (microservices, Docker containers, Domain-Driven Design for certain microservices) plus other simpler architectural styles, like monolithic apps that can also live as Docker containers.
3637
<p>
3738
There are also additional eBooks focusing on Containers/Docker lifecycle (DevOps, CI/CD, etc.) with Microsoft Tools, already published plus an additional eBook focusing on Enterprise Apps Patterns with Xamarin.Forms.
3839
You can download them and start reviewing these Guides/eBooks here:
@@ -43,7 +44,7 @@ You can download them and start reviewing these Guides/eBooks here:
4344
| <a href='https://aka.ms/microservicesebook'><img src="img/ebook_arch_dev_microservices_containers_cover.png"> </a> | <a href='https://aka.ms/dockerlifecycleebook'> <img src="img/ebook_containers_lifecycle.png"> </a> | <a href='https://aka.ms/xamarinpatternsebook'> <img src="img/xamarin-enterprise-patterns-ebook-cover-small.png"> </a> |
4445
| <sup> <a href='https://aka.ms/microservicesebook'>**Download** (Early DRAFT, still work in progress)</a> </sup> | <sup> <a href='https://aka.ms/dockerlifecycleebook'>**Download** (First Edition from late 2016) </a> </sup> | <sup> <a href='https://aka.ms/xamarinpatternsebook'>**Download** (Early DRAFT, still work in progress) </a> </sup> |
4546

46-
Send feedback to [cesardl@microsoft.com](cesardl@microsoft.com)
47+
Send feedback to [dotnet-architecture-ebooks-feedback@service.microsoft.com](dotnet-architecture-ebooks-feedback@service.microsoft.com)
4748
<p>
4849
However, we encourage to download and review the "Architecting & Developing eBook" because the architectural styles and architectural patterns and technologies explained in the guidance are using this reference application when explaining many pattern implementations, so you'll understand much better the context, design and decisions taken in the current architecture and internal designs.
4950

6.75 KB
Loading
242 KB
Loading
31.1 KB
Loading

src/BuildingBlocks/EventBus/EventBus/Abstractions/IEventBus.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Text;
52

63
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
74
{

src/BuildingBlocks/EventBus/EventBus/Abstractions/IIntegrationEventHandler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Text;
52
using System.Threading.Tasks;
63

74
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions

src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42

53
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
64
{
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using Microsoft.Extensions.Logging;
2+
using Polly;
3+
using Polly.Retry;
4+
using RabbitMQ.Client;
5+
using RabbitMQ.Client.Events;
6+
using RabbitMQ.Client.Exceptions;
7+
using System;
8+
using System.IO;
9+
using System.Net.Sockets;
10+
11+
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
12+
{
13+
public class DefaultRabbitMQPersisterConnection
14+
: IRabbitMQPersisterConnection
15+
{
16+
private readonly IConnectionFactory _connectionFactory;
17+
private readonly ILogger<DefaultRabbitMQPersisterConnection> _logger;
18+
19+
IConnection _connection;
20+
bool _disposed;
21+
22+
object sync_root = new object();
23+
24+
public DefaultRabbitMQPersisterConnection(IConnectionFactory connectionFactory,ILogger<DefaultRabbitMQPersisterConnection> logger)
25+
{
26+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
27+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
28+
}
29+
30+
public bool IsConnected
31+
{
32+
get
33+
{
34+
return _connection != null && _connection.IsOpen && !_disposed;
35+
}
36+
}
37+
38+
public IModel CreateModel()
39+
{
40+
if (!IsConnected)
41+
{
42+
throw new InvalidOperationException("No RabbitMQ connections are available to perform this action");
43+
}
44+
45+
return _connection.CreateModel();
46+
}
47+
48+
public void Dispose()
49+
{
50+
if (_disposed) return;
51+
52+
_disposed = true;
53+
54+
try
55+
{
56+
_connection.Dispose();
57+
}
58+
catch (IOException ex)
59+
{
60+
_logger.LogCritical(ex.ToString());
61+
}
62+
}
63+
64+
public bool TryConnect()
65+
{
66+
_logger.LogInformation("RabbitMQ Client is trying to connect");
67+
68+
lock (sync_root)
69+
{
70+
var policy = RetryPolicy.Handle<SocketException>()
71+
.Or<BrokerUnreachableException>()
72+
.WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
73+
{
74+
_logger.LogWarning(ex.ToString());
75+
}
76+
);
77+
78+
policy.Execute(() =>
79+
{
80+
_connection = _connectionFactory
81+
.CreateConnection();
82+
});
83+
84+
if (IsConnected)
85+
{
86+
_connection.ConnectionShutdown += OnConnectionShutdown;
87+
_connection.CallbackException += OnCallbackException;
88+
_connection.ConnectionBlocked += OnConnectionBlocked;
89+
90+
_logger.LogInformation($"RabbitMQ persister connection acquire a connection {_connection.Endpoint.HostName} and is subscribed to failure events");
91+
92+
return true;
93+
}
94+
else
95+
{
96+
_logger.LogCritical("FATAL ERROR: RabbitMQ connections can't be created and opened");
97+
98+
return false;
99+
}
100+
}
101+
}
102+
103+
private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e)
104+
{
105+
if (_disposed) return;
106+
107+
_logger.LogWarning("A RabbitMQ connection is shutdown. Trying to re-connect...");
108+
109+
TryConnect();
110+
}
111+
112+
void OnCallbackException(object sender, CallbackExceptionEventArgs e)
113+
{
114+
if (_disposed) return;
115+
116+
_logger.LogWarning("A RabbitMQ connection throw exception. Trying to re-connect...");
117+
118+
TryConnect();
119+
}
120+
121+
void OnConnectionShutdown(object sender, ShutdownEventArgs reason)
122+
{
123+
if (_disposed) return;
124+
125+
_logger.LogWarning("A RabbitMQ connection is on shutdown. Trying to re-connect...");
126+
127+
TryConnect();
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)