This project is an example of using RabbitMQ message queuing, Hangfire services and generating reports and emails.
To be able to make the project Clean Architecture Design has been used.
- Asp.Net Core Web API and ConsoleApp with
.Net6.0
framework. - RabbitMQ server and packages. For more info about installing on windows check the link!
- Hangfire server packages and jobs.
- Mailkit for sending emails, ClosedXL for generating excel files.
- EntityFramworkCore as an ORM and Tools packages.
- MSSQL Server as an Database and SQLServer packages.
- Postman and Swagger used for tests.
- Creating a filter system for an endpoint like Paging, Filtering and Searching.
- Generate a message queue in one of the operations. (e.g. When creating a User)
- Create a service to Consume that message queue.
- Create a background service to get Current User List as Excel file and send that in Email at 7.35am on weekdays only.
- To get the project :
git clone https://github.com/186-Teleperformans-Net-Bootcamp/hafta5-mhtaldmr.git
- To create the database first, in the
TP.Net.Hw.Infrastructure
folder :
update-database
- To start the project, MULTIPLE STARTUP must be selected with
TP.Net.Hw.WebUI
andTP.Net.Hw.Consumer
or type in those folders:
dotnet run
- "dotnet restore" command can be used to restore dependencies and tools inside the project.
- The project can be directly started in VisualStudio by pressing 'F5'.
- The port will be listenin on : https://localhost:7182
1. Filtering Example
- For filtering https://localhost:7182/messages url can be used. Filter options are;
- For SortBy option, 3 different columns can be selected: messagebody, createdAt, Id
- The paging details will be sending in the header as: x-pagination.
2. Message Queueing Example
- For observing the message queues, connections, exchanges http://localhost:15672 RabbitMQ UI can be used.
- For generating a user https://localhost:7182/accounts/signup url can be used.
- After generating a user, a mesage will be publising with that user's info. Also, queueName and routingKey options must be spesified in the service parameters.
//Publishing the user when a new user is created!.
_publisherService.Publish(user: newUser, queueName: "direct.email", routingKey: "email1");
- Consumer will have the same queue name and connection, then it will consume the message immediately.
3. Hangfire Job Example
- For observing how the hangfire works, https://localhost:7182/hangfire Hangfire UI will be very helpful.
- According to requirements, the job for sending email, First the excel report must be extracted. Thus, in the email service, calling the excel report service and await for the result of it. Then attach the file, email can be send.
public async Task SendEmailReport()
{
//Calling the excel report export service!
await _reportService.GetUsersExcelReport();
...
}
- The generated recurring job can be seen in this Hangfire UI.
4. Email and Excel Report Example
- The created and sended Email.
- The generated excel files in the file explorer.
- The generated Excel file content.