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
9b67cc4d
Commit
9b67cc4d
authored
Jun 24, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor.
parent
b478b77d
Changes
23
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
187 additions
and
261 deletions
+187
-261
ConsistencyDbContext.cs
...otNetCore.CAP.EntityFrameworkCore/ConsistencyDbContext.cs
+2
-2
ConsistencyEntityFrameworkBuilderExtensions.cs
...meworkCore/ConsistencyEntityFrameworkBuilderExtensions.cs
+1
-1
ConsistencyMessageStore.cs
...etCore.CAP.EntityFrameworkCore/ConsistencyMessageStore.cs
+58
-125
IProcessor.Producer.cs
src/DotNetCore.CAP.Kafka/IProcessor.Producer.cs
+9
-8
KafkaConsumerClient.cs
src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs
+4
-5
KafkaTopicAttribute.cs
src/DotNetCore.CAP.Kafka/KafkaTopicAttribute.cs
+4
-2
RabbitMQConsumerClient.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
+4
-5
RabbitMQProducerClient.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQProducerClient.cs
+2
-1
ConsumerContext.cs
src/DotNetCore.CAP/Abstractions/ConsumerContext.cs
+2
-2
IConsumerServiceSelector.cs
src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs
+3
-4
IModelBinder.cs
src/DotNetCore.CAP/Abstractions/ModelBinding/IModelBinder.cs
+1
-1
ModelBindingContext.cs
...Core.CAP/Abstractions/ModelBinding/ModelBindingContext.cs
+1
-1
ICapMessageStore.cs
src/DotNetCore.CAP/ICapMessageStore.cs
+18
-28
ICapProducerService.Default.cs
src/DotNetCore.CAP/ICapProducerService.Default.cs
+5
-11
IConsumerClient.cs
src/DotNetCore.CAP/IConsumerClient.cs
+3
-5
IConsumerClientFactory.cs
src/DotNetCore.CAP/IConsumerClientFactory.cs
+2
-7
IConsumerHandler.Default.cs
src/DotNetCore.CAP/IConsumerHandler.Default.cs
+36
-26
IConsumerInvoker.Default.cs
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
+2
-3
IConsumerServiceSelector.Default.cs
...tNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
+2
-1
MethodMatcherCache.cs
src/DotNetCore.CAP/Internal/MethodMatcherCache.cs
+0
-1
LoggerExtensions.cs
src/DotNetCore.CAP/LoggerExtensions.cs
+12
-0
CAP.BuilderTest.cs
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
+10
-6
NoopMessageStore.cs
test/DotNetCore.CAP.Test/NoopMessageStore.cs
+6
-16
No files found.
src/DotNetCore.CAP.EntityFrameworkCore/ConsistencyDbContext.cs
View file @
9b67cc4d
...
@@ -24,7 +24,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
...
@@ -24,7 +24,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// <summary>
/// <summary>
/// Gets or sets the <see cref="DbSet{ConsistencyMessage}"/> of Messages.
/// Gets or sets the <see cref="DbSet{ConsistencyMessage}"/> of Messages.
/// </summary>
/// </summary>
public
DbSet
<
C
onsistency
Message
>
Messages
{
get
;
set
;
}
public
DbSet
<
C
ap
Message
>
Messages
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Configures the schema for the identity framework.
/// Configures the schema for the identity framework.
...
@@ -34,7 +34,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
...
@@ -34,7 +34,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// </param>
/// </param>
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
{
modelBuilder
.
Entity
<
C
onsistency
Message
>(
b
=>
modelBuilder
.
Entity
<
C
ap
Message
>(
b
=>
{
{
b
.
HasKey
(
m
=>
m
.
Id
);
b
.
HasKey
(
m
=>
m
.
Id
);
b
.
ToTable
(
"ConsistencyMessages"
);
b
.
ToTable
(
"ConsistencyMessages"
);
...
...
src/DotNetCore.CAP.EntityFrameworkCore/ConsistencyEntityFrameworkBuilderExtensions.cs
View file @
9b67cc4d
...
@@ -18,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -18,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
public
static
CapBuilder
AddEntityFrameworkStores
<
TContext
>(
this
CapBuilder
builder
)
public
static
CapBuilder
AddEntityFrameworkStores
<
TContext
>(
this
CapBuilder
builder
)
where
TContext
:
DbContext
where
TContext
:
DbContext
{
{
builder
.
Services
.
AddScoped
<
ICapMessageStore
,
C
onsistency
MessageStore
<
TContext
>>();
builder
.
Services
.
AddScoped
<
ICapMessageStore
,
C
ap
MessageStore
<
TContext
>>();
return
builder
;
return
builder
;
}
}
...
...
src/DotNetCore.CAP.EntityFrameworkCore/ConsistencyMessageStore.cs
View file @
9b67cc4d
This diff is collapsed.
Click to expand it.
src/DotNetCore.CAP.Kafka/IProcessor.Producer.cs
View file @
9b67cc4d
...
@@ -83,14 +83,14 @@ namespace DotNetCore.CAP.Kafka
...
@@ -83,14 +83,14 @@ namespace DotNetCore.CAP.Kafka
var
messageStore
=
provider
.
GetRequiredService
<
ICapMessageStore
>();
var
messageStore
=
provider
.
GetRequiredService
<
ICapMessageStore
>();
try
try
{
{
var
message
=
await
messageStore
.
Get
FirstEnqueuedMessageAsync
(
_cts
.
Token
);
var
message
=
await
messageStore
.
Get
NextSentMessageToBeEnqueuedAsync
(
);
if
(
message
!=
null
)
if
(
message
!=
null
)
{
{
var
sp
=
Stopwatch
.
StartNew
();
var
sp
=
Stopwatch
.
StartNew
();
message
.
Stat
us
=
MessageStatus
.
Processing
;
message
.
Stat
eName
=
StateName
.
Processing
;
await
messageStore
.
Update
Async
(
message
,
_cts
.
Token
);
await
messageStore
.
Update
SentMessageAsync
(
message
);
var
jobResult
=
ExecuteJob
(
message
.
Topic
,
message
.
Payload
);
var
jobResult
=
ExecuteJob
(
message
.
KeyName
,
message
.
Content
);
sp
.
Stop
();
sp
.
Stop
();
...
@@ -100,14 +100,15 @@ namespace DotNetCore.CAP.Kafka
...
@@ -100,14 +100,15 @@ namespace DotNetCore.CAP.Kafka
}
}
else
else
{
{
message
.
Status
=
MessageStatus
.
Successed
;
//TODO : the state will be deleted when release.
await
messageStore
.
UpdateAsync
(
message
,
_cts
.
Token
);
message
.
StateName
=
StateName
.
Succeeded
;
//await messageStore.DeleteAsync(message, _cts.Token);
await
messageStore
.
UpdateSentMessageAsync
(
message
);
_logger
.
JobExecuted
(
sp
.
Elapsed
.
TotalSeconds
);
_logger
.
JobExecuted
(
sp
.
Elapsed
.
TotalSeconds
);
}
}
}
}
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
return
false
;
return
false
;
}
}
...
...
src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs
View file @
9b67cc4d
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.Kafka
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.Kafka
private
Consumer
<
Null
,
string
>
_consumerClient
;
private
Consumer
<
Null
,
string
>
_consumerClient
;
public
event
EventHandler
<
DeliverMessag
e
>
MessageReceieved
;
public
event
EventHandler
<
MessageBas
e
>
MessageReceieved
;
public
IDeserializer
<
string
>
StringDeserializer
{
get
;
set
;
}
public
IDeserializer
<
string
>
StringDeserializer
{
get
;
set
;
}
...
@@ -69,11 +69,10 @@ namespace DotNetCore.CAP.Kafka
...
@@ -69,11 +69,10 @@ namespace DotNetCore.CAP.Kafka
private
void
ConsumerClient_OnMessage
(
object
sender
,
Message
<
Null
,
string
>
e
)
private
void
ConsumerClient_OnMessage
(
object
sender
,
Message
<
Null
,
string
>
e
)
{
{
var
message
=
new
DeliverMessag
e
var
message
=
new
MessageBas
e
{
{
MessageKey
=
e
.
Topic
,
KeyName
=
e
.
Topic
,
Value
=
e
.
Value
,
Content
=
e
.
Value
Body
=
Encoding
.
UTF8
.
GetBytes
(
e
.
Value
)
};
};
MessageReceieved
?.
Invoke
(
sender
,
message
);
MessageReceieved
?.
Invoke
(
sender
,
message
);
}
}
...
...
src/DotNetCore.CAP.Kafka/KafkaTopicAttribute.cs
View file @
9b67cc4d
...
@@ -11,7 +11,8 @@ namespace DotNetCore.CAP.Kafka
...
@@ -11,7 +11,8 @@ namespace DotNetCore.CAP.Kafka
:
this
(
topicName
,
partition
,
0
)
{
}
:
this
(
topicName
,
partition
,
0
)
{
}
public
KafkaTopicAttribute
(
string
topicName
,
int
partition
,
long
offset
)
public
KafkaTopicAttribute
(
string
topicName
,
int
partition
,
long
offset
)
:
base
(
topicName
)
{
:
base
(
topicName
)
{
Offset
=
offset
;
Offset
=
offset
;
Partition
=
partition
;
Partition
=
partition
;
}
}
...
@@ -24,7 +25,8 @@ namespace DotNetCore.CAP.Kafka
...
@@ -24,7 +25,8 @@ namespace DotNetCore.CAP.Kafka
public
bool
IsOffset
{
get
{
return
Offset
==
0
;
}
}
public
bool
IsOffset
{
get
{
return
Offset
==
0
;
}
}
public
override
string
ToString
()
{
public
override
string
ToString
()
{
return
Name
;
return
Name
;
}
}
}
}
...
...
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
View file @
9b67cc4d
...
@@ -19,7 +19,7 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -19,7 +19,7 @@ namespace DotNetCore.CAP.RabbitMQ
private
string
_queueName
;
private
string
_queueName
;
public
event
EventHandler
<
DeliverMessag
e
>
MessageReceieved
;
public
event
EventHandler
<
MessageBas
e
>
MessageReceieved
;
public
RabbitMQConsumerClient
(
string
exchange
,
string
hostName
)
public
RabbitMQConsumerClient
(
string
exchange
,
string
hostName
)
{
{
...
@@ -65,11 +65,10 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -65,11 +65,10 @@ namespace DotNetCore.CAP.RabbitMQ
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
{
{
var
message
=
new
DeliverMessag
e
var
message
=
new
MessageBas
e
{
{
MessageKey
=
e
.
RoutingKey
,
KeyName
=
e
.
RoutingKey
,
Body
=
e
.
Body
,
Content
=
Encoding
.
UTF8
.
GetString
(
e
.
Body
)
Value
=
Encoding
.
UTF8
.
GetString
(
e
.
Body
)
};
};
MessageReceieved
?.
Invoke
(
sender
,
message
);
MessageReceieved
?.
Invoke
(
sender
,
message
);
}
}
...
...
src/DotNetCore.CAP.RabbitMQ/RabbitMQProducerClient.cs
View file @
9b67cc4d
...
@@ -38,7 +38,8 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -38,7 +38,8 @@ namespace DotNetCore.CAP.RabbitMQ
}
}
}
}
public
Task
SendAsync
<
T
>(
string
topic
,
T
contentObj
)
{
public
Task
SendAsync
<
T
>(
string
topic
,
T
contentObj
)
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
}
}
...
...
src/DotNetCore.CAP/Abstractions/ConsumerContext.cs
View file @
9b67cc4d
...
@@ -13,7 +13,7 @@ namespace DotNetCore.CAP.Abstractions
...
@@ -13,7 +13,7 @@ namespace DotNetCore.CAP.Abstractions
/// </summary>
/// </summary>
/// <param name="descriptor">consumer method descriptor. </param>
/// <param name="descriptor">consumer method descriptor. </param>
/// <param name="message"> reveied message.</param>
/// <param name="message"> reveied message.</param>
public
ConsumerContext
(
ConsumerExecutorDescriptor
descriptor
,
DeliverMessag
e
message
)
public
ConsumerContext
(
ConsumerExecutorDescriptor
descriptor
,
MessageBas
e
message
)
{
{
ConsumerDescriptor
=
descriptor
??
throw
new
ArgumentNullException
(
nameof
(
descriptor
));
ConsumerDescriptor
=
descriptor
??
throw
new
ArgumentNullException
(
nameof
(
descriptor
));
DeliverMessage
=
message
??
throw
new
ArgumentNullException
(
nameof
(
message
));
DeliverMessage
=
message
??
throw
new
ArgumentNullException
(
nameof
(
message
));
...
@@ -27,6 +27,6 @@ namespace DotNetCore.CAP.Abstractions
...
@@ -27,6 +27,6 @@ namespace DotNetCore.CAP.Abstractions
/// <summary>
/// <summary>
/// consumer reveived message.
/// consumer reveived message.
/// </summary>
/// </summary>
public
DeliverMessag
e
DeliverMessage
{
get
;
set
;
}
public
MessageBas
e
DeliverMessage
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs
View file @
9b67cc4d
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
DotNetCore.CAP.Abstractions
;
namespace
DotNetCore.CAP.Abstractions
namespace
DotNetCore.CAP.Abstractions
{
{
/// <summary>
/// <summary>
/// Defines an interface for selecting an cosumer service method to invoke for the current message.
/// Defines an interface for selecting an cosumer service method to invoke for the current message.
/// </summary>
/// </summary>
public
interface
IConsumerServiceSelector
public
interface
IConsumerServiceSelector
{
{
...
@@ -17,8 +16,8 @@ namespace DotNetCore.CAP.Abstractions
...
@@ -17,8 +16,8 @@ namespace DotNetCore.CAP.Abstractions
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
(
CapStartContext
context
);
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
(
CapStartContext
context
);
/// <summary>
/// <summary>
/// Selects the best <see cref="ConsumerExecutorDescriptor"/> candidate from <paramref name="candidates"/> for the
/// Selects the best <see cref="ConsumerExecutorDescriptor"/> candidate from <paramref name="candidates"/> for the
/// current message associated
with <paramref name="context"/>
.
/// current message associated.
/// </summary>
/// </summary>
/// <param name="key">topic or exchange router key.</param>
/// <param name="key">topic or exchange router key.</param>
/// <param name="candidates">the set of <see cref="ConsumerExecutorDescriptor"/> candidates.</param>
/// <param name="candidates">the set of <see cref="ConsumerExecutorDescriptor"/> candidates.</param>
...
...
src/DotNetCore.CAP/Abstractions/ModelBinding/IModelBinder.cs
View file @
9b67cc4d
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
/// </para>
/// </para>
/// <para>
/// <para>
/// A model binder that completes successfully should set <see cref="ModelBindingContext.Result"/> to
/// A model binder that completes successfully should set <see cref="ModelBindingContext.Result"/> to
/// a value returned from <see cref="ModelBindingResult.Success"/>.
/// a value returned from <see cref="ModelBindingResult.Success"/>.
/// </para>
/// </para>
/// </returns>
/// </returns>
Task
BindModelAsync
(
ModelBindingContext
bindingContext
);
Task
BindModelAsync
(
ModelBindingContext
bindingContext
);
...
...
src/DotNetCore.CAP/Abstractions/ModelBinding/ModelBindingContext.cs
View file @
9b67cc4d
...
@@ -18,7 +18,7 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
...
@@ -18,7 +18,7 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
public
object
Model
{
get
;
set
;
}
public
object
Model
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Gets or sets the name of the model.
/// Gets or sets the name of the model.
/// </summary>
/// </summary>
public
string
ModelName
{
get
;
set
;
}
public
string
ModelName
{
get
;
set
;
}
...
...
src/DotNetCore.CAP/ICapMessageStore.cs
View file @
9b67cc4d
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP
namespace
DotNetCore.CAP
...
@@ -11,49 +10,40 @@ namespace DotNetCore.CAP
...
@@ -11,49 +10,40 @@ namespace DotNetCore.CAP
public
interface
ICapMessageStore
public
interface
ICapMessageStore
{
{
/// <summary>
/// <summary>
///
Finds and returns a message, if any, who has the specified <paramref name="messageId"/>
.
///
Creates a new message in a store as an asynchronous operation
.
/// </summary>
/// </summary>
/// <param name="messageId">The message ID to search for.</param>
/// <param name="message">The message to create in the store.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
Task
<
OperateResult
>
StoreSentMessageAsync
(
CapSentMessage
message
);
/// <returns>
/// The <see cref="Task"/> that represents the asynchronous operation, containing the message matching the specified <paramref name="messageId"/> if it exists.
/// </returns>
Task
<
ConsistencyMessage
>
FindByIdAsync
(
string
messageId
,
CancellationToken
cancellationToken
);
/// <summary>
/// <summary>
///
Creates a new message in a store as an asynchronous operation
.
///
Fetches the next message to be executed
.
/// </summary>
/// </summary>
/// <param name="message">The message to create in the store.</param>
/// <returns></returns>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
Task
<
CapSentMessage
>
GetNextSentMessageToBeEnqueuedAsync
();
/// <returns>A <see cref="Task{TResult}"/> that represents the <see cref="OperateResult"/> of the asynchronous query.</returns>
Task
<
OperateResult
>
CreateAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
);
/// <summary>
/// <summary>
/// Updates a message in a store as an asynchronous operation.
/// Updates a message in a store as an asynchronous operation.
/// </summary>
/// </summary>
/// <param name="message">The message to update in the store.</param>
/// <param name="message">The message to update in the store.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
Task
<
OperateResult
>
UpdateSentMessageAsync
(
CapSentMessage
message
);
/// <returns>A <see cref="Task{TResult}"/> that represents the <see cref="OperateResult"/> of the asynchronous query.</returns>
Task
<
OperateResult
>
UpdateAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
);
/// <summary>
/// <summary>
/// Deletes a message from the store as an asynchronous operation.
/// Deletes a message from the store as an asynchronous operation.
/// </summary>
/// </summary>
/// <param name="message">The message to delete in the store.</param>
/// <param name="message">The message to delete in the store.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
Task
<
OperateResult
>
RemoveSentMessageAsync
(
CapSentMessage
message
);
/// <returns>A <see cref="Task{TResult}"/> that represents the <see cref="OperateResult"/> of the asynchronous query.</returns>
Task
<
OperateResult
>
DeleteAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
);
/// <summary>
/// <summary>
///
Gets the ID for a message from the
store as an asynchronous operation.
///
Creates a new message in a
store as an asynchronous operation.
/// </summary>
/// </summary>
/// <param name="message">The message whose ID should be returned.</param>
/// <param name="message"></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns></returns>
/// <returns>A <see cref="Task{TResult}"/> that contains the ID of the message.</returns>
Task
<
OperateResult
>
StoreReceivedMessageAsync
(
CapReceivedMessage
message
);
Task
<
string
>
GeConsistencyMessageIdAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
);
Task
<
ConsistencyMessage
>
GetFirstEnqueuedMessageAsync
(
CancellationToken
cancellationToken
);
// void ChangeState(ConsistencyMessage message, MessageStatus status);
/// <summary>
/// Updates a message in a store as an asynchronous operation.
/// </summary>
/// <param name="message">The message to update in the store.</param>
Task
<
OperateResult
>
UpdateReceivedMessageAsync
(
CapReceivedMessage
message
);
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/ICapProducerService.Default.cs
View file @
9b67cc4d
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Infrastructure
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
...
@@ -13,7 +12,6 @@ namespace DotNetCore.CAP
...
@@ -13,7 +12,6 @@ namespace DotNetCore.CAP
{
{
private
readonly
ICapMessageStore
_store
;
private
readonly
ICapMessageStore
_store
;
private
readonly
ILogger
_logger
;
private
readonly
ILogger
_logger
;
private
readonly
CancellationTokenSource
_cts
;
public
DefaultProducerService
(
public
DefaultProducerService
(
ICapMessageStore
store
,
ICapMessageStore
store
,
...
@@ -21,7 +19,6 @@ namespace DotNetCore.CAP
...
@@ -21,7 +19,6 @@ namespace DotNetCore.CAP
{
{
_store
=
store
;
_store
=
store
;
_logger
=
logger
;
_logger
=
logger
;
_cts
=
new
CancellationTokenSource
();
}
}
public
Task
SendAsync
(
string
topic
,
string
content
)
public
Task
SendAsync
(
string
topic
,
string
content
)
...
@@ -45,20 +42,17 @@ namespace DotNetCore.CAP
...
@@ -45,20 +42,17 @@ namespace DotNetCore.CAP
private
async
Task
StoreMessage
(
string
topic
,
string
content
)
private
async
Task
StoreMessage
(
string
topic
,
string
content
)
{
{
var
message
=
new
C
onsistency
Message
var
message
=
new
C
apSent
Message
{
{
Topic
=
topic
,
KeyName
=
topic
,
Payload
=
content
Content
=
content
};
};
await
_store
.
CreateAsync
(
message
,
_cts
.
Token
);
await
_store
.
StoreSentMessageAsync
(
message
);
WaitHandleEx
.
PulseEvent
.
Set
();
WaitHandleEx
.
PulseEvent
.
Set
();
if
(
_logger
.
IsEnabled
(
LogLevel
.
Debug
))
_logger
.
EnqueuingMessage
(
topic
,
content
);
{
_logger
.
LogDebug
(
"Enqueuing a topic to be store. topic:{topic}, content:{content}"
,
topic
,
content
);
}
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/IConsumerClient.cs
View file @
9b67cc4d
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP
namespace
DotNetCore.CAP
{
{
/// <summary>
/// <summary>
/// consumer client
/// consumer client
/// </summary>
/// </summary>
public
interface
IConsumerClient
:
IDisposable
public
interface
IConsumerClient
:
IDisposable
{
{
...
@@ -16,6 +14,6 @@ namespace DotNetCore.CAP
...
@@ -16,6 +14,6 @@ namespace DotNetCore.CAP
void
Listening
(
TimeSpan
timeout
);
void
Listening
(
TimeSpan
timeout
);
event
EventHandler
<
DeliverMessag
e
>
MessageReceieved
;
event
EventHandler
<
MessageBas
e
>
MessageReceieved
;
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/IConsumerClientFactory.cs
View file @
9b67cc4d
using
System
;
namespace
DotNetCore.CAP
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
DotNetCore.CAP
{
{
/// <summary>
/// <summary>
/// Consumer client factory to create consumer client instance.
/// Consumer client factory to create consumer client instance.
...
@@ -18,4 +13,4 @@ namespace DotNetCore.CAP
...
@@ -18,4 +13,4 @@ namespace DotNetCore.CAP
/// <returns></returns>
/// <returns></returns>
IConsumerClient
Create
(
string
groupId
,
string
clientHostAddress
);
IConsumerClient
Create
(
string
groupId
,
string
clientHostAddress
);
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/IConsumerHandler.Default.cs
View file @
9b67cc4d
using
System
;
using
System
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions
;
...
@@ -24,7 +23,7 @@ namespace DotNetCore.CAP
...
@@ -24,7 +23,7 @@ namespace DotNetCore.CAP
private
readonly
ICapMessageStore
_messageStore
;
private
readonly
ICapMessageStore
_messageStore
;
private
readonly
CancellationTokenSource
_cts
;
private
readonly
CancellationTokenSource
_cts
;
public
event
EventHandler
<
C
onsistency
Message
>
MessageReceieved
;
public
event
EventHandler
<
C
ap
Message
>
MessageReceieved
;
private
CapStartContext
_context
;
private
CapStartContext
_context
;
private
Task
_compositeTask
;
private
Task
_compositeTask
;
...
@@ -37,7 +36,8 @@ namespace DotNetCore.CAP
...
@@ -37,7 +36,8 @@ namespace DotNetCore.CAP
ILoggerFactory
loggerFactory
,
ILoggerFactory
loggerFactory
,
ICapMessageStore
messageStore
,
ICapMessageStore
messageStore
,
MethodMatcherCache
selector
,
MethodMatcherCache
selector
,
IOptions
<
CapOptions
>
options
)
{
IOptions
<
CapOptions
>
options
)
{
_selector
=
selector
;
_selector
=
selector
;
_logger
=
loggerFactory
.
CreateLogger
<
ConsumerHandler
>();
_logger
=
loggerFactory
.
CreateLogger
<
ConsumerHandler
>();
_loggerFactory
=
loggerFactory
;
_loggerFactory
=
loggerFactory
;
...
@@ -49,23 +49,29 @@ namespace DotNetCore.CAP
...
@@ -49,23 +49,29 @@ namespace DotNetCore.CAP
_cts
=
new
CancellationTokenSource
();
_cts
=
new
CancellationTokenSource
();
}
}
protected
virtual
void
OnMessageReceieved
(
ConsistencyMessage
message
)
{
protected
virtual
void
OnMessageReceieved
(
CapMessage
message
)
{
MessageReceieved
?.
Invoke
(
this
,
message
);
MessageReceieved
?.
Invoke
(
this
,
message
);
}
}
public
void
Start
()
{
public
void
Start
()
{
_context
=
new
CapStartContext
(
_serviceProvider
,
_cts
.
Token
);
_context
=
new
CapStartContext
(
_serviceProvider
,
_cts
.
Token
);
var
matchs
=
_selector
.
GetCandidatesMethods
(
_context
);
var
matchs
=
_selector
.
GetCandidatesMethods
(
_context
);
var
groupingMatchs
=
matchs
.
GroupBy
(
x
=>
x
.
Value
.
Attribute
.
GroupOrExchange
);
var
groupingMatchs
=
matchs
.
GroupBy
(
x
=>
x
.
Value
.
Attribute
.
GroupOrExchange
);
foreach
(
var
matchGroup
in
groupingMatchs
)
{
foreach
(
var
matchGroup
in
groupingMatchs
)
Task
.
Factory
.
StartNew
(()
=>
{
{
using
(
var
client
=
_consumerClientFactory
.
Create
(
matchGroup
.
Key
,
_options
.
BrokerUrlList
))
{
Task
.
Factory
.
StartNew
(()
=>
{
using
(
var
client
=
_consumerClientFactory
.
Create
(
matchGroup
.
Key
,
_options
.
BrokerUrlList
))
{
client
.
MessageReceieved
+=
OnMessageReceieved
;
client
.
MessageReceieved
+=
OnMessageReceieved
;
foreach
(
var
item
in
matchGroup
)
{
foreach
(
var
item
in
matchGroup
)
{
client
.
Subscribe
(
item
.
Key
);
client
.
Subscribe
(
item
.
Key
);
}
}
...
@@ -76,19 +82,17 @@ namespace DotNetCore.CAP
...
@@ -76,19 +82,17 @@ namespace DotNetCore.CAP
_compositeTask
=
Task
.
CompletedTask
;
_compositeTask
=
Task
.
CompletedTask
;
}
}
public
virtual
void
OnMessageReceieved
(
object
sender
,
DeliverMessage
message
)
{
public
virtual
void
OnMessageReceieved
(
object
sender
,
MessageBase
message
)
var
consistencyMessage
=
new
ConsistencyMessage
()
{
{
Topic
=
message
.
MessageKey
,
var
capMessage
=
new
CapReceivedMessage
(
message
);
Payload
=
"Reveived:"
+
Encoding
.
UTF8
.
GetString
(
message
.
Body
),
Status
=
MessageStatus
.
Received
};
_logger
.
LogInformation
(
"message receieved message topic name: "
+
c
onsistency
Message
.
Id
);
_logger
.
LogInformation
(
"message receieved message topic name: "
+
c
ap
Message
.
Id
);
_messageStore
.
CreateAsync
(
consistencyMessage
,
_cts
.
Token
).
Wait
();
_messageStore
.
StoreReceivedMessageAsync
(
capMessage
).
Wait
();
try
{
try
var
executeDescriptor
=
_selector
.
GetTopicExector
(
message
.
MessageKey
);
{
var
executeDescriptor
=
_selector
.
GetTopicExector
(
message
.
KeyName
);
var
consumerContext
=
new
ConsumerContext
(
executeDescriptor
,
message
);
var
consumerContext
=
new
ConsumerContext
(
executeDescriptor
,
message
);
...
@@ -96,15 +100,18 @@ namespace DotNetCore.CAP
...
@@ -96,15 +100,18 @@ namespace DotNetCore.CAP
invoker
.
InvokeAsync
();
invoker
.
InvokeAsync
();
_messageStore
.
Update
Async
(
consistencyMessage
,
_cts
.
Token
).
Wait
();
_messageStore
.
Update
ReceivedMessageAsync
(
capMessage
).
Wait
();
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
_logger
.
LogError
(
"exception raised when excute method : "
+
ex
.
Message
);
_logger
.
LogError
(
"exception raised when excute method : "
+
ex
.
Message
);
}
}
}
}
public
void
Dispose
()
{
public
void
Dispose
()
if
(
_disposed
)
{
{
if
(
_disposed
)
{
return
;
return
;
}
}
_disposed
=
true
;
_disposed
=
true
;
...
@@ -112,12 +119,15 @@ namespace DotNetCore.CAP
...
@@ -112,12 +119,15 @@ namespace DotNetCore.CAP
_logger
.
ServerShuttingDown
();
_logger
.
ServerShuttingDown
();
_cts
.
Cancel
();
_cts
.
Cancel
();
try
{
try
{
_compositeTask
.
Wait
((
int
)
TimeSpan
.
FromSeconds
(
60
).
TotalMilliseconds
);
_compositeTask
.
Wait
((
int
)
TimeSpan
.
FromSeconds
(
60
).
TotalMilliseconds
);
}
}
catch
(
AggregateException
ex
)
{
catch
(
AggregateException
ex
)
{
var
innerEx
=
ex
.
InnerExceptions
[
0
];
var
innerEx
=
ex
.
InnerExceptions
[
0
];
if
(!(
innerEx
is
OperationCanceledException
))
{
if
(!(
innerEx
is
OperationCanceledException
))
{
_logger
.
ExpectedOperationCanceledException
(
innerEx
);
_logger
.
ExpectedOperationCanceledException
(
innerEx
);
}
}
}
}
...
...
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
View file @
9b67cc4d
using
System
;
using
System
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
...
@@ -41,13 +40,13 @@ namespace DotNetCore.CAP.Internal
...
@@ -41,13 +40,13 @@ namespace DotNetCore.CAP.Internal
{
{
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
_serviceProvider
,
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
());
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
_serviceProvider
,
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
());
var
bodyString
=
Encoding
.
UTF8
.
GetString
(
_consumerContext
.
DeliverMessage
.
Body
)
;
var
value
=
_consumerContext
.
DeliverMessage
.
Content
;
if
(
_executor
.
MethodParameters
.
Length
>
0
)
if
(
_executor
.
MethodParameters
.
Length
>
0
)
{
{
var
firstParameter
=
_executor
.
MethodParameters
[
0
];
var
firstParameter
=
_executor
.
MethodParameters
[
0
];
var
bindingContext
=
ModelBindingContext
.
CreateBindingContext
(
bodyString
,
var
bindingContext
=
ModelBindingContext
.
CreateBindingContext
(
value
,
firstParameter
.
Name
,
firstParameter
.
ParameterType
);
firstParameter
.
Name
,
firstParameter
.
ParameterType
);
_modelBinder
.
BindModelAsync
(
bindingContext
);
_modelBinder
.
BindModelAsync
(
bindingContext
);
...
...
src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
View file @
9b67cc4d
...
@@ -24,7 +24,8 @@ namespace DotNetCore.CAP.Internal
...
@@ -24,7 +24,8 @@ namespace DotNetCore.CAP.Internal
}
}
/// <summary>
/// <summary>
///
/// Selects the best <see cref="ConsumerExecutorDescriptor"/> candidate from <paramref name="candidates"/> for the
/// current message associated.
/// </summary>
/// </summary>
/// <param name="key"></param>
/// <param name="key"></param>
/// <param name="executeDescriptor"></param>
/// <param name="executeDescriptor"></param>
...
...
src/DotNetCore.CAP/Internal/MethodMatcherCache.cs
View file @
9b67cc4d
using
System
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Concurrent
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP.Internal
namespace
DotNetCore.CAP.Internal
{
{
...
...
src/DotNetCore.CAP/LoggerExtensions.cs
View file @
9b67cc4d
...
@@ -17,6 +17,8 @@ namespace DotNetCore.CAP
...
@@ -17,6 +17,8 @@ namespace DotNetCore.CAP
private
static
Action
<
ILogger
,
string
,
double
,
Exception
>
_cronJobExecuted
;
private
static
Action
<
ILogger
,
string
,
double
,
Exception
>
_cronJobExecuted
;
private
static
Action
<
ILogger
,
string
,
Exception
>
_cronJobFailed
;
private
static
Action
<
ILogger
,
string
,
Exception
>
_cronJobFailed
;
private
static
Action
<
ILogger
,
string
,
string
,
Exception
>
_enqueuingMessage
;
static
LoggerExtensions
()
static
LoggerExtensions
()
{
{
_serverStarting
=
LoggerMessage
.
Define
<
int
,
int
>(
_serverStarting
=
LoggerMessage
.
Define
<
int
,
int
>(
...
@@ -53,6 +55,16 @@ namespace DotNetCore.CAP
...
@@ -53,6 +55,16 @@ namespace DotNetCore.CAP
LogLevel
.
Warning
,
LogLevel
.
Warning
,
4
,
4
,
"Cron job '{jobName}' failed to execute."
);
"Cron job '{jobName}' failed to execute."
);
_enqueuingMessage
=
LoggerMessage
.
Define
<
string
,
string
>(
LogLevel
.
Debug
,
2
,
"Enqueuing a topic to the store. NameKey: {NameKey}. Content: {Content}"
);
}
public
static
void
EnqueuingMessage
(
this
ILogger
logger
,
string
nameKey
,
string
content
)
{
_enqueuingMessage
(
logger
,
nameKey
,
content
,
null
);
}
}
public
static
void
ServerStarting
(
this
ILogger
logger
,
int
machineProcessorCount
,
int
processorCount
)
public
static
void
ServerStarting
(
this
ILogger
logger
,
int
machineProcessorCount
,
int
processorCount
)
...
...
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
View file @
9b67cc4d
...
@@ -54,6 +54,10 @@ namespace DotNetCore.CAP.Test
...
@@ -54,6 +54,10 @@ namespace DotNetCore.CAP.Test
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
SendAsync
<
T
>(
string
topic
,
T
contentObj
)
{
throw
new
NotImplementedException
();
}
}
}
...
@@ -67,32 +71,32 @@ namespace DotNetCore.CAP.Test
...
@@ -67,32 +71,32 @@ namespace DotNetCore.CAP.Test
private
class
MyMessageStore
:
ICapMessageStore
private
class
MyMessageStore
:
ICapMessageStore
{
{
public
Task
<
OperateResult
>
CreateAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
CapSentMessage
>
GetNextSentMessageToBeEnqueuedAsync
(
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
OperateResult
>
DeleteAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
RemoveSentMessageAsync
(
CapSentMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
ConsistencyMessage
>
FindByIdAsync
(
string
messageId
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
StoreReceivedMessageAsync
(
CapReceivedMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
string
>
GeConsistencyMessageIdAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
StoreSentMessageAsync
(
CapSentMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
ConsistencyMessage
>
GetFirstEnqueuedMessageAsync
(
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
UpdateReceivedMessageAsync
(
CapReceivedMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
OperateResult
>
Update
Async
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
Update
SentMessageAsync
(
CapSentMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
...
...
test/DotNetCore.CAP.Test/NoopMessageStore.cs
View file @
9b67cc4d
...
@@ -7,42 +7,32 @@ namespace DotNetCore.CAP.Test
...
@@ -7,42 +7,32 @@ namespace DotNetCore.CAP.Test
{
{
public
class
NoopMessageStore
:
ICapMessageStore
public
class
NoopMessageStore
:
ICapMessageStore
{
{
public
Task
<
OperateResult
>
CreateAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
CapSentMessage
>
GetNextSentMessageToBeEnqueuedAsync
(
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
OperateResult
>
DeleteAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
RemoveSentMessageAsync
(
CapSentMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
void
Dispose
(
)
public
Task
<
OperateResult
>
StoreReceivedMessageAsync
(
CapReceivedMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
ConsistencyMessage
>
FindByIdAsync
(
string
messageId
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
StoreSentMessageAsync
(
CapSentMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
string
>
GeConsistencyMessageIdAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
UpdateReceivedMessageAsync
(
CapReceivedMessage
message
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
ConsistencyMessage
>
GetFirstEnqueuedMessageAsync
(
CancellationToken
cancellationToken
)
public
Task
<
OperateResult
>
UpdateSentMessageAsync
(
CapSentMessage
message
)
{
throw
new
NotImplementedException
();
}
public
Task
<
string
>
GetMessageIdAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
{
throw
new
NotImplementedException
();
}
public
Task
<
OperateResult
>
UpdateAsync
(
ConsistencyMessage
message
,
CancellationToken
cancellationToken
)
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
...
...
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