Browse Source

clear up code.

master
yangxiaodong 7 years ago
parent
commit
3ebc726ceb
15 changed files with 24 additions and 66 deletions
  1. +0
    -1
      src/Cap.Consistency.EntityFrameworkCore/ConsistencyEntityFrameworkBuilderExtensions.cs
  2. +0
    -1
      src/Cap.Consistency.EntityFrameworkCore/ConsistencyMessageStore.cs
  3. +2
    -6
      src/Cap.Consistency.Kafka/KafkaConsumerClient.cs
  4. +2
    -5
      src/Cap.Consistency.Kafka/KafkaConsumerClientFactory.cs
  5. +1
    -3
      src/Cap.Consistency.Kafka/KafkaProducerClient.cs
  6. +2
    -5
      src/Cap.Consistency.Kafka/KafkaTopicAttribute.cs
  7. +2
    -8
      src/Cap.Consistency.Kafka/Microsoft.Extensions.DependencyInjection/ConsistencyBuilderExtensions.cs
  8. +2
    -4
      src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClient.cs
  9. +2
    -5
      src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClientFactory.cs
  10. +2
    -6
      src/Cap.Consistency.RabbitMQ/RabbitMQProducerClient.cs
  11. +3
    -9
      src/Cap.Consistency/Consumer/IConsumerHandler.cs
  12. +2
    -6
      test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs
  13. +3
    -4
      test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreTest.cs
  14. +0
    -1
      test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs
  15. +1
    -2
      test/Cap.Consistency.Test/ConsistencyMessageManagerTest.cs

+ 0
- 1
src/Cap.Consistency.EntityFrameworkCore/ConsistencyEntityFrameworkBuilderExtensions.cs View File

@@ -17,7 +17,6 @@ namespace Microsoft.Extensions.DependencyInjection
/// <returns>The <see cref="ConsistencyBuilder"/> instance this method extends.</returns>
public static ConsistencyBuilder AddEntityFrameworkStores<TContext>(this ConsistencyBuilder builder)
where TContext : DbContext {

builder.Services.AddScoped<IConsistencyMessageStore, ConsistencyMessageStore<TContext>>();

return builder;


+ 0
- 1
src/Cap.Consistency.EntityFrameworkCore/ConsistencyMessageStore.cs View File

@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using Cap.Consistency.Infrastructure;


+ 2
- 6
src/Cap.Consistency.Kafka/KafkaConsumerClient.cs View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cap.Consistency.Consumer;
using Cap.Consistency.Infrastructure;
@@ -11,7 +10,6 @@ namespace Cap.Consistency.Kafka
{
public class KafkaConsumerClient : IConsumerClient
{

private readonly string _groupId;
private readonly string _bootstrapServers;

@@ -33,7 +31,6 @@ namespace Cap.Consistency.Kafka
}

public void Subscribe(string topicName, int partition) {

if (_consumerClient == null) {
InitKafkaClient();
}
@@ -72,7 +69,6 @@ namespace Cap.Consistency.Kafka
MessageReceieved?.Invoke(sender, message);
}

#endregion

#endregion private methods
}
}
}

+ 2
- 5
src/Cap.Consistency.Kafka/KafkaConsumerClientFactory.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cap.Consistency.Consumer;
using Cap.Consistency.Consumer;

namespace Cap.Consistency.Kafka
{
@@ -11,4 +8,4 @@ namespace Cap.Consistency.Kafka
return new KafkaConsumerClient(groupId, clientHostAddress);
}
}
}
}

+ 1
- 3
src/Cap.Consistency.Kafka/KafkaProducerClient.cs View File

@@ -14,7 +14,6 @@ namespace Cap.Consistency.Kafka
{
public class KafkaProducerClient : IProducerClient
{

private readonly ConsistencyOptions _options;
private readonly ILogger _logger;

@@ -23,7 +22,6 @@ namespace Cap.Consistency.Kafka
_logger = loggerFactory.CreateLogger(nameof(KafkaProducerClient));
}


public Task SendAsync(string topic, string content) {
var config = new Dictionary<string, object> { { "bootstrap.servers", _options.BrokerUrlList } };
try {
@@ -42,4 +40,4 @@ namespace Cap.Consistency.Kafka
}
}
}
}
}

+ 2
- 5
src/Cap.Consistency.Kafka/KafkaTopicAttribute.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cap.Consistency.Abstractions;
using Cap.Consistency.Abstractions;

namespace Cap.Consistency.Kafka
{
@@ -31,4 +28,4 @@ namespace Cap.Consistency.Kafka
return Name;
}
}
}
}

+ 2
- 8
src/Cap.Consistency.Kafka/Microsoft.Extensions.DependencyInjection/ConsistencyBuilderExtensions.cs View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cap.Consistency;
using Cap.Consistency.Consumer;
using Cap.Consistency.Consumer;
using Cap.Consistency.Kafka;
using Cap.Consistency.Producer;

@@ -11,13 +7,11 @@ namespace Microsoft.Extensions.DependencyInjection
public static class ConsistencyBuilderExtensions
{
public static ConsistencyBuilder AddKafka(this ConsistencyBuilder builder) {

builder.Services.AddSingleton<IConsumerClientFactory, KafkaConsumerClientFactory>();

builder.Services.AddTransient<IProducerClient, KafkaProducerClient>();

return builder;
}

}
}
}

+ 2
- 4
src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClient.cs View File

@@ -1,6 +1,5 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Cap.Consistency.Consumer;
using Cap.Consistency.Infrastructure;
using RabbitMQ.Client;
@@ -39,8 +38,7 @@ namespace Cap.Consistency.RabbitMQ
}

public void Listening(TimeSpan timeout) {

// Task.Delay(timeout).Wait();
// Task.Delay(timeout).Wait();

var consumer = new EventingBasicConsumer(_channel);
consumer.Received += OnConsumerReceived;
@@ -69,4 +67,4 @@ namespace Cap.Consistency.RabbitMQ
MessageReceieved?.Invoke(sender, message);
}
}
}
}

+ 2
- 5
src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClientFactory.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cap.Consistency.Consumer;
using Cap.Consistency.Consumer;

namespace Cap.Consistency.RabbitMQ
{
@@ -11,4 +8,4 @@ namespace Cap.Consistency.RabbitMQ
return new RabbitMQConsumerClient(groupId, clientHostAddress);
}
}
}
}

+ 2
- 6
src/Cap.Consistency.RabbitMQ/RabbitMQProducerClient.cs View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text;
using System.Threading.Tasks;
using Cap.Consistency.Infrastructure;
using Cap.Consistency.Producer;
@@ -12,7 +10,6 @@ namespace Cap.Consistency.RabbitMQ
{
public class RabbitMQProducerClient : IProducerClient
{

private readonly ConsistencyOptions _options;
private readonly ILogger _logger;

@@ -28,7 +25,6 @@ namespace Cap.Consistency.RabbitMQ
channel.ExchangeDeclare(exchange: "topic_logs",
type: "topic");


var body = Encoding.UTF8.GetBytes(content);
channel.BasicPublish(exchange: "topic_logs",
routingKey: topic,
@@ -39,4 +35,4 @@ namespace Cap.Consistency.RabbitMQ
}
}
}
}
}

+ 3
- 9
src/Cap.Consistency/Consumer/IConsumerHandler.cs View File

@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cap.Consistency.Infrastructure;

namespace Cap.Consistency.Consumer
namespace Cap.Consistency.Consumer
{
public interface IConsumerHandler: ITopicRouteHandler
public interface IConsumerHandler : ITopicServer
{

}
}
}

+ 2
- 6
test/Cap.Consistency.EntityFrameworkCore.Test/DefaultPocoTest.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Cap.Consistency.Infrastructure;
using Cap.Consistency.Store;
using Microsoft.AspNetCore.Builder.Internal;
@@ -54,6 +51,5 @@ namespace Cap.Consistency.EntityFrameworkCore.Test
operateResult = await messageManager.DeleteAsync(user);
Assert.True(operateResult.Succeeded);
}

}
}
}

+ 3
- 4
test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreTest.cs View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cap.Consistency.Infrastructure;
@@ -27,7 +26,8 @@ namespace Cap.Consistency.EntityFrameworkCore.Test

public class ApplicationDbContext : ConsistencyDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) {
}
}

[ConditionalFact]
@@ -75,7 +75,6 @@ namespace Cap.Consistency.EntityFrameworkCore.Test
Assert.True(result.Succeeded);
}


public ConsistencyDbContext CreateContext(bool delete = false) {
var db = DbUtil.Create<ConsistencyDbContext>(_fixture.ConnectionString);
if (delete) {
@@ -101,4 +100,4 @@ namespace Cap.Consistency.EntityFrameworkCore.Test
}

public class ApplicationMessage : ConsistencyMessage { }
}
}

+ 0
- 1
test/Cap.Consistency.EntityFrameworkCore.Test/MessageStoreWithGenericsTest.cs View File

@@ -3,7 +3,6 @@ using Cap.Consistency.Infrastructure;
using Cap.Consistency.Store;
using Cap.Consistency.Test;
using Microsoft.AspNetCore.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Xunit;



+ 1
- 2
test/Cap.Consistency.Test/ConsistencyMessageManagerTest.cs View File

@@ -64,8 +64,7 @@ namespace Cap.Consistency.Test
store.VerifyAll();
}

public ConsistencyMessageManager TestConsistencyMessageManager(IConsistencyMessageStore store = null)
{
public ConsistencyMessageManager TestConsistencyMessageManager(IConsistencyMessageStore store = null) {
store = store ?? new Mock<IConsistencyMessageStore>().Object;
var mockLogger = new Mock<ILogger<ConsistencyMessageManager>>().Object;
var manager = new ConsistencyMessageManager(store, null, mockLogger);


Loading…
Cancel
Save