|
1 | | - |
| 1 | + |
2 | 2 |
|
3 | | -[](https://badge.fury.io/nu/ServiceBricks) |
4 | | - |
| 3 | +[](https://badge.fury.io/nu/ServiceBricks.Notification.Microservice) |
| 4 | + |
5 | 5 | [](https://opensource.org/licenses/MIT) |
6 | 6 |
|
7 | | -# ServiceBricks: The Microservices Foundation |
| 7 | +# ServiceBricks Notification Microservice |
8 | 8 |
|
9 | 9 | ## Overview |
10 | 10 |
|
11 | | -[ServiceBricks](https://ServiceBricks.com) is a powerful microservices platform designed to streamline the development, deployment, and maintenance of distributed systems using artificial intelligence. |
12 | | -Leveraging Domain-Driven Design (DDD), Event-Driven Architecture (EDA), and a host of advanced features, ServiceBricks empowers teams to create scalable, customizable services tailored to specific business domains. |
| 11 | +This repository contains the notification microservice built using the ServiceBricks foundation. |
| 12 | +The notification microservice is responsible for sending emails and SMS messages from the system. |
| 13 | +It provides a background task to process notify messages, along with retry, should external providers not be available when being sent. |
| 14 | +It subscribes to service bus messages for email and sms broadcasts, so that the security microservice and others have a default mechanism to send notifications from the system. |
13 | 15 |
|
14 | | -## Why ServiceBricks? |
| 16 | +### Supported Providers |
| 17 | +By default, dependency injection is registered with a dummy email and sms provider that does not send any message but simply logs them using an ILogger<> inteface. |
| 18 | +You must explicitly add a line of code and configurations to register the providers below. |
| 19 | +You can quickly build your own providers by including the **ServiceBricks.Notification.Model** NuGet package and implementing the IEmailProvider and ISmsProvider interfaces. |
15 | 20 |
|
16 | | -* **Artificial Intelligence:** Use our online generator to create production-grade microservices in seconds using only a single human sentence as input. |
17 | | -* **Advanced Architecture:** Provides the core architectural patterns, implementation, standardization, and governance for your microservices. |
18 | | -* **REST APIs:** Expose standardized, secure REST APIs to manage your data. |
19 | | -* **Storage Agnostic:** Interchangeably supports relational, document, cloud or embedded database engines |
20 | | -* **Seamless Integration:** Switch storage providers without impacting microservice operations and avoid vendor lock-in. |
21 | 21 |
|
| 22 | +#### Email |
22 | 23 |
|
23 | | -## Major Features |
| 24 | +* SendGrid - Nuget Package - ServiceBricks.Notification.SendGrid |
24 | 25 |
|
25 | | -* **Artificial Intelligence Integration:** Use large language models to build, query and manipulate your microservice data using simple human input. |
26 | | -* **Generics:** Extensive use of generics, allowing the compiler to generate most of the required source code. |
27 | | -* **REST API Services:** Templated, repository-based services for quickly exposing standard CRUD+QPV (Query, Patch, Validate) methods or custom methods. |
28 | | -* **[ServiceQuery Integration](https://github.com/holomodular/ServiceQuery):** Supports standardized, polyglot, dynamic data querying for all database engines. |
29 | | -* **[Business Rule Engine](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/BusinessRuleEngine.md):** Polymorphic techniques to build reusable business logic. |
30 | | -* **[Domain-Driven Design (DDD)](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/FlowOfData.md) & [Event-Driven Architecture (EDA)](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/EventDrivenArchitecture.md):** Customize business logic for any supported object and method. |
31 | | -* **[Background Processing](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/BackgroundTasks.md):** Supports asynchronous processes, tasks, and rules. |
32 | | -* **[Relational, Document, Cloud and Embedded Database Support](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/SupportedDatabaseEngines.md):** Works standard with Azure Data Tables, Cosmos DB, InMemory, MongoDB, Postgres, SQLite, SQL Server and more. |
33 | | -* **[Service Bus Engine](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/BroadcastsAndServiceBus.md):** Supports broadcasts of system data with InMemory and Azure Service Bus. |
34 | | -* **[Classic or Modern REST API Design](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/ClassicVsModernRestApi.md):** Choose between Classic or Modern modes, with various response formats. |
35 | | -* **[NuGet Packages](https://github.com/holomodular/ServiceBricks-Documentation/blob/main/V1/NuGet.md):** Quickly build new services and applications. |
36 | | -* **Testing Framework:** Comprehensive Xunit test framework for robust unit and integration testing with thousands of tests available. |
37 | | -* **Open Source:** All referenced assemblies are open source and licensed under MIT or an equivalent license. |
| 26 | +Add ServiceBricks:Notification:SendGrid:ApiKey to your appsettings.config |
| 27 | +```csharp |
| 28 | +using ServiceBricks.Notification.SendGrid; |
| 29 | +services.AddServiceBricksNotificationSendGrid(); |
| 30 | +``` |
38 | 31 |
|
| 32 | +* SMTP - Included in ServiceBricks.Notification |
39 | 33 |
|
40 | | -## Getting Started with Examples |
| 34 | +See config below |
| 35 | +```csharp |
| 36 | +services.AddScoped<IEmailProvider, SmtpEmailProvider>(); |
| 37 | +``` |
41 | 38 |
|
42 | | -Explore our [ServiceBricks-Examples](https://github.com/holomodular/ServiceBricks-Examples) repository for practical examples on hosting and deploying your ServiceBricks foundation. From single, monolithic web applications to distributed, multi-deployment, containerized web applications, these examples provide the building blocks to create and scale your own foundations quickly. |
| 39 | +#### SMS |
43 | 40 |
|
44 | | -## Documentation |
| 41 | +Coming soon! Or build your own as needed. |
45 | 42 |
|
46 | | -Check out our [ServiceBricks-Documentation](https://github.com/holomodular/ServiceBricks-Documentation) repository for comprehensive documentation on the platform, including guides on using all components and developing your own microservices. |
| 43 | +## Data Transfer Objects |
47 | 44 |
|
48 | | -## Official Pre-Built Microservices |
| 45 | +### NotifyMessageDto - Admin Policy |
| 46 | +Used to store a notification message. It additionally contains properties to support the IDpWorkProcess and WorkService for processing the table like a work queue. |
49 | 47 |
|
50 | | -Get started quickly with our pre-built microservices: |
| 48 | +```csharp |
51 | 49 |
|
52 | | -* [ServiceBricks-Cache](https://github.com/holomodular/ServiceBricks-Cache): Generic data storage microservice with a built in expiration process and a distributed semaphore for cache-level locking for multi-instance deployments. |
53 | | -* [ServiceBricks-Logging](https://github.com/holomodular/ServiceBricks-Logging): Service-scoped or centralized logging and a web request auditing microservice. |
54 | | -* [ServiceBricks-Notification](https://github.com/holomodular/ServiceBricks-Notification): Notification and delivery for emails and SMS messages. |
55 | | -* [ServiceBricks-Security](https://github.com/holomodular/ServiceBricks-Security): Authentication, authorization, and application security with JWT bearer token support for multi-instance deployments. |
56 | | -* [ServiceBricks-Work](https://github.com/holomodular/ServiceBricks-Work): Work queue microservice for reliable, event-driven background processing. |
| 50 | +public class NotifyMessageDto : DataTransferObject, IDpWorkProcess |
| 51 | +{ |
| 52 | + public string SenderType { get; set; } |
| 53 | + public virtual bool IsHtml { get; set; } |
| 54 | + public virtual string Priority { get; set; } |
| 55 | + public virtual string Subject { get; set; } |
| 56 | + public virtual string BccAddress { get; set; } |
| 57 | + public virtual string CcAddress { get; set; } |
| 58 | + public virtual string ToAddress { get; set; } |
| 59 | + public virtual string FromAddress { get; set; } |
| 60 | + public virtual string Body { get; set; } |
| 61 | + public virtual string BodyHtml { get; set; } |
57 | 62 |
|
58 | | -## Trademarks |
| 63 | + // IDpWorkProcess related |
| 64 | + public bool IsError { get; set; } |
| 65 | + public bool IsComplete { get; set; } |
| 66 | + public int RetryCount { get; set; } |
| 67 | + public DateTimeOffset FutureProcessDate { get; set; } |
| 68 | + public DateTimeOffset CreateDate { get; set; } |
| 69 | + public DateTimeOffset UpdateDate { get; set; } |
| 70 | + public DateTimeOffset ProcessDate { get; set; } |
| 71 | + public string ProcessResponse { get; set; } |
| 72 | + public bool IsProcessing { get; set; } |
59 | 73 |
|
60 | | -“ServiceBricks”, "ServiceQuery" and “HoloModular” are trademarks of HoloModular LLC. The MIT License covers code only; it does not grant rights to use our trademarks, logos, or brand assets (including in modified or redistributed versions) without permission. |
| 74 | +} |
61 | 75 |
|
62 | | -## About |
| 76 | +``` |
| 77 | + |
| 78 | +## Business Events and Processes |
| 79 | + |
| 80 | +### SendNotificationProcess |
| 81 | +This process is used to send a notify message. The SendNotificationProcessRule class implements the functionality to send an email or sms sendertype. |
| 82 | +You can register new rules to handle new sender types or unregister the existing rule and build your own. |
| 83 | + |
| 84 | + |
| 85 | +## Background Tasks and Timers |
| 86 | + |
| 87 | +### SendNotificationTimer class |
| 88 | +A background timer can be enabled, with an initial delay and interval, that executes the SendNotificationTask. |
| 89 | + |
| 90 | +[View Source](https://github.com/holomodular/ServiceBricks-Notification/blob/main/src/V1/ServiceBricks.Notification/Background/SendNotificationTimer.cs) |
| 91 | + |
| 92 | +### SendNotificationTask class |
| 93 | +This background task invokes the [NotifyMessageWorkService](https://github.com/holomodular/ServiceBricks-Notification/blob/main/src/V1/ServiceBricks.Notification/Background/SendNotificationTask.cs) |
| 94 | + |
| 95 | +[View Source](https://github.com/holomodular/ServiceBricks-Notification/blob/main/src/V1/ServiceBricks.Notification/Background/SendNotificationTask.cs) |
| 96 | + |
| 97 | + |
| 98 | +## Service Bus |
| 99 | + |
| 100 | +### CreateApplicationEmailBroadcast |
| 101 | +This microservice subscribes to the CreateApplicationEmailBroadcast message. |
| 102 | +It is associated to the [CreateApplicationEmailRule](https://github.com/holomodular/ServiceBricks-Notification/blob/main/src/V1/ServiceBricks.Notification/Rule/CreateApplicationEmailRule.cs) Business Rule. |
| 103 | +When receiving the message from service bus, it will attempt to send the notification first, then store the process disposition before creating the message in storage. This reduces the reliance on the timer for sending messages and sends messages immediately when received. |
| 104 | + |
| 105 | +```csharp |
| 106 | + |
| 107 | + public class CreateApplicationEmailBroadcast : DomainBroadcast<ApplicationEmailDto> |
| 108 | + { |
| 109 | + public CreateApplicationEmailBroadcast(ApplicationEmailDto obj) |
| 110 | + { |
| 111 | + DomainObject = obj; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +### CreateApplicationSmsBroadcast |
| 118 | +This microservice subscribes to the CreateApplicationSmsBroadcast message. |
| 119 | +It is associated to the [CreateApplicationSmsRule](https://github.com/holomodular/ServiceBricks-Notification/blob/main/src/V1/ServiceBricks.Notification/Rule/CreateApplicationSmsRule.cs) Business Rule. |
| 120 | +When receiving the message from service bus, it will attempt to send the notification first, then store the process disposition before creating the message in storage. This reduces the reliance on the timer for sending messages and sends messages immediately when received. |
| 121 | +```csharp |
| 122 | + |
| 123 | + public class CreateApplicationSmsBroadcast : DomainBroadcast<ApplicationSmsDto> |
| 124 | + { |
| 125 | + public CreateApplicationSmsBroadcast(ApplicationSmsDto obj) |
| 126 | + { |
| 127 | + DomainObject = obj; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | +``` |
| 132 | + |
| 133 | +## Additional |
| 134 | + |
| 135 | + |
| 136 | +## Application Settings |
| 137 | + |
| 138 | +```json |
| 139 | + |
| 140 | +{ |
| 141 | + // ServiceBricks Settings |
| 142 | + "ServiceBricks":{ |
| 143 | + |
| 144 | + // Notification Microservice Settings |
| 145 | + "Notification": { |
| 146 | + |
| 147 | + // Send Notification Process |
| 148 | + "Send": { |
| 149 | + "TimerEnabled": false, |
| 150 | + "TimerIntervalMilliseconds": 7000, |
| 151 | + "TimerDueMilliseconds": 1000, |
| 152 | + "EmailFromDefault": "support@servicebricks.com", |
| 153 | + "SmsFromDefault": "1234567890", |
| 154 | + "IsDevelopment": false, |
| 155 | + "DevelopmentEmailTo": "developer@servicebricks.com", |
| 156 | + "DevelopmentSmsTo": "1234567890" |
| 157 | + }, |
| 158 | + |
| 159 | + // SMTP provider |
| 160 | + "Smtp": { |
| 161 | + "EmailServer": "yourserver.com", |
| 162 | + "EmailPort": 123, |
| 163 | + "EmailEnableSsl": true, |
| 164 | + "EmailUsername": "username", |
| 165 | + "EmailPassword": "password" |
| 166 | + }, |
| 167 | + |
| 168 | + // ServiceBricks.Notification.SendGrid NuGet Package |
| 169 | + "SendGrid": { |
| 170 | + "ApiKey": "SendGridApiKey" |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +``` |
| 177 | + |
| 178 | +# About ServiceBricks |
| 179 | + |
| 180 | +ServiceBricks is the cornerstone for building a microservices foundation. |
| 181 | +Visit https://ServiceBricks.com to learn more. |
63 | 182 |
|
64 | | -ServiceBricks is owned and maintained by HoloModular LLC and authored by Danny Logsdon (Founder). Visit our websites at https://HoloModular.com, https://ServiceBricks.com or https://www.linkedin.com/in/danlogsdon to learn more. |
|
0 commit comments