Skip to content

Commit

Permalink
Fix Grpc generate problem.
Browse files Browse the repository at this point in the history
Add grpc service installer in identity and email project.
Add in iJwtService CreateToken method and implement in JwtService .
Delete email logic in identity service and implement message pattern logic.
  • Loading branch information
a-sharifov committed Feb 5, 2024
1 parent c189553 commit 095c0e0
Show file tree
Hide file tree
Showing 45 changed files with 207 additions and 176 deletions.
2 changes: 1 addition & 1 deletion crs/CommonComponents/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="8.2.1" />
<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";

package Contracts.Abstractions.Protobuf;
option csharp_namespace = "Contracts.Abstractions";

package abstractions;


message NotFound {}
34 changes: 22 additions & 12 deletions crs/CommonComponents/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\EventBus\EventBus.Common\EventBus.Common.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\EventBus\EventBus.Common\EventBus.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Abstractions\" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="Abstractions\Abstractions.proto" GrpcServices="Both" />
<Protobuf Include="Services\Identity\Identity.proto" GrpcServices="Both" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.25.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />
<PackageReference Include="Grpc.Tools" Version="2.61.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions crs/CommonComponents/Contracts/Services/Identity/Identity.proto
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
syntax = "proto3";

package Contracts.Services.Idenitty.Protobuf;
option csharp_namespace = "Contracts.Services.Identity";

import "Abstractions/Abstractions.proto";
package identity;

service IdenittyService {
service IdentityService {
rpc GetUser(GetUserRequest) returns (User);
}

message GetUserRequest {
string id = 1;
}

message UserDetails {
message User {
string user_id = 1;
string email = 3;
string first_name = 2;
string last_name = 2;
bool is_email_confirmed = 4;
Role role = 5;
Gender gender = 6;
string email = 2;
string first_name = 3;
string last_name = 4;
bool is_email_confirmed = 5;
Role role = 6;
Gender gender = 7;
}

enum Role {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
global using MassTransit;
global using MassTransit.Configuration;
global using EventBus.Common.Abstractions;
global using Common.Events;
8 changes: 7 additions & 1 deletion crs/Docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ REDIS_PASSWORD=Password123
RABBITMQ_DEFAULT_USER=admin
RABBITMQ_DEFAULT_PASS=admin

CERTBOT_EMAIL=akber.sharifov2004@gmail.com
CERTBOT_EMAIL=akber.sharifov2004@gmail.com

EMAIL_FROM=Eshop
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USERNAME=akber.sharifov2004@gmail.com
EMAIL_PASSWORD=ueey qfia bnyx atce
8 changes: 8 additions & 0 deletions crs/Docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ services:
- ASPNETCORE_HTTP_PORTS=5110
- ASPNETCORE_ENVIRONMENT=Development
# Custom environment variables
- Email__From=${EMAIL_FROM}}
- Email__Host=${EMAIL_HOST}
- Email__Port=${EMAIL_PORT}
- Email__Username=${EMAIL_USERNAME}
- Email__Password=${EMAIL_PASSWORD}
- Retry__Message__Send__Count=3
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
ports:
- "5110:80"



mssql:
environment:
- ACCEPT_EULA=Y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Polly" Version="8.2.1" />
<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="Quartz" Version="3.8.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Email.App.Configurations;

internal sealed class GrpcServiceInstaller : IServiceInstaller
{
public void Install(IServiceCollection services, IConfiguration configuration)
{
services.AddGrpcClient<IdentityService.IdentityServiceClient>(options =>
{
options.Address = new Uri(Env.IDENTITY_URL);
});

services.AddGrpc();
}
}
2 changes: 2 additions & 0 deletions crs/Services/Email/Email.App/Email.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
Expand All @@ -24,6 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\CommonComponents\Common\Common.csproj" />
<ProjectReference Include="..\..\..\CommonComponents\Contracts\Contracts.csproj" />
<ProjectReference Include="..\Email.Application\Email.Application.csproj" />
<ProjectReference Include="..\Email.Infrastructure\Email.Infrastructure.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions crs/Services/Email/Email.App/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// </summary>
internal static class Env
{
public static string IDENTITY_URL => GetEnvironmentVariable("IDENTITY_URL");
public static string RABBITMQ_DEFAULT_USER => GetEnvironmentVariable("RABBITMQ_DEFAULT_USER");
public static string RABBITMQ_DEFAULT_PASS => GetEnvironmentVariable("RABBITMQ_DEFAULT_PASS");

Expand Down
1 change: 1 addition & 0 deletions crs/Services/Email/Email.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
global using FluentValidation;
global using Email.App.OptionsSetup;
global using Common.Infrastructure.Middleware;
global using Contracts.Services.Identity;
8 changes: 0 additions & 8 deletions crs/Services/Email/Email.App/appsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ Logging:
LogLevel:
Default: Information
Microsoft.AspNetCore: Warning

Email:
From: Eshop
Host: smtp.gmail.com
Port: 587
Username: akber.sharifov2004@gmail.com
Password: ueey qfia bnyx atce


Swagger:
Title: "Email API"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ internal sealed class SendConfirmationUserMessageCommandHandler(IIdentityEmailSe
: ICommandHandler<SendConfirmationUserMessageCommand>
{
private readonly IIdentityEmailService _emailService = emailService;
private readonly I


public Task<Result> Handle(SendConfirmationUserMessageCommand request, CancellationToken cancellationToken)
{



_emailService.SendConfirmationEmailAsync(
new SendConfirmationEmailRequest
{
Expand Down
2 changes: 1 addition & 1 deletion crs/Services/Email/Email.Application/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global using System.Reflection;
global using Common.Application.Abstractions.Messaging.Command;
global using Common.Domain.Primitives.Results;
global using Email.Infrastructure.Email.Abstractions;
global using Email.Infrastructure.Email.Abstractions;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="MimeKit" Version="4.3.0" />
<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface IEmailService
/// <param name="request">The <see cref="SendMessageRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns></returns>
Task SendAsync(SendMessageRequest request, CancellationToken cancellationToken = default);
Task SendMessageAsync(SendMessageRequest request, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class EmailOptions
public int Port { get; set; }
public string Username { get; set; } = null!;
public string Password { get; set; } = null!;
public int RetryMessageSendCount { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// This class is used to get the path of the email templates.
/// </summary>
public static class EmailTemplatePath
internal static class EmailTemplatePath
{
/// <summary>
/// required change this template: {{firstName}}, {{lastName}}, {{confirmationLink}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace Email.Infrastructure.Email;

public abstract class EmailBaseService(IOptions<EmailOptions> options) : IEmailService
internal abstract class EmailBaseService(IOptions<EmailOptions> options) : IEmailService
{
private readonly EmailOptions _options = options.Value;

public async Task SendAsync(SendMessageRequest request, CancellationToken cancellationToken = default)
public async Task SendMessageAsync(SendMessageRequest request, CancellationToken cancellationToken = default) =>
await Policy.Handle<Exception>()
.WaitAndRetryAsync(
_options.RetryMessageSendCount,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
.ExecuteAsync(async () => await SendAsync(request, cancellationToken));

private async Task SendAsync(SendMessageRequest request, CancellationToken cancellationToken = default)
{
MimeMessage message = new();
message.From.Add(MailboxAddress.Parse(_options.From));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public async Task SendConfirmationEmailAsync(SendConfirmationEmailRequest reques
Body: confirmEmailTemplate
);

await SendAsync(sendMessageRequest, cancellationToken);
await SendMessageAsync(sendMessageRequest, cancellationToken);
}
}
3 changes: 2 additions & 1 deletion crs/Services/Email/Email.Infrastructure/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
global using MimeKit;
global using MailKit.Net.Smtp;
global using System.Reflection;
global using System.Text.Encodings.Web;
global using System.Text.Encodings.Web;
global using Polly;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\CommonComponents\Contracts\Contracts.csproj" />
<ProjectReference Include="..\..\..\CommonComponents\EventBus\EventBus.MassTransit\EventBus.MassTransit.csproj" />
<ProjectReference Include="..\Email.Application\Email.Application.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion crs/Services/Email/Email.MessageBus/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
global using EventBus.MassTransit.Handlers;
global using Contracts.Services.Identity.Commands;
global using MassTransit;
global using MassTransit;
global using MediatR;
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
namespace Email.MessageBus.Handlers.Commands;
using Email.Application.Emails.Commands.SendConfirmationUserMessage;

public sealed class UserCreatedConfirmationEmailSendCommandHandler
: IntegrationCommandHandler<UserCreatedConfirmationEmailSendCommand>
namespace Email.MessageBus.Handlers.Commands;

internal sealed class UserCreatedConfirmationEmailSendCommandHandler(ISender sender)
: IntegrationCommandHandler<UserCreatedConfirmationEmailSendCommand>
{
public override Task Handle(ConsumeContext<UserCreatedConfirmationEmailSendCommand> context)
private readonly ISender _sender = sender;

public override async Task Handle(ConsumeContext<UserCreatedConfirmationEmailSendCommand> context)
{
throw new NotImplementedException();
var request = new SendConfirmationUserMessageCommand(
context.Message.UserId,
context.Message.ReturnUrl);

var result = await _sender.Send(request);

if (result.IsFailure)
{
throw new Exception(result.Error);
}
}
}
3 changes: 3 additions & 0 deletions crs/Services/Identity/Idenitty.Grpc/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using Grpc.Core;
global using Contracts.Services.Identity;
global using MediatR;
21 changes: 16 additions & 5 deletions crs/Services/Identity/Idenitty.Grpc/Idenitty.Grpc.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Tools" Version="2.61.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\CommonComponents\Contracts\Contracts.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions crs/Services/Identity/Idenitty.Grpc/IdentityGrpcService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Idenitty.Grpc;

public sealed class IdentityGrpcService(ISender sender) : IdentityService.IdentityServiceBase
{
private readonly ISender _sender = sender;

public override async Task<User> GetUser(GetUserRequest request, ServerCallContext context)
{
var result = await _sender.Send();

return base.GetUser(request, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Identity.App.Configurations;

internal sealed class GrpcServiceInstaller : IServiceInstaller
{
public void Install(IServiceCollection services, IConfiguration configuration)
{
services.AddGrpc();
}
}
Loading

0 comments on commit 095c0e0

Please sign in to comment.