Browse Source

refactor

master
yangxiaodong 7 years ago
parent
commit
656771420b
2 changed files with 9 additions and 10 deletions
  1. +8
    -8
      src/Cap.Consistency/Consumer/ConsumerHandler.cs
  2. +1
    -2
      src/Cap.Consistency/Consumer/IConsumerHandler.cs

+ 8
- 8
src/Cap.Consistency/Consumer/ConsumerHandler.cs View File

@@ -4,14 +4,14 @@ using System.Linq;
using System.Threading.Tasks;
using Cap.Consistency.Abstractions;
using Cap.Consistency.Infrastructure;
using Cap.Consistency.Routing;
using Cap.Consistency.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Cap.Consistency.Store;

namespace Cap.Consistency.Consumer
{
public class ConsumerHandler<T> : IConsumerHandler<T> where T : ConsistencyMessage, new()
public class ConsumerHandler : IConsumerHandler
{
private readonly IServiceProvider _serviceProvider;
private readonly IConsumerInvokerFactory _consumerInvokerFactory;
@@ -20,21 +20,21 @@ namespace Cap.Consistency.Consumer
private readonly ILogger _logger;
private readonly MethodMatcherCache _selector;
private readonly ConsistencyOptions _options;
private readonly ConsistencyMessageManager<T> _messageManager;
private readonly ConsistencyMessageManager _messageManager;

public event EventHandler<T> MessageReceieved;
public event EventHandler<ConsistencyMessage> MessageReceieved;

public ConsumerHandler(
IServiceProvider serviceProvider,
IConsumerInvokerFactory consumerInvokerFactory,
IConsumerClientFactory consumerClientFactory,
ILoggerFactory loggerFactory,
ConsistencyMessageManager<T> messageManager,
ConsistencyMessageManager messageManager,
MethodMatcherCache selector,
IOptions<ConsistencyOptions> options) {

_selector = selector;
_logger = loggerFactory.CreateLogger<ConsumerHandler<T>>();
_logger = loggerFactory.CreateLogger<ConsumerHandler>();
_loggerFactory = loggerFactory;
_serviceProvider = serviceProvider;
_consumerInvokerFactory = consumerInvokerFactory;
@@ -44,7 +44,7 @@ namespace Cap.Consistency.Consumer
}


protected virtual void OnMessageReceieved(T message) {
protected virtual void OnMessageReceieved(ConsistencyMessage message) {
MessageReceieved?.Invoke(this, message);
}

@@ -77,7 +77,7 @@ namespace Cap.Consistency.Consumer
}

private void OnMessageReceieved(object sender, DeliverMessage message) {
T consistencyMessage = new T() {
var consistencyMessage = new ConsistencyMessage() {
Id = message.MessageKey,
Payload = Encoding.UTF8.GetString(message.Body)
};


+ 1
- 2
src/Cap.Consistency/Consumer/IConsumerHandler.cs View File

@@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.Text;
using Cap.Consistency.Infrastructure;
using Cap.Consistency.Routing;

namespace Cap.Consistency.Consumer
{
public interface IConsumerHandler<T> : ITopicRoute where T : ConsistencyMessage, new()
public interface IConsumerHandler: ITopicRouteHandler
{

}


Loading…
Cancel
Save