diff --git a/.gitignore b/.gitignore index 8ce36ecb..3da00f18 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ package-lock.json **/.vscode/ .DS_store node_modules -*.txt .env **/__pycache__/ *.suo diff --git a/pub_sub/csharp/CheckoutService/Program.cs b/pub_sub/csharp/CheckoutService/Program.cs deleted file mode 100644 index 974a1e37..00000000 --- a/pub_sub/csharp/CheckoutService/Program.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace CheckoutService -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } -} diff --git a/pub_sub/csharp/CheckoutService/Startup.cs b/pub_sub/csharp/CheckoutService/Startup.cs deleted file mode 100644 index 9a597315..00000000 --- a/pub_sub/csharp/CheckoutService/Startup.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; - -namespace CheckoutService -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - - services.AddControllers(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "CheckoutService", Version = "v1" }); - }); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CheckoutService v1")); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseCloudEvents(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapSubscribeHandler(); - endpoints.MapControllers(); - }); - } - } -} diff --git a/pub_sub/csharp/OrderProcessingService/Program.cs b/pub_sub/csharp/OrderProcessingService/Program.cs deleted file mode 100644 index 3b9dafc3..00000000 --- a/pub_sub/csharp/OrderProcessingService/Program.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using Dapr.Client; -using Microsoft.AspNetCore.Mvc; -using System.Threading; - -namespace EventService -{ - class Program - { - static async Task Main(string[] args) - { - string PUBSUB_NAME = "order_pub_sub"; - string TOPIC_NAME = "orders"; - while(true) { - System.Threading.Thread.Sleep(5000); - Random random = new Random(); - int orderId = random.Next(1,1000); - CancellationTokenSource source = new CancellationTokenSource(); - CancellationToken cancellationToken = source.Token; - using var client = new DaprClientBuilder().Build(); - await client.PublishEventAsync(PUBSUB_NAME, TOPIC_NAME, orderId, cancellationToken); - Console.WriteLine("Published data: " + orderId); - } - } - } -} diff --git a/pub_sub/csharp/checkout/Program.cs b/pub_sub/csharp/checkout/Program.cs new file mode 100644 index 00000000..7757a320 --- /dev/null +++ b/pub_sub/csharp/checkout/Program.cs @@ -0,0 +1,21 @@ +using System; +using Dapr.Client; +using System.Threading; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + + +while(true) { + Random random = new Random(); + var order = new Order(random.Next(1,1000)); + var data = JsonSerializer.Serialize(order); + CancellationTokenSource source = new CancellationTokenSource(); + CancellationToken cancellationToken = source.Token; + using var client = new DaprClientBuilder().Build(); + await client.PublishEventAsync("order_pub_sub", "orders", data, cancellationToken); + Console.WriteLine("Published data: " + data); + System.Threading.Thread.Sleep(1000); +} + +public record Order([property: JsonPropertyName("orderid")] int order_id); diff --git a/pub_sub/csharp/OrderProcessingService/OrderProcessingService.csproj b/pub_sub/csharp/checkout/checkout.csproj similarity index 78% rename from pub_sub/csharp/OrderProcessingService/OrderProcessingService.csproj rename to pub_sub/csharp/checkout/checkout.csproj index a82a4f1b..e55f867f 100644 --- a/pub_sub/csharp/OrderProcessingService/OrderProcessingService.csproj +++ b/pub_sub/csharp/checkout/checkout.csproj @@ -2,11 +2,11 @@ Exe - net5.0 + net6.0 - - + + diff --git a/pub_sub/csharp/CheckoutService/Controllers/CheckoutServiceController.cs b/pub_sub/csharp/order-processor/Controllers/order-processor.cs similarity index 78% rename from pub_sub/csharp/CheckoutService/Controllers/CheckoutServiceController.cs rename to pub_sub/csharp/order-processor/Controllers/order-processor.cs index 64039185..f5d357c6 100644 --- a/pub_sub/csharp/CheckoutService/Controllers/CheckoutServiceController.cs +++ b/pub_sub/csharp/order-processor/Controllers/order-processor.cs @@ -7,13 +7,13 @@ using System.Net; using Dapr; using Dapr.Client; -namespace CheckoutService.controller +namespace order_processor.controller { [ApiController] - public class CheckoutServiceController : Controller + public class order_processorController : Controller { [Topic("order_pub_sub", "orders")] - [HttpPost("checkout")] + [HttpPost("order-processor")] public HttpResponseMessage getCheckout([FromBody] int orderId) { Console.WriteLine("Subscriber received : " + orderId); diff --git a/pub_sub/csharp/order-processor/Program.cs b/pub_sub/csharp/order-processor/Program.cs new file mode 100644 index 00000000..8277f1c4 --- /dev/null +++ b/pub_sub/csharp/order-processor/Program.cs @@ -0,0 +1,40 @@ +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); + app.UseDeveloperExceptionPage(); +} + +app.MapGet("/dapr/subscribe", () => { + var subscriptions = "[{'pubsubname': 'order_pub_sub', 'topic': 'orders', 'route': 'orders'}]"; + return subscriptions; +}); + +app.MapPost("/orders", async (Order order) => { + Console.WriteLine("Subscriber received : " + order.ToString()); + return new HttpResponseMessage(HttpStatusCode.OK); +}); + + // [Topic("order_pub_sub", "orders")] + // [HttpPost("order-processor")] + // public HttpResponseMessage getCheckout([FromBody] int orderId) + // { + // Console.WriteLine("Subscriber received : " + orderId); + // return new HttpResponseMessage(HttpStatusCode.OK); + // } + +await app.RunAsync(); + +app.Run(); + +public record Order([property: JsonPropertyName("orderid")] int order_id); diff --git a/pub_sub/csharp/CheckoutService/Properties/launchSettings.json b/pub_sub/csharp/order-processor/Properties/launchSettings.json similarity index 100% rename from pub_sub/csharp/CheckoutService/Properties/launchSettings.json rename to pub_sub/csharp/order-processor/Properties/launchSettings.json diff --git a/pub_sub/csharp/CheckoutService/appsettings.Development.json b/pub_sub/csharp/order-processor/appsettings.Development.json similarity index 100% rename from pub_sub/csharp/CheckoutService/appsettings.Development.json rename to pub_sub/csharp/order-processor/appsettings.Development.json diff --git a/pub_sub/csharp/CheckoutService/appsettings.json b/pub_sub/csharp/order-processor/appsettings.json similarity index 100% rename from pub_sub/csharp/CheckoutService/appsettings.json rename to pub_sub/csharp/order-processor/appsettings.json diff --git a/pub_sub/csharp/CheckoutService/CheckoutService.csproj b/pub_sub/csharp/order-processor/order-processor.csproj similarity index 82% rename from pub_sub/csharp/CheckoutService/CheckoutService.csproj rename to pub_sub/csharp/order-processor/order-processor.csproj index dfacbc9a..dec6078e 100644 --- a/pub_sub/csharp/CheckoutService/CheckoutService.csproj +++ b/pub_sub/csharp/order-processor/order-processor.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 diff --git a/pub_sub/python/README.md b/pub_sub/python/README.md index a03f15ba..a17dfa33 100644 --- a/pub_sub/python/README.md +++ b/pub_sub/python/README.md @@ -49,7 +49,7 @@ sleep: 10 --> ```bash -dapr run --app-id checkoout --components-path ../../components/ -- python3 app.py +dapr run --app-id checkout --components-path ../../components/ -- python3 app.py ``` diff --git a/pub_sub/python/checkout/requirements.txt b/pub_sub/python/checkout/requirements.txt new file mode 100644 index 00000000..53c59751 --- /dev/null +++ b/pub_sub/python/checkout/requirements.txt @@ -0,0 +1 @@ +dapr diff --git a/pub_sub/python/order-processor/requirements.txt b/pub_sub/python/order-processor/requirements.txt new file mode 100644 index 00000000..2575cdc6 --- /dev/null +++ b/pub_sub/python/order-processor/requirements.txt @@ -0,0 +1,2 @@ +dapr +Flask