Skip to content

Commit

Permalink
Fix rabbit mq bindings in manifest. (#1985) (#2000)
Browse files Browse the repository at this point in the history
* Fix rabbit mq bindings in manifest.

* Use 3 tag for RMQ, and checkin manifest.
  • Loading branch information
mitchdenny committed Jan 31, 2024
1 parent 0e735d2 commit c7bb15f
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 474 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ node_modules/

# vscode python env files
.env
/playground/eShopLite/.gitignore
/playground/eShopLite/azure.yaml
/playground/eShopLite/next-steps.md
24 changes: 24 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.AppHost",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.ApiService", "playground\SqlServerEndToEnd\SqlServerEndToEnd.ApiService\SqlServerEndToEnd.ApiService.csproj", "{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mongo", "mongo", "{C544D8A6-977E-40EA-8B1A-1FB2146A2108}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.AppHost", "playground\mongo\Mongo.AppHost\Mongo.AppHost.csproj", "{8F132275-233C-4121-AC6F-352C902FA064}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.ApiService", "playground\mongo\Mongo.ApiService\Mongo.ApiService.csproj", "{40EC38A2-69DB-4759-81C8-13F31090FEA6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CatalogModel", "playground\eShopLite\CatalogModel\CatalogModel.csproj", "{83267206-9438-42CD-860C-C92E7DBAA4C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -565,6 +573,18 @@ Global
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.Build.0 = Release|Any CPU
{8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.Build.0 = Release|Any CPU
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.Build.0 = Release|Any CPU
{83267206-9438-42CD-860C-C92E7DBAA4C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83267206-9438-42CD-860C-C92E7DBAA4C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83267206-9438-42CD-860C-C92E7DBAA4C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83267206-9438-42CD-860C-C92E7DBAA4C3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -664,6 +684,10 @@ Global
{2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{7616FD70-6BEC-439D-B39E-A838F939C0F9} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
{C544D8A6-977E-40EA-8B1A-1FB2146A2108} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{8F132275-233C-4121-AC6F-352C902FA064} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108}
{40EC38A2-69DB-4759-81C8-13F31090FEA6} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108}
{83267206-9438-42CD-860C-C92E7DBAA4C3} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
2 changes: 1 addition & 1 deletion playground/eShopLite/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.WithReference(catalogDb)
.WithReplicas(2);

var messaging = builder.AddRabbitMQ("messaging");
var messaging = builder.AddRabbitMQContainer("messaging");

var basketService = builder.AddProject("basketservice", @"..\BasketService\BasketService.csproj")
.WithReference(basketCache)
Expand Down
27 changes: 26 additions & 1 deletion playground/eShopLite/AppHost/aspire-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,32 @@
}
},
"messaging": {
"type": "rabbitmq.server.v0"
"type": "container.v0",
"image": "rabbitmq:3",
"env": {
"RABBITMQ_DEFAULT_USER": "guest",
"RABBITMQ_DEFAULT_PASS": "{messaging.inputs.password}"
},
"bindings": {
"tcp": {
"scheme": "tcp",
"protocol": "tcp",
"transport": "tcp",
"containerPort": 5672
}
},
"connectionString": "amqp://guest:{messaging.inputs.password}@{messaging.bindings.tcp.host}:{messaging.bindings.tcp.port}",
"inputs": {
"password": {
"type": "string",
"secret": true,
"default": {
"generate": {
"minLength": 10
}
}
}
}
},
"basketservice": {
"type": "project.v0",
Expand Down
4 changes: 2 additions & 2 deletions playground/eShopLite/CatalogDb/CatalogDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CatalogModel\CatalogModel.csproj" />
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" />
<ProjectReference Include="..\..\..\src\Components\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions playground/eShopLite/CatalogModel/CatalogModel.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Components\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.csproj" />
</ItemGroup>

</Project>
142 changes: 142 additions & 0 deletions playground/eShopLite/CatalogModel/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CatalogModel;

public record Catalog(int FirstId, int NextId, bool IsLastPage, IEnumerable<CatalogItem> Data);

public class CatalogDbContext(DbContextOptions<CatalogDbContext> options) : DbContext(options)
{
// https://learn.microsoft.com/ef/core/performance/advanced-performance-topics#compiled-queries

private static readonly Func<CatalogDbContext, int?, int?, int?, int, IAsyncEnumerable<CatalogItem>> s_getCatalogItemsQuery =
EF.CompileAsyncQuery((CatalogDbContext context, int? catalogBrandId, int? before, int? after, int pageSize) =>
context.CatalogItems.AsNoTracking()
.OrderBy(ci => ci.Id)
.Where(ci => catalogBrandId == null || ci.CatalogBrandId == catalogBrandId)
.Where(ci => before == null || ci.Id <= before)
.Where(ci => after == null || ci.Id >= after)
.Take(pageSize + 1));

public Task<List<CatalogItem>> GetCatalogItemsCompiledAsync(int? catalogBrandId, int? before, int? after, int pageSize)
{
return ToListAsync(s_getCatalogItemsQuery(this, catalogBrandId, before, after, pageSize));
}

public DbSet<CatalogItem> CatalogItems => Set<CatalogItem>();
public DbSet<CatalogBrand> CatalogBrands => Set<CatalogBrand>();
public DbSet<CatalogType> CatalogTypes => Set<CatalogType>();

protected override void OnModelCreating(ModelBuilder builder)
{
DefineCatalogBrand(builder.Entity<CatalogBrand>());

DefineCatalogItem(builder.Entity<CatalogItem>());

DefineCatalogType(builder.Entity<CatalogType>());
}

private static void DefineCatalogType(EntityTypeBuilder<CatalogType> builder)
{
builder.ToTable("CatalogType");

builder.HasKey(ci => ci.Id);

builder.Property(ci => ci.Id)
.UseHiLo("catalog_type_hilo")
.IsRequired();

builder.Property(cb => cb.Type)
.IsRequired()
.HasMaxLength(100);
}

private static void DefineCatalogItem(EntityTypeBuilder<CatalogItem> builder)
{
builder.ToTable("Catalog");

builder.Property(ci => ci.Id)
.UseHiLo("catalog_hilo")
.IsRequired();

builder.Property(ci => ci.Name)
.IsRequired(true)
.HasMaxLength(50);

builder.Property(ci => ci.Price)
.IsRequired(true);

builder.Property(ci => ci.PictureFileName)
.IsRequired(false);

builder.Ignore(ci => ci.PictureUri);

builder.HasOne(ci => ci.CatalogBrand)
.WithMany()
.HasForeignKey(ci => ci.CatalogBrandId);

builder.HasOne(ci => ci.CatalogType)
.WithMany()
.HasForeignKey(ci => ci.CatalogTypeId);
}

private static void DefineCatalogBrand(EntityTypeBuilder<CatalogBrand> builder)
{
builder.ToTable("CatalogBrand");
builder.HasKey(ci => ci.Id);

builder.Property(ci => ci.Id)
.UseHiLo("catalog_brand_hilo")
.IsRequired();

builder.Property(cb => cb.Brand)
.IsRequired()
.HasMaxLength(100);
}

private static async Task<List<T>> ToListAsync<T>(IAsyncEnumerable<T> asyncEnumerable)
{
var results = new List<T>();
await foreach (var value in asyncEnumerable)
{
results.Add(value);
}

return results;
}
}

public class CatalogType
{
public int Id { get; set; }
public required string Type { get; set; }
}

public class CatalogBrand
{
public int Id { get; set; }
public required string Brand { get; set; }
}

public class CatalogItem
{
public int Id { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public decimal Price { get; set; }
public required string PictureFileName { get; set; }
public string? PictureUri { get; set; }

public int CatalogTypeId { get; set; }
public required CatalogType CatalogType { get; set; }

public int CatalogBrandId { get; set; }
public required CatalogBrand CatalogBrand { get; set; }
public int AvailableStock { get; set; }
public int RestockThreshold { get; set; }
public int MaxStockThreshold { get; set; }
public bool OnReorder { get; set; }
}
2 changes: 1 addition & 1 deletion playground/eShopLite/CatalogService/CatalogApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CatalogDb;
using CatalogModel;

namespace CatalogService;

Expand Down
3 changes: 2 additions & 1 deletion playground/eShopLite/CatalogService/CatalogService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CatalogDb\CatalogDb.csproj" />
<ProjectReference Include="..\CatalogModel\CatalogModel.csproj" />
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion playground/eShopLite/CatalogService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CatalogDb;
using CatalogModel;
using CatalogService;

var builder = WebApplication.CreateBuilder(args);
Expand Down
9 changes: 0 additions & 9 deletions playground/eShopLite/azure.yaml

This file was deleted.

Loading

0 comments on commit c7bb15f

Please sign in to comment.