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
768a62c3
Commit
768a62c3
authored
Jul 15, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
3ec25195
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
93 additions
and
30 deletions
+93
-30
AppDbContext.cs
samples/Sample.Kafka/AppDbContext.cs
+2
-1
ValuesController.cs
samples/Sample.Kafka/Controllers/ValuesController.cs
+8
-5
Sample.Kafka.csproj
samples/Sample.Kafka/Sample.Kafka.csproj
+0
-1
Startup.cs
samples/Sample.Kafka/Startup.cs
+5
-4
CAP.BuilderExtensions.cs
...tNetCore.CAP.EntityFrameworkCore/CAP.BuilderExtensions.cs
+3
-1
CAP.EFOptions.cs
src/DotNetCore.CAP.EntityFrameworkCore/CAP.EFOptions.cs
+1
-1
CapDbContext.cs
src/DotNetCore.CAP.EntityFrameworkCore/CapDbContext.cs
+3
-2
CapPublisher.cs
src/DotNetCore.CAP.EntityFrameworkCore/CapPublisher.cs
+55
-0
EFStorageConnection.cs
...DotNetCore.CAP.EntityFrameworkCore/EFStorageConnection.cs
+1
-1
CAP.ServiceCollectionExtensions.cs
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
+2
-2
DotNetCore.CAP.csproj
src/DotNetCore.CAP/DotNetCore.CAP.csproj
+1
-1
IDispatcher.Default.cs
src/DotNetCore.CAP/Processor/IDispatcher.Default.cs
+3
-3
IDispatcher.cs
src/DotNetCore.CAP/Processor/IDispatcher.cs
+1
-1
IProcessingServer.Cap.cs
src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs
+6
-5
IProcessor.PublishQueuer.cs
src/DotNetCore.CAP/Processor/IProcessor.PublishQueuer.cs
+1
-1
IProcessor.SubscribeQueuer.cs
src/DotNetCore.CAP/Processor/IProcessor.SubscribeQueuer.cs
+1
-1
No files found.
samples/Sample.Kafka/AppDbContext.cs
View file @
768a62c3
...
...
@@ -13,7 +13,8 @@ namespace Sample.Kafka
{
protected
override
void
OnConfiguring
(
DbContextOptionsBuilder
optionsBuilder
)
{
optionsBuilder
.
UseSqlServer
(
"Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True"
);
//optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True");
optionsBuilder
.
UseSqlServer
(
"Server=DESKTOP-M9R8T31;Initial Catalog=Test;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
);
}
}
}
samples/Sample.Kafka/Controllers/ValuesController.cs
View file @
768a62c3
using
System
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP
;
using
DotNetCore.CAP.
Kafka
;
using
DotNetCore.CAP.
RabbitMQ
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Mvc
;
using
Dapper
;
namespace
Sample.Kafka.Controllers
{
...
...
@@ -11,10 +12,12 @@ namespace Sample.Kafka.Controllers
public
class
ValuesController
:
Controller
,
ICapSubscribe
{
private
readonly
ICapPublisher
_producer
;
private
readonly
AppDbContext
_dbContext
;
public
ValuesController
(
ICapPublisher
producer
)
public
ValuesController
(
ICapPublisher
producer
,
AppDbContext
dbContext
)
{
_producer
=
producer
;
_dbContext
=
dbContext
;
}
[
Route
(
"/"
)]
...
...
@@ -33,11 +36,11 @@ namespace Sample.Kafka.Controllers
}
[
Route
(
"~/send"
)]
public
async
Task
<
IActionResult
>
SendTopic
(
[
FromServices
]
AppDbContext
dbContext
)
public
async
Task
<
IActionResult
>
SendTopic
()
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
using
(
var
trans
=
_
dbContext
.
Database
.
BeginTransaction
())
{
await
_producer
.
PublishAsync
(
"zzwl.topic.finace.callBack"
,
new
Person
{
Name
=
"Test"
,
Age
=
11
}
);
await
_producer
.
PublishAsync
(
"zzwl.topic.finace.callBack"
,
""
);
trans
.
Commit
();
}
...
...
samples/Sample.Kafka/Sample.Kafka.csproj
View file @
768a62c3
...
...
@@ -25,7 +25,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotNetCore.CAP.EntityFrameworkCore\DotNetCore.CAP.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.Kafka\DotNetCore.CAP.Kafka.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP.RabbitMQ\DotNetCore.CAP.RabbitMQ.csproj" />
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup>
...
...
samples/Sample.Kafka/Startup.cs
View file @
768a62c3
...
...
@@ -28,13 +28,14 @@ namespace Sample.Kafka
services
.
AddCap
()
.
AddEntityFrameworkStores
<
AppDbContext
>(
x
=>
{
x
.
ConnectionString
=
"Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True"
;
//x.ConnectionString = "Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True";
x
.
ConnectionString
=
"Server=DESKTOP-M9R8T31;Initial Catalog=Test;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
;
})
.
AddRabbitMQ
(
x
=>
{
x
.
HostName
=
"
192.168.2.206
"
;
x
.
UserName
=
"admin"
;
x
.
Password
=
"123123"
;
x
.
HostName
=
"
localhost
"
;
//
x.UserName = "admin";
//
x.Password = "123123";
});
//.AddKafka(x => x.Servers = "");
...
...
src/DotNetCore.CAP.EntityFrameworkCore/CAP.BuilderExtensions.cs
View file @
768a62c3
...
...
@@ -23,8 +23,10 @@ namespace Microsoft.Extensions.DependencyInjection
builder
.
Services
.
AddSingleton
<
IStorage
,
EFStorage
>();
builder
.
Services
.
AddScoped
<
IStorageConnection
,
EFStorageConnection
>();
builder
.
Services
.
Add
Transient
<
IAdditionalProcessor
,
DefaultAdditionalProcesso
r
>();
builder
.
Services
.
Add
Scoped
<
ICapPublisher
,
CapPublishe
r
>();
builder
.
Services
.
AddTransient
<
IAdditionalProcessor
,
DefaultAdditionalProcessor
>();
builder
.
Services
.
Configure
(
actionOptions
);
var
sqlServerOptions
=
new
SqlServerOptions
();
...
...
src/DotNetCore.CAP.EntityFrameworkCore/CAP.EFOptions.cs
View file @
768a62c3
...
...
@@ -12,7 +12,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
public
EFOptions
()
{
ConnectionString
=
"Server=DESKTOP-M9R8T31;Initial Catalog=
WebApp1
;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
;
ConnectionString
=
"Server=DESKTOP-M9R8T31;Initial Catalog=
Test
;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
;
}
/// <summary>
...
...
src/DotNetCore.CAP.EntityFrameworkCore/CapDbContext.cs
View file @
768a62c3
...
...
@@ -47,7 +47,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// </param>
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
//
_sqlServerOptions = new SqlServerOptions();
_sqlServerOptions
=
new
SqlServerOptions
();
modelBuilder
.
HasDefaultSchema
(
_sqlServerOptions
.
Schema
);
modelBuilder
.
Entity
<
CapSentMessage
>(
b
=>
...
...
@@ -67,7 +67,8 @@ namespace DotNetCore.CAP.EntityFrameworkCore
protected
override
void
OnConfiguring
(
DbContextOptionsBuilder
optionsBuilder
)
{
// optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True");
// optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True");
optionsBuilder
.
UseSqlServer
(
"Server=DESKTOP-M9R8T31;Initial Catalog=Test;User Id=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
);
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.EntityFrameworkCore/CapPublisher.cs
0 → 100644
View file @
768a62c3
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Dapper
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Processor
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Storage
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
DotNetCore.CAP.EntityFrameworkCore
{
public
class
CapPublisher
:
ICapPublisher
{
private
readonly
SqlServerOptions
_options
;
private
readonly
IServiceProvider
_provider
;
private
readonly
DbContext
_dbContext
;
public
CapPublisher
(
SqlServerOptions
options
,
IServiceProvider
provider
)
{
_options
=
options
;
_provider
=
provider
;
_dbContext
=
(
DbContext
)
_provider
.
GetService
(
_options
.
DbContextType
);
}
public
async
Task
PublishAsync
(
string
topic
,
string
content
)
{
var
connection
=
_dbContext
.
Database
.
GetDbConnection
();
var
transaction
=
_dbContext
.
Database
.
CurrentTransaction
;
transaction
=
transaction
??
await
_dbContext
.
Database
.
BeginTransactionAsync
(
IsolationLevel
.
ReadCommitted
);
var
dbTransaction
=
transaction
.
GetDbTransaction
();
var
message
=
new
CapSentMessage
{
KeyName
=
topic
,
Content
=
content
,
StatusName
=
StatusName
.
Scheduled
};
var
sql
=
"INSERT INTO [cap].[CapSentMessages] ([Id],[Added],[Content],[KeyName],[ExpiresAt],[Retries],[StatusName])VALUES(@Id,@Added,@Content,@KeyName,@ExpiresAt,@Retries,@StatusName)"
;
await
connection
.
ExecuteAsync
(
sql
,
message
,
transaction
:
dbTransaction
);
PublishQueuer
.
PulseEvent
.
Set
();
}
public
Task
PublishAsync
<
T
>(
string
topic
,
T
contentObj
)
{
throw
new
NotImplementedException
();
}
}
}
src/DotNetCore.CAP.EntityFrameworkCore/EFStorageConnection.cs
View file @
768a62c3
...
...
@@ -89,7 +89,7 @@ WHERE StatusName = '{StatusName.Scheduled}'";
var
sql
=
$@"
SELECT TOP (1) *
FROM [
{
_options
.
Schema
}
].[
{
nameof
(
CapDbContext
.
CapReceivedMessages
)}
] WITH (readpast)
WHERE Stat
e
Name = '
{
StatusName
.
Enqueued
}
'"
;
WHERE Stat
us
Name = '
{
StatusName
.
Enqueued
}
'"
;
var
connection
=
_context
.
GetDbConnection
();
var
message
=
(
await
connection
.
QueryAsync
<
CapReceivedMessage
>(
sql
)).
FirstOrDefault
();
...
...
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
View file @
768a62c3
...
...
@@ -55,14 +55,14 @@ namespace Microsoft.Extensions.DependencyInjection
//Processors
services
.
AddTransient
<
PublishQueuer
>();
services
.
AddTransient
<
SubscribeQueuer
>();
services
.
AddTransient
<
I
MessageProcessor
,
DefaultMessageProcesso
r
>();
services
.
AddTransient
<
I
Dispatcher
,
DefaultDispatche
r
>();
//Executors
services
.
AddSingleton
<
IQueueExecutorFactory
,
QueueExecutorFactory
>();
services
.
AddSingleton
<
IQueueExecutor
,
SubscibeQueueExecutor
>();
services
.
TryAddScoped
<
ICapPublisher
,
DefaultCapPublisher
>();
//
services.TryAddScoped<ICapPublisher, DefaultCapPublisher>();
return
new
CapBuilder
(
services
);
}
...
...
src/DotNetCore.CAP/DotNetCore.CAP.csproj
View file @
768a62c3
...
...
@@ -15,7 +15,7 @@
<ItemGroup>
<None Include="IQueueExecutor.Subscibe.cs" />
<None Include="Processor\I
Processor.Message
.Default.cs" />
<None Include="Processor\I
Dispatcher
.Default.cs" />
</ItemGroup>
<ItemGroup>
...
...
src/DotNetCore.CAP/Processor/I
Processor.Message
.Default.cs
→
src/DotNetCore.CAP/Processor/I
Dispatcher
.Default.cs
View file @
768a62c3
...
...
@@ -8,7 +8,7 @@ using Microsoft.Extensions.Options;
namespace
DotNetCore.CAP.Processor
{
public
class
Default
MessageProcessor
:
IMessageProcesso
r
public
class
Default
Dispatcher
:
IDispatche
r
{
private
readonly
IQueueExecutorFactory
_queueExecutorFactory
;
private
readonly
IServiceProvider
_provider
;
...
...
@@ -19,11 +19,11 @@ namespace DotNetCore.CAP.Processor
internal
static
readonly
AutoResetEvent
PulseEvent
=
new
AutoResetEvent
(
true
);
public
Default
MessageProcesso
r
(
public
Default
Dispatche
r
(
IServiceProvider
provider
,
IQueueExecutorFactory
queueExecutorFactory
,
IOptions
<
CapOptions
>
capOptions
,
ILogger
<
Default
MessageProcesso
r
>
logger
)
ILogger
<
Default
Dispatche
r
>
logger
)
{
_logger
=
logger
;
_queueExecutorFactory
=
queueExecutorFactory
;
...
...
src/DotNetCore.CAP/Processor/I
MessageProcesso
r.cs
→
src/DotNetCore.CAP/Processor/I
Dispatche
r.cs
View file @
768a62c3
...
...
@@ -4,7 +4,7 @@ using System.Text;
namespace
DotNetCore.CAP.Processor
{
public
interface
I
MessageProcesso
r
:
IProcessor
public
interface
I
Dispatche
r
:
IProcessor
{
bool
Waiting
{
get
;
}
}
...
...
src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs
View file @
768a62c3
...
...
@@ -18,7 +18,7 @@ namespace DotNetCore.CAP.Processor
private
readonly
CapOptions
_options
;
private
IProcessor
[]
_processors
;
private
IList
<
I
MessageProcessor
>
_messageProcesso
rs
;
private
IList
<
I
Dispatcher
>
_messageDispatche
rs
;
private
ProcessingContext
_context
;
private
Task
_compositeTask
;
private
bool
_disposed
;
...
...
@@ -34,6 +34,7 @@ namespace DotNetCore.CAP.Processor
_provider
=
provider
;
_options
=
options
.
Value
;
_cts
=
new
CancellationTokenSource
();
_messageDispatchers
=
new
List
<
IDispatcher
>();
}
public
void
Start
()
...
...
@@ -90,7 +91,7 @@ namespace DotNetCore.CAP.Processor
private
bool
AllProcessorsWaiting
()
{
foreach
(
var
processor
in
_message
Processo
rs
)
foreach
(
var
processor
in
_message
Dispatche
rs
)
{
if
(!
processor
.
Waiting
)
{
...
...
@@ -110,10 +111,10 @@ namespace DotNetCore.CAP.Processor
var
returnedProcessors
=
new
List
<
IProcessor
>();
for
(
int
i
=
0
;
i
<
processorCount
;
i
++)
{
var
messageProcessors
=
_provider
.
GetService
<
I
MessageProcesso
r
>();
_message
Processo
rs
.
Add
(
messageProcessors
);
var
messageProcessors
=
_provider
.
GetService
<
I
Dispatche
r
>();
_message
Dispatche
rs
.
Add
(
messageProcessors
);
}
returnedProcessors
.
AddRange
(
_message
Processo
rs
);
returnedProcessors
.
AddRange
(
_message
Dispatche
rs
);
returnedProcessors
.
Add
(
_provider
.
GetService
<
PublishQueuer
>());
returnedProcessors
.
Add
(
_provider
.
GetService
<
SubscribeQueuer
>());
...
...
src/DotNetCore.CAP/Processor/IProcessor.PublishQueuer.cs
View file @
768a62c3
...
...
@@ -59,7 +59,7 @@ namespace DotNetCore.CAP.Processor
context
.
ThrowIfStopping
();
Default
MessageProcesso
r
.
PulseEvent
.
Set
();
Default
Dispatche
r
.
PulseEvent
.
Set
();
await
WaitHandleEx
.
WaitAnyAsync
(
PulseEvent
,
context
.
CancellationToken
.
WaitHandle
,
_pollingDelay
);
...
...
src/DotNetCore.CAP/Processor/IProcessor.SubscribeQueuer.cs
View file @
768a62c3
...
...
@@ -59,7 +59,7 @@ namespace DotNetCore.CAP.Processor
context
.
ThrowIfStopping
();
Default
MessageProcesso
r
.
PulseEvent
.
Set
();
Default
Dispatche
r
.
PulseEvent
.
Set
();
await
WaitHandleEx
.
WaitAnyAsync
(
PulseEvent
,
context
.
CancellationToken
.
WaitHandle
,
_pollingDelay
);
...
...
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