Skip to content

Commit

Permalink
Add CAP for EventBus
Browse files Browse the repository at this point in the history
Fixe  .AsNoTracking()
  • Loading branch information
maikebing committed Sep 3, 2020
1 parent 203dad8 commit 11cf8b4
Show file tree
Hide file tree
Showing 28 changed files with 736 additions and 388 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,4 @@ ASALocalRun/
/IoTSharp/healthchecksdb-shm
/IoTSharp/DiskQuue.iotsharp
/IoTSharp/DiskQuue-log.iotsharp
/zk-single-kafka-single
17 changes: 17 additions & 0 deletions IoTSharp/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ public enum TelemetryStorage
Sharding,
Taos
}
[JsonConverter(typeof(StringEnumConverter))]
public enum EventBusStore
{
PostgreSql,
MongoDB,
InMemory
}
[JsonConverter(typeof(StringEnumConverter))]
public enum EventBusMQ
{
RabbitMQ,
Kafka,
InMemory
}

public class AppSettings
{
public string JwtKey { get; set; }
Expand All @@ -40,6 +55,8 @@ public class AppSettings
public TelemetryStorage TelemetryStorage { get; set; } = TelemetryStorage.SingleTable;

public ShardingSetting Sharding { get; set; } = new ShardingSetting();
public EventBusStore EventBusStore { get; set; } = EventBusStore.InMemory;
public EventBusMQ EventBusMQ { get; set; } = EventBusMQ.InMemory;
}
public class ShardingSetting
{
Expand Down
18 changes: 9 additions & 9 deletions IoTSharp/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, ICon
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TelemetryData>().HasKey(c => new { c.DeviceId, c.KeyName, c.DateTime });
modelBuilder.Entity<TelemetryData>().HasIndex(c => new { c.DeviceId, c.KeyName, c.DateTime });
modelBuilder.Entity<DataStorage>().HasKey(c => new { c.Catalog, c.DeviceId, c.KeyName, c.DateTime });
modelBuilder.Entity<DataStorage>().HasIndex(c => c.Catalog);
modelBuilder.Entity<TelemetryData>().HasKey(c => new { c.DeviceId, c.KeyName, c.DateTime });
modelBuilder.Entity<TelemetryData>().HasIndex(c => new { c.DeviceId, c.KeyName, c.DateTime });
modelBuilder.Entity<DataStorage>().HasKey(c => new { c.Catalog, c.DeviceId, c.KeyName });
modelBuilder.Entity<DataStorage>().HasIndex(c => c.Catalog);
modelBuilder.Entity<DataStorage>().HasIndex(c => new { c.Catalog, c.DeviceId });
modelBuilder.Entity<DataStorage>().HasIndex(c => new {c.Catalog,c.DeviceId, c.KeyName } );


modelBuilder.Entity<DataStorage>()
.HasDiscriminator<DataCatalog>(nameof(Data.DataStorage.Catalog))
.HasValue<DataStorage>(DataCatalog.None)
Expand Down Expand Up @@ -61,7 +61,7 @@ private void ForNpgsql(ModelBuilder modelBuilder)
modelBuilder.Entity<AttributeLatest>()
.Property(b => b.Value_XML)
.HasColumnType("xml");


modelBuilder.Entity<TelemetryLatest>()
.Property(b => b.Value_Json)
Expand All @@ -79,7 +79,7 @@ private void ForNpgsql(ModelBuilder modelBuilder)
.Property(b => b.ActionResult)
.HasColumnType("jsonb");
}

public DbSet<Tenant> Tenant { get; set; }
public DbSet<Customer> Customer { get; set; }
public DbSet<Relationship> Relationship { get; set; }
Expand All @@ -95,6 +95,6 @@ private void ForNpgsql(ModelBuilder modelBuilder)
public DbSet<RetainedMessage> RetainedMessage { get; set; }

public DbSet<AuthorizedKey> AuthorizedKeys { get; set; }

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace IoTSharp.Migrations
{
public partial class RemoveDataStorageDateTimeKey : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_DataStorage",
table: "DataStorage");

migrationBuilder.DropIndex(
name: "IX_DataStorage_Catalog_DeviceId_KeyName",
table: "DataStorage");

migrationBuilder.DropIndex(
name: "IX_DataStorage_Catalog_DeviceId_KeyName_DateTime",
table: "DataStorage");

migrationBuilder.AlterColumn<DateTime>(
name: "Value_DateTime",
table: "DataStorage",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");

migrationBuilder.AlterColumn<DateTime>(
name: "DateTime",
table: "DataStorage",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");

migrationBuilder.AddPrimaryKey(
name: "PK_DataStorage",
table: "DataStorage",
columns: new[] { "Catalog", "DeviceId", "KeyName" });

migrationBuilder.CreateTable(
name: "TelemetryData",
columns: table => new
{
DeviceId = table.Column<Guid>(nullable: false),
KeyName = table.Column<string>(nullable: false),
DateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DataSide = table.Column<int>(nullable: false),
Type = table.Column<int>(nullable: false),
Value_Boolean = table.Column<bool>(nullable: false),
Value_String = table.Column<string>(nullable: true),
Value_Long = table.Column<long>(nullable: false),
Value_DateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Value_Double = table.Column<double>(nullable: false),
Value_Json = table.Column<string>(type: "jsonb", nullable: true),
Value_XML = table.Column<string>(type: "xml", nullable: true),
Value_Binary = table.Column<byte[]>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TelemetryData", x => new { x.DeviceId, x.KeyName, x.DateTime });
});

migrationBuilder.CreateIndex(
name: "IX_TelemetryData_DeviceId_KeyName_DateTime",
table: "TelemetryData",
columns: new[] { "DeviceId", "KeyName", "DateTime" });
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TelemetryData");

migrationBuilder.DropPrimaryKey(
name: "PK_DataStorage",
table: "DataStorage");

migrationBuilder.AlterColumn<DateTime>(
name: "Value_DateTime",
table: "DataStorage",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");

migrationBuilder.AlterColumn<DateTime>(
name: "DateTime",
table: "DataStorage",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");

migrationBuilder.AddPrimaryKey(
name: "PK_DataStorage",
table: "DataStorage",
columns: new[] { "Catalog", "DeviceId", "KeyName", "DateTime" });

migrationBuilder.CreateIndex(
name: "IX_DataStorage_Catalog_DeviceId_KeyName",
table: "DataStorage",
columns: new[] { "Catalog", "DeviceId", "KeyName" });

migrationBuilder.CreateIndex(
name: "IX_DataStorage_Catalog_DeviceId_KeyName_DateTime",
table: "DataStorage",
columns: new[] { "Catalog", "DeviceId", "KeyName", "DateTime" });
}
}
}
78 changes: 54 additions & 24 deletions IoTSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.5")
.HasAnnotation("ProductVersion", "3.1.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("IoTSharp.Data.AuditLog", b =>
Expand Down Expand Up @@ -148,12 +148,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("KeyName")
.HasColumnType("text");

b.Property<DateTime>("DateTime")
.HasColumnType("timestamp without time zone");

b.Property<int>("DataSide")
.HasColumnType("integer");

b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone");

b.Property<int>("Type")
.HasColumnType("integer");

Expand All @@ -164,7 +164,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("boolean");

b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp without time zone");
.HasColumnType("timestamp with time zone");

b.Property<double>("Value_Double")
.HasColumnType("double precision");
Expand All @@ -181,16 +181,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Value_XML")
.HasColumnType("xml");

b.HasKey("Catalog", "DeviceId", "KeyName", "DateTime");
b.HasKey("Catalog", "DeviceId", "KeyName");

b.HasIndex("Catalog");

b.HasIndex("Catalog", "DeviceId");

b.HasIndex("Catalog", "DeviceId", "KeyName");

b.HasIndex("Catalog", "DeviceId", "KeyName", "DateTime");

b.ToTable("DataStorage");

b.HasDiscriminator<int>("Catalog").HasValue(0);
Expand Down Expand Up @@ -309,6 +305,54 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("RetainedMessage");
});

modelBuilder.Entity("IoTSharp.Data.TelemetryData", b =>
{
b.Property<Guid>("DeviceId")
.HasColumnType("uuid");

b.Property<string>("KeyName")
.HasColumnType("text");

b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone");

b.Property<int>("DataSide")
.HasColumnType("integer");

b.Property<int>("Type")
.HasColumnType("integer");

b.Property<byte[]>("Value_Binary")
.HasColumnType("bytea");

b.Property<bool>("Value_Boolean")
.HasColumnType("boolean");

b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp with time zone");

b.Property<double>("Value_Double")
.HasColumnType("double precision");

b.Property<string>("Value_Json")
.HasColumnType("jsonb");

b.Property<long>("Value_Long")
.HasColumnType("bigint");

b.Property<string>("Value_String")
.HasColumnType("text");

b.Property<string>("Value_XML")
.HasColumnType("xml");

b.HasKey("DeviceId", "KeyName", "DateTime");

b.HasIndex("DeviceId", "KeyName", "DateTime");

b.ToTable("TelemetryData");
});

modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Property<Guid>("Id")
Expand Down Expand Up @@ -541,27 +585,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("AspNetUserTokens");
});

modelBuilder.Entity("IoTSharp.Data.AttributeData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");

b.HasDiscriminator().HasValue(1);
});

modelBuilder.Entity("IoTSharp.Data.AttributeLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");

b.HasDiscriminator().HasValue(2);
});

modelBuilder.Entity("IoTSharp.Data.TelemetryData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");

b.HasDiscriminator().HasValue(3);
});

modelBuilder.Entity("IoTSharp.Data.TelemetryLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
Expand Down
Loading

0 comments on commit 11cf8b4

Please sign in to comment.