Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
aedf82cb
Commit
aedf82cb
authored
Dec 05, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sqlsever samples
parent
2f4b65b4
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
319 additions
and
0 deletions
+319
-0
CAP.sln
CAP.sln
+7
-0
AppDbContext.cs
samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs
+40
-0
ValuesController.cs
...Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs
+76
-0
20191205032949_FirstMigration.Designer.cs
...rver/Migrations/20191205032949_FirstMigration.Designer.cs
+40
-0
20191205032949_FirstMigration.cs
...tMQ.SqlServer/Migrations/20191205032949_FirstMigration.cs
+29
-0
AppDbContextModelSnapshot.cs
...abbitMQ.SqlServer/Migrations/AppDbContextModelSnapshot.cs
+38
-0
Program.cs
samples/Sample.RabbitMQ.SqlServer/Program.cs
+20
-0
Sample.RabbitMQ.SqlServer.csproj
...ample.RabbitMQ.SqlServer/Sample.RabbitMQ.SqlServer.csproj
+22
-0
Startup.cs
samples/Sample.RabbitMQ.SqlServer/Startup.cs
+39
-0
appsettings.json
samples/Sample.RabbitMQ.SqlServer/appsettings.json
+8
-0
No files found.
CAP.sln
View file @
aedf82cb
...
...
@@ -70,6 +70,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.Dashboard",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka.InMemory", "samples\Sample.Kafka.InMemory\Sample.Kafka.InMemory.csproj", "{1B0371D6-36A4-4C78-A727-8ED732FDBA1D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RabbitMQ.SqlServer", "samples\Sample.RabbitMQ.SqlServer\Sample.RabbitMQ.SqlServer.csproj", "{F6C5C676-AF05-46D5-A45D-442137B31898}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -151,6 +153,10 @@ Global
{1B0371D6-36A4-4C78-A727-8ED732FDBA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B0371D6-36A4-4C78-A727-8ED732FDBA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B0371D6-36A4-4C78-A727-8ED732FDBA1D}.Release|Any CPU.Build.0 = Release|Any CPU
{F6C5C676-AF05-46D5-A45D-442137B31898}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6C5C676-AF05-46D5-A45D-442137B31898}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6C5C676-AF05-46D5-A45D-442137B31898}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6C5C676-AF05-46D5-A45D-442137B31898}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -175,6 +181,7 @@ Global
{58B6E829-C6C8-457C-9DD0-C600650254DF} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
{56FB261C-67AF-4715-9A46-4FA4FAB91B2C} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
{1B0371D6-36A4-4C78-A727-8ED732FDBA1D} = {3A6B6931-A123-477A-9469-8B468B5385AF}
{F6C5C676-AF05-46D5-A45D-442137B31898} = {3A6B6931-A123-477A-9469-8B468B5385AF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E70565D-94CF-40B4-BFE1-AC18D5F736AB}
...
...
samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs
0 → 100644
View file @
aedf82cb
using
Microsoft.EntityFrameworkCore
;
namespace
Sample.RabbitMQ.SqlServer
{
public
class
Person
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
override
string
ToString
()
{
return
$"Name:
{
Name
}
, Id:
{
Id
}
"
;
}
}
public
class
Person2
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
override
string
ToString
()
{
return
$"Name:
{
Name
}
, Id:
{
Id
}
"
;
}
}
public
class
AppDbContext
:
DbContext
{
public
const
string
ConnectionString
=
"Server=192.168.2.120;Database=captest;User Id=sa;Password=P@ssw0rd;"
;
public
DbSet
<
Person
>
Persons
{
get
;
set
;
}
protected
override
void
OnConfiguring
(
DbContextOptionsBuilder
optionsBuilder
)
{
optionsBuilder
.
UseSqlServer
(
ConnectionString
);
}
}
}
samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs
0 → 100644
View file @
aedf82cb
using
System
;
using
System.Data
;
using
System.Threading.Tasks
;
using
Dapper
;
using
DotNetCore.CAP
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Data.SqlClient
;
namespace
Sample.RabbitMQ.SqlServer.Controllers
{
[
Route
(
"api/[controller]"
)]
public
class
ValuesController
:
Controller
{
private
readonly
ICapPublisher
_capBus
;
public
ValuesController
(
ICapPublisher
capPublisher
)
{
_capBus
=
capPublisher
;
}
[
Route
(
"~/without/transaction"
)]
public
async
Task
<
IActionResult
>
WithoutTransaction
()
{
await
_capBus
.
PublishAsync
(
"sample.rabbitmq.mysql"
,
new
Person
()
{
Id
=
123
,
Name
=
"Bar"
});
return
Ok
();
}
[
Route
(
"~/adonet/transaction"
)]
public
IActionResult
AdonetWithTransaction
()
{
using
(
var
connection
=
new
SqlConnection
(
AppDbContext
.
ConnectionString
))
{
using
(
var
transaction
=
connection
.
BeginTransaction
(
_capBus
,
true
))
{
//your business code
connection
.
Execute
(
"insert into test(name) values('test')"
,
transaction
:
transaction
);
_capBus
.
Publish
(
"sample.rabbitmq.mysql"
,
DateTime
.
Now
);
}
}
return
Ok
();
}
[
Route
(
"~/ef/transaction"
)]
public
IActionResult
EntityFrameworkWithTransaction
([
FromServices
]
AppDbContext
dbContext
)
{
using
(
dbContext
.
Database
.
BeginTransaction
(
_capBus
,
autoCommit
:
true
))
{
dbContext
.
Persons
.
Add
(
new
Person
()
{
Name
=
"ef.transaction"
});
_capBus
.
Publish
(
"sample.rabbitmq.mysql"
,
DateTime
.
Now
);
}
return
Ok
();
}
[
NonAction
]
[
CapSubscribe
(
"sample.rabbitmq.mysql"
)]
public
void
Subscriber
(
DateTime
p
)
{
Console
.
WriteLine
(
$@"
{
DateTime
.
Now
}
Subscriber invoked, Info:
{
p
}
"
);
}
[
NonAction
]
[
CapSubscribe
(
"sample.rabbitmq.mysql"
,
Group
=
"group.test2"
)]
public
void
Subscriber2
(
DateTime
p
,
[
FromCap
]
CapHeader
header
)
{
Console
.
WriteLine
(
$@"
{
DateTime
.
Now
}
Subscriber invoked, Info:
{
p
}
"
);
}
}
}
samples/Sample.RabbitMQ.SqlServer/Migrations/20191205032949_FirstMigration.Designer.cs
0 → 100644
View file @
aedf82cb
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Sample.RabbitMQ.SqlServer
;
namespace
Sample.RabbitMQ.SqlServer.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20191205032949_FirstMigration"
)]
partial
class
FirstMigration
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"3.0.0"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"Sample.RabbitMQ.SqlServer.Person"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"int"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"nvarchar(max)"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Persons"
);
});
#pragma warning restore 612, 618
}
}
}
samples/Sample.RabbitMQ.SqlServer/Migrations/20191205032949_FirstMigration.cs
0 → 100644
View file @
aedf82cb
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
Sample.RabbitMQ.SqlServer.Migrations
{
public
partial
class
FirstMigration
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"Persons"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
nullable
:
false
)
.
Annotation
(
"SqlServer:Identity"
,
"1, 1"
),
Name
=
table
.
Column
<
string
>(
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Persons"
,
x
=>
x
.
Id
);
});
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"Persons"
);
}
}
}
samples/Sample.RabbitMQ.SqlServer/Migrations/AppDbContextModelSnapshot.cs
0 → 100644
View file @
aedf82cb
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Sample.RabbitMQ.SqlServer
;
namespace
Sample.RabbitMQ.SqlServer.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
partial
class
AppDbContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"3.0.0"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"Sample.RabbitMQ.SqlServer.Person"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"int"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"nvarchar(max)"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Persons"
);
});
#pragma warning restore 612, 618
}
}
}
samples/Sample.RabbitMQ.SqlServer/Program.cs
0 → 100644
View file @
aedf82cb
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Hosting
;
namespace
Sample.RabbitMQ.SqlServer
{
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
<
Startup
>();
});
}
}
samples/Sample.RabbitMQ.SqlServer/Sample.RabbitMQ.SqlServer.csproj
0 → 100644
View file @
aedf82cb
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotNetCore.CAP.Dashboard\DotNetCore.CAP.Dashboard.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.RabbitMQ\DotNetCore.CAP.RabbitMQ.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.SqlServer\DotNetCore.CAP.SqlServer.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup>
</Project>
samples/Sample.RabbitMQ.SqlServer/Startup.cs
0 → 100644
View file @
aedf82cb
using
System
;
using
DotNetCore.CAP.Messages
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
Sample.RabbitMQ.SqlServer
{
public
class
Startup
{
public
void
ConfigureServices
(
IServiceCollection
services
)
{
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddCap
(
x
=>
{
x
.
UseEntityFramework
<
AppDbContext
>();
x
.
UseRabbitMQ
(
"192.168.2.120"
);
x
.
UseDashboard
();
x
.
FailedRetryCount
=
5
;
x
.
FailedThresholdCallback
=
(
type
,
msg
)
=>
{
Console
.
WriteLine
(
$@"A message of type
{
type
}
failed after executing
{
x
.
FailedRetryCount
}
several times, requiring manual troubleshooting. Message name:
{
msg
.
GetName
()}
"
);
};
});
services
.
AddControllers
();
}
public
void
Configure
(
IApplicationBuilder
app
)
{
app
.
UseRouting
();
app
.
UseEndpoints
(
endpoints
=>
{
endpoints
.
MapControllers
();
});
}
}
}
samples/Sample.RabbitMQ.SqlServer/appsettings.json
0 → 100644
View file @
aedf82cb
{
"Logging"
:
{
"IncludeScopes"
:
false
,
"LogLevel"
:
{
"Default"
:
"Error"
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment