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
d42c34c1
Commit
d42c34c1
authored
Jul 24, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update samples.
parent
e31a206b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
68 deletions
+37
-68
CAP.sln
CAP.sln
+8
-1
ValuesController.cs
samples/Sample.Kafka/Controllers/ValuesController.cs
+16
-23
Program.cs
samples/Sample.Kafka/Program.cs
+9
-1
Sample.Kafka.SqlServer.csproj
samples/Sample.Kafka/Sample.Kafka.SqlServer.csproj
+3
-7
Startup.cs
samples/Sample.Kafka/Startup.cs
+1
-18
appsettings.Development.json
samples/Sample.Kafka/appsettings.Development.json
+0
-10
appsettings.json
samples/Sample.Kafka/appsettings.json
+0
-8
No files found.
CAP.sln
View file @
d42c34c1
...
...
@@ -35,7 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP", "src\DotNe
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3A6B6931-A123-477A-9469-8B468B5385AF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka
", "samples\Sample.Kafka\Sample.Kafka
.csproj", "{2F095ED9-5BC9-4512-9013-A47685FB2508}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka
.SqlServer", "samples\Sample.Kafka\Sample.Kafka.SqlServer
.csproj", "{2F095ED9-5BC9-4512-9013-A47685FB2508}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.Kafka", "src\DotNetCore.CAP.Kafka\DotNetCore.CAP.Kafka.csproj", "{C42CDE33-0878-4BA0-96F2-4CB7C8FDEAAD}"
EndProject
...
...
@@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCore.CAP.MySql", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCore.CAP.MySql.Test", "test\DotNetCore.CAP.MySql.Test\DotNetCore.CAP.MySql.Test.csproj", "{80A84F62-1558-427B-BA74-B47AA8A665B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.RabbitMQ.MySql", "samples\Sample.RabbitMQ.MySql\Sample.RabbitMQ.MySql.csproj", "{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -104,6 +106,10 @@ Global
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.Build.0 = Release|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -119,5 +125,6 @@ Global
{DA00FA38-C4B9-4F55-8756-D480FBC1084F} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0}
{FA15685A-778A-4D2A-A2FE-27FAD2FFA65B} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
{80A84F62-1558-427B-BA74-B47AA8A665B5} = {C09CDAB0-6DD4-46E9-B7F3-3EF2A4741EA0}
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873} = {3A6B6931-A123-477A-9469-8B468B5385AF}
EndGlobalSection
EndGlobal
samples/Sample.Kafka/Controllers/ValuesController.cs
View file @
d42c34c1
using
System
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Mvc
;
namespace
Sample.Kafka.Controllers
...
...
@@ -9,46 +9,39 @@ namespace Sample.Kafka.Controllers
[
Route
(
"api/[controller]"
)]
public
class
ValuesController
:
Controller
,
ICapSubscribe
{
private
readonly
ICapPublisher
_
producer
;
private
readonly
AppDbContext
_dbContext
;
private
readonly
ICapPublisher
_
capBus
;
private
readonly
AppDbContext
_dbContext
;
public
ValuesController
(
ICapPublisher
producer
,
AppDbContext
dbContext
)
{
_
producer
=
producer
;
_
capBus
=
producer
;
_dbContext
=
dbContext
;
}
[
Route
(
"
/
"
)]
public
IActionResult
Index
()
[
Route
(
"
~/publish
"
)]
public
IActionResult
PublishMessage
()
{
_capBus
.
Publish
(
"sample.rabbitmq.mysql"
,
""
);
return
Ok
();
}
public
string
ServerPath
=>
((
IHostingEnvironment
)
HttpContext
.
RequestServices
.
GetService
(
typeof
(
IHostingEnvironment
))).
ContentRootPath
;
[
CapSubscribe
(
"zzwl.topic.finace.callBack"
,
Group
=
"test
"
)]
public
void
KafkaTest
(
Person
person
)
[
Route
(
"~/publishWithTrans
"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
(
)
{
Console
.
WriteLine
(
DateTime
.
Now
);
}
[
Route
(
"~/send"
)]
public
async
Task
<
IActionResult
>
SendTopic
()
{
using
(
var
trans
=
_dbContext
.
Database
.
BeginTransaction
())
using
(
var
trans
=
await
_dbContext
.
Database
.
BeginTransactionAsync
())
{
await
_producer
.
PublishAsync
(
"zzwl.topic.finace.callBack"
,
""
);
await
_capBus
.
PublishAsync
(
"sample.rabbitmq.mysql"
,
""
);
trans
.
Commit
();
}
return
Ok
();
}
public
class
Person
[
NonAction
]
[
CapSubscribe
(
"sample.kafka.sqlserver"
,
Group
=
"test"
)]
public
void
KafkaTest
()
{
public
string
Name
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
Console
.
WriteLine
(
"[sample.kafka.sqlserver] message received"
);
Debug
.
WriteLine
(
"[sample.kafka.sqlserver] message received"
);
}
}
}
\ No newline at end of file
samples/Sample.Kafka/Program.cs
View file @
d42c34c1
using
System.IO
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Configuration
;
namespace
Sample.Kafka
{
public
class
Program
{
public
static
void
Main
(
string
[]
args
)
{
public
static
void
Main
(
string
[]
args
)
{
var
config
=
new
ConfigurationBuilder
()
.
AddCommandLine
(
args
)
.
AddEnvironmentVariables
(
"ASPNETCORE_"
)
.
Build
();
var
host
=
new
WebHostBuilder
()
.
UseConfiguration
(
config
)
.
UseKestrel
()
.
UseContentRoot
(
Directory
.
GetCurrentDirectory
())
.
UseIISIntegration
()
...
...
samples/Sample.Kafka/Sample.Kafka.csproj
→
samples/Sample.Kafka/Sample.Kafka.
SqlServer.
csproj
View file @
d42c34c1
...
...
@@ -2,14 +2,9 @@
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>Sample.Kafka.SqlServer</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Compile Remove="wwwroot\**" />
<Content Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
<None Remove="wwwroot\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
...
...
@@ -17,6 +12,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
...
...
samples/Sample.Kafka/Startup.cs
View file @
d42c34c1
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
...
...
@@ -8,19 +7,6 @@ namespace Sample.Kafka
{
public
class
Startup
{
public
Startup
(
IHostingEnvironment
env
)
{
var
builder
=
new
ConfigurationBuilder
()
.
SetBasePath
(
env
.
ContentRootPath
)
.
AddJsonFile
(
"appsettings.json"
,
optional
:
false
,
reloadOnChange
:
true
)
.
AddJsonFile
(
$"appsettings.
{
env
.
EnvironmentName
}
.json"
,
optional
:
true
)
.
AddEnvironmentVariables
();
Configuration
=
builder
.
Build
();
}
public
IConfigurationRoot
Configuration
{
get
;
}
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
services
.
AddDbContext
<
AppDbContext
>();
...
...
@@ -28,18 +14,15 @@ namespace Sample.Kafka
services
.
AddCap
(
x
=>
{
x
.
UseEntityFramework
<
AppDbContext
>();
//x.UseSqlServer("Server=DESKTOP-M9R8T31;Initial Catalog=Test;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True");
x
.
UseKafka
(
"localhost:9092"
);
});
// Add framework services.
services
.
AddMvc
();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure
(
IApplicationBuilder
app
,
IHostingEnvironment
env
,
ILoggerFactory
loggerFactory
)
{
loggerFactory
.
AddConsole
(
Configuration
.
GetSection
(
"Logging"
)
);
loggerFactory
.
AddConsole
();
loggerFactory
.
AddDebug
();
app
.
UseMvc
();
...
...
samples/Sample.Kafka/appsettings.Development.json
deleted
100644 → 0
View file @
e31a206b
{
"Logging"
:
{
"IncludeScopes"
:
false
,
"LogLevel"
:
{
"Default"
:
"Debug"
,
"System"
:
"Information"
,
"Microsoft"
:
"Information"
}
}
}
samples/Sample.Kafka/appsettings.json
deleted
100644 → 0
View file @
e31a206b
{
"Logging"
:
{
"IncludeScopes"
:
false
,
"LogLevel"
:
{
"Default"
:
"Warning"
}
}
}
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