Skip to content

Commit

Permalink
last commit for 101
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Karaca committed Apr 22, 2022
1 parent e38bc88 commit fcb90e6
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 192 deletions.
38 changes: 19 additions & 19 deletions MasstransitDemo.Api/Controllers/NotificationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
using MasstransitDemo.Shared;
using Microsoft.AspNetCore.Mvc;

namespace MasstransitDemo.Api.Controllers
namespace MasstransitDemo.Api.Controllers;

[Route("api/[controller]")]
[ApiController]
public class NotificationController : ControllerBase
{
[Route("api/[controller]")]
[ApiController]
public class NotificationController : ControllerBase
public readonly IPublishEndpoint publishEndpoint;

public NotificationController(IPublishEndpoint publishEndpoint)
{
public readonly IPublishEndpoint publishEndpoint;
this.publishEndpoint = publishEndpoint;
}

public NotificationController(IPublishEndpoint publishEndpoint)
{
this.publishEndpoint = publishEndpoint;
}
[HttpPost]
public async Task<IActionResult> Notify(NotificationDto notificationDto)
{
await publishEndpoint.Publish<INotificationCreated>(new {
NotificationDate = notificationDto.NotificationDate,
NotificationMessage = notificationDto.NotificationMessage,
NotificationType = notificationDto.NotificationType
});

[HttpPost]
public async Task Notify(NotificationModel model)
{
await publishEndpoint.Publish<INotificationSubmitted>(new NotificationSubmitted
{
NotificationDate = model.NotificationDate,
NotificationMessage = model.NotificationMessage,
NotificationType = model.NotificationType
});
}
return Ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MasstransitDemo.Api.Models
{
public class NotificationModel
public class NotificationDto
{
public DateTime NotificationDate { get; set; }
public string NotificationMessage { get; set; }
Expand Down
13 changes: 0 additions & 13 deletions MasstransitDemo.Api/Models/NotificationSubmitted.cs

This file was deleted.

35 changes: 0 additions & 35 deletions MasstransitDemo.Api/Observers/PublishObserver.cs

This file was deleted.

12 changes: 1 addition & 11 deletions MasstransitDemo.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
using MassTransit;
using MasstransitDemo.Api.Observers;
using MasstransitDemo.Shared;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var services = builder.Services;

services.AddSingleton<IPublishObserver, PublishObserver>();
services.AddMassTransit(busConfigurator =>
builder.Services.AddMassTransit(busConfigurator =>
{
busConfigurator.SetKebabCaseEndpointNameFormatter();
busConfigurator.UsingRabbitMq((context, busFactoryConfigurator) =>
{
busFactoryConfigurator.Host("rabbitmq", hostConfigurator => { });
busFactoryConfigurator.ConnectPublishObserver(context.GetRequiredService<IPublishObserver>());
});
//EndpointConvention.Map<INotificationSubmitted>(new Uri($"queue:{RabbitMQOptions.TransactionQueue}"));
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
Expand Down
6 changes: 3 additions & 3 deletions MasstransitDemo.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"profiles": {
"MasstransitDemo.Api": {
"commandName": "Project",
"launchBrowser": false,
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -21,15 +21,15 @@
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": false,
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": false,
"environmentVariables": {
Expand Down
36 changes: 0 additions & 36 deletions MasstransitDemo.Consumer/ConsumeObserver.cs

This file was deleted.

5 changes: 0 additions & 5 deletions MasstransitDemo.Consumer/IConsumer.cs

This file was deleted.

9 changes: 0 additions & 9 deletions MasstransitDemo.Consumer/INotificationProcessor.cs

This file was deleted.

15 changes: 15 additions & 0 deletions MasstransitDemo.Consumer/NotificationCreatedConsumer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MassTransit;
using MasstransitDemo.Shared;
using System.Text.Json;

namespace MasstransitDemo.Consumer;

public class NotificationCreatedConsumer : IConsumer<INotificationCreated>
{
public async Task Consume(ConsumeContext<INotificationCreated> context)
{
var serializedMessage = JsonSerializer.Serialize(context.Message, new JsonSerializerOptions { });

Console.WriteLine($"NotificationCreated event consumed. Message: {serializedMessage}");
}
}
13 changes: 0 additions & 13 deletions MasstransitDemo.Consumer/NotificationProcessor.cs

This file was deleted.

10 changes: 2 additions & 8 deletions MasstransitDemo.Consumer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
using MassTransit;
using MasstransitDemo.Consumer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Reflection;

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<INotificationProcessor, NotificationProcessor>();
services.AddSingleton<IConsumeObserver, ConsumeObserver>();
services.AddMassTransit(busConfigurator =>
{
var entryAssembly = Assembly.GetExecutingAssembly();
busConfigurator.AddConsumers(entryAssembly);
busConfigurator.UsingRabbitMq((context, busFactoryConfigurator) =>
{
busConfigurator.SetKebabCaseEndpointNameFormatter();
busFactoryConfigurator.Host("rabbitmq", h => { });
busFactoryConfigurator.Host("rabbitmq", "/", h => { });
busFactoryConfigurator.ConfigureEndpoints(context);
busFactoryConfigurator.ConnectConsumeObserver(context.GetRequiredService<IConsumeObserver>());
});
});
});

var app = builder.Build();

app.Run();
app.Run();
20 changes: 0 additions & 20 deletions MasstransitDemo.Consumer/SubmitNoticationConsumer.cs

This file was deleted.

8 changes: 8 additions & 0 deletions MasstransitDemo.Shared/INotificationCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MasstransitDemo.Shared;

public interface INotificationCreated
{
DateTime NotificationDate { get; }
string NotificationMessage { get; }
NotificationType NotificationType { get; }
}
9 changes: 0 additions & 9 deletions MasstransitDemo.Shared/INotificationSubmitted.cs

This file was deleted.

13 changes: 6 additions & 7 deletions MasstransitDemo.Shared/NotificationType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace MasstransitDemo.Shared
namespace MasstransitDemo.Shared;

public enum NotificationType
{
public enum NotificationType
{
Email,
Push,
Sms
}
Email,
Push,
Sms
}
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ services:
ports:
- '7047:443'
- '7048:80'
depends_on:
- "rabbitmq"

rabbitmq:
container_name: "rabbitmq"
container_name: "rabbitmqcontainer"
image: rabbitmq:management
hostname: "rabbitmq"
ports:
Expand All @@ -24,5 +26,4 @@ services:
context: .
dockerfile: MasstransitDemo.Consumer/Dockerfile
depends_on:
- "rabbitmq"

- "rabbitmq"

0 comments on commit fcb90e6

Please sign in to comment.