Skip to content

Commit

Permalink
Merge pull request #3 from dotnetcore/master
Browse files Browse the repository at this point in the history
merge from origin
  • Loading branch information
wadnm committed Dec 26, 2017
2 parents 8503dd6 + a887fb7 commit 8a89fa7
Show file tree
Hide file tree
Showing 52 changed files with 724 additions and 99 deletions.
2 changes: 2 additions & 0 deletions README.EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var host = new ServiceHostBuilder()
.UseServer("127.0.0.1", 98)
//.UseServer("127.0.0.1", 98,“true”) //Automatically generate Token
//.UseServer("127.0.0.1", 98,“123456789”) //Fixed password Token
.UseLog4net("Configs/log4net.config") //Use log4net to generate the log
.UseLog4net() //Use log4net to generate the log
.UseStartup<Startup>()
.Build();

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ var host = new ServiceHostBuilder()
});
})
.SubscribeAt() //消息订阅
.UseServer("127.0.0.1", 98)
//.UseServer("127.0.0.1", 98)
//.UseServer("127.0.0.1", 98,“true”) //自动生成Token
//.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
.UseServer(options=> {
options.Ip = "127.0.0.1";
options.Port = 98;
options.ExecutionTimeoutInMilliseconds = 30000; //执行超时时间
options.Strategy=(int)StrategyType.Failover; //容错策略使用故障切换
options.RequestCacheEnabled=true; //开启缓存(只有通过接口代理远程调用,才能启用缓存)
options.Injection="return null"; //注入方式
options.InjectionNamespaces= new string[] { "Surging.IModuleServices.Common" }); //脚本注入使用的命名空间
options.BreakeErrorThresholdPercentage="50"; //错误率达到多少开启熔断保护
options.BreakeSleepWindowInMilliseconds=60000; //熔断多少毫秒后去尝试请求
options.BreakerForceClosed=false; //是否强制关闭熔断
options.BreakerRequestVolumeThreshold = 20;//10秒钟内至少多少请求失败,熔断器才发挥起作用
options.MaxConcurrentRequests== 100000;//支持最大并发
})
.UseLog4net("Configs/log4net.config") //使用log4net记录日志
.UseLog4net() //使用log4net记录日志
.UseStartup<Startup>()
.Build();

Expand Down
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#### Surging.Core.Log4net 0.4.8 December 17 2017
- Add logs based on log4net

#### Surging.Core.Zookeeper 0.4.9 December 16 2017
- Fixed using zookeeper registry did not register fault tolerance rules

#### 0.4.8 December 10 2017
- First public release
74 changes: 74 additions & 0 deletions docs/docs.en/Cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
surging is based on .net core language high-performance distributed microservices framework,
Clients can enable caching to intercept client calls to the server,The following example enables caching

Code Examples
=============

Clients enable caching through the following configuration:
```c#
{
"CachingSettings": [
{
"Id": "SurgingCache",
"Class": "Surging.Core.Caching.RedisCache.RedisContext,Surging.Core.Caching",
"Properties": [
{
"Name": "appRuleFile",
"Ref": "rule"
},
{
"Name": "dataContextPool",
"Ref": "ddls_sample",
"Maps": [
{
"Name": "Redis",
"Properties": [
{
"value": "127.0.0.1:6379::1"
}
]
}
]
},
{
"Name": "defaultExpireTime",
"value": "120"
},
{
"Name": "connectTimeout",
"Value": "120"
},
{
"Name": "minSize",
"Value": "1"
},
{
"Name": "maxSize",
"Value": "10"
}
]
}
]
}
```
* The configuration section "CachingSettings" property "Id" is the ICacheProvider instance ID
* Configuration section "Maps" property "Name" is what cache
* Configuration section "Maps" property Properties is a cache server list
* Configuration section "Properties" property "defaultExpireTime" value of 120 is the cache default lost effective time is 120 seconds
* Configuration section "Properties" property "connectTimeout" value of 120 is connection cache server Timeout time is 120 seconds
* Configuration section "Properties" property "minSize" value of 1 is the minimum thread pool is 1
* Configuration section "Properties" property "maxSize" value of 10 is the maximum thread pool is 10

Open the cache can be In the interface method attribute "Command" property RequestCacheEnabled is set to true:
```c#
[ServiceBundle("api/{Service}")]
public interface IUserService :Surging.Core.CPlatform.Ioc.IServiceKey
{
[Command(RequestCacheEnabled =true)]
Task<string> SayHello(string username);
}
```
## Next steps

* [How to cache interception]

51 changes: 28 additions & 23 deletions docs/docs.en/ConfigMicroservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,35 @@ Add the following configuration to main program "main":
```c#
//If do not add UseProtoBufferCodec or UseMessagePackCodec, the default json.net
var host = new ServiceHostBuilder()
.RegisterServices(builder =>
{
builder.AddMicroService(option =>
{
option.AddServiceRuntime();//
//option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181")); //Use Zookeeper Manage
option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));//Use Consul Manage
option.UseDotNettyTransport();//Use DotNetty Transport
option.UseRabbitMQTransport();//Use Rabbitmq Transport
option.AddRabbitMQAdapt();//Based on rabbitmq consumer service adapter
//option.UseProtoBufferCodec();//Based on protobuf serialization codec
option.UseMessagePackCodec();//Based on messagepack serialization codec
builder.Register(p => new CPlatformContainer(ServiceLocator.Current));//Initialize the injection container
});
})
.SubscribeAt() //News subscription
.UseServer("127.0.0.1", 98)
.RegisterServices(builder =>
{
builder.AddMicroService(option =>
{
option.AddServiceRuntime();//
//option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));//Use Zookeeper Manage
option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));//Use Consul Manage
option.UseDotNettyTransport();//Use DotNetty Transport
option.UseRabbitMQTransport();//Use Rabbitmq Transport
option.AddRabbitMQAdapt();//Based on rabbitmq consumer service adapter
//option.UseProtoBufferCodec();//Based on protobuf serialization codec
option.UseMessagePackCodec();//Based on messagepack serialization codec
builder.Register(p => new CPlatformContainer(ServiceLocator.Current));//Initialize the injection container
});
})
.SubscribeAt() //News subscription
.UseServer("127.0.0.1", 98)
//.UseServer("127.0.0.1", 98,“true”) //Token automatically generated
//.UseServer("127.0.0.1", 98,“123456789”) //Fixed password token
.UseStartup<Startup>()
.Build();
.UseLog4net("Configs/log4net.config") //Use log4net to generate the log
.UseLog4net() //Use log4net to generate the log
.UseStartup<Startup>()
.Build();

using (host.Run())
{
Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
}
using (host.Run())
{
Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
}

```
Client how to configure
=============
Expand All @@ -55,6 +58,8 @@ var host = new ServiceHostBuilder()
});
})
.UseClient()
.UseLog4net("Configs/log4net.config") //Use log4net to generate the log
.UseLog4net() //Use log4net to generate the log
.UseStartup<Startup>()
.Build();

Expand Down
Binary file added logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Surging.ApiGateway/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Surging.Core.DotNetty;
using Surging.Core.ProxyGenerator;
using Surging.Core.System.Intercept;
//using Surging.Core.Zookeeper;
//using Surging.Core.Zookeeper.Configurations;
using System;

Expand Down
11 changes: 10 additions & 1 deletion src/Surging.ApiGateway/Surging.ApiGateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<UserSecretsId>aspnet-Surging.ApiGateway-147A234E-A922-4E6A-89B8-DCC64AEA96EE</UserSecretsId>
<ServerGarbageCollection>false</ServerGarbageCollection> </PropertyGroup>
<ServerGarbageCollection>false</ServerGarbageCollection>
<Version>0.4.8</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
<Company />
<Description>surging is a distributed micro service framework that provides high-performance RPC remote service calls, using Zookeeper, Consul as the registration center for surging services, integrating hash, random, polling as a load balancing algorithm, RPC integration using the netty framework, Using asynchronous transmission. Use json.net, protobuf, messagepack for serialization Codec</Description>
<Copyright>Copyright © fanly All Rights Reserved.</Copyright>
<PackageLicenseUrl>https://github.com/dotnetcore/surging/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/dotnetcore/surging</PackageProjectUrl>
<PackageTags>MicroService surging</PackageTags> </PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.6.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>0.4.8</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
<Company />
<Description>surging is a distributed micro service framework that provides high-performance RPC remote service calls, using Zookeeper, Consul as the registration center for surging services, integrating hash, random, polling as a load balancing algorithm, RPC integration using the netty framework, Using asynchronous transmission. Use json.net, protobuf, messagepack for serialization Codec</Description>
<Copyright>Copyright © fanly All Rights Reserved.</Copyright>
<PackageLicenseUrl>https://github.com/dotnetcore/surging/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/dotnetcore/surging</PackageProjectUrl>
<PackageTags>MicroService surging</PackageTags>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 19 additions & 2 deletions src/Surging.Core/Surging.Core.CPlatform/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Surging.Core.CPlatform.Configurations;
using Surging.Core.CPlatform.DependencyResolution;
using Surging.Core.CPlatform.Runtime.Client.Address.Resolvers.Implementation.Selectors.Implementation;
using Surging.Core.CPlatform.Utilities;
Expand All @@ -13,9 +14,13 @@ namespace Surging.Core.CPlatform
{
public class AppConfig
{
internal static IConfigurationRoot Configuration { get; set; }

#region 字段
private static AddressSelectorMode _loadBalanceMode=AddressSelectorMode.Polling;
private static SurgingServerOptions _serverOptions=new SurgingServerOptions();
#endregion

internal static IConfigurationRoot Configuration { get; set; }

public static AddressSelectorMode LoadBalanceMode
{
get
Expand All @@ -34,5 +39,17 @@ internal set
_loadBalanceMode = value;
}
}

public static SurgingServerOptions ServerOptions
{
get
{
return _serverOptions;
}
internal set
{
_serverOptions = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Surging.Core.CPlatform.Support;
using System;
using System.Collections.Generic;
using System.Text;

namespace Surging.Core.CPlatform.Configurations
{
public class SurgingServerOptions: ServiceCommand
{
public string Ip { get; set; }

public int Port { get; set; }

public string token { get; set; } = "True";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Surging.Core.CPlatform.Messages;
using System;
using System.Collections.Generic;
using System.Text;

namespace Surging.Core.CPlatform.Messages
{
public class MessagePackTransportMessageType
{
public static string remoteInvokeResultMessageTypeName= typeof(RemoteInvokeResultMessage).FullName;

public static string remoteInvokeMessageTypeName = typeof(RemoteInvokeMessage).FullName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public TransportMessage(object content)
/// <returns>如果是则返回true,否则返回false。</returns>
public bool IsInvokeMessage()
{
return ContentType == typeof(RemoteInvokeMessage).FullName;
return ContentType == MessagePackTransportMessageType.remoteInvokeMessageTypeName;
}

/// <summary>
Expand All @@ -50,7 +50,7 @@ public bool IsInvokeMessage()
/// <returns>如果是则返回true,否则返回false。</returns>
public bool IsInvokeResultMessage()
{
return ContentType == typeof(RemoteInvokeResultMessage).FullName;
return ContentType == MessagePackTransportMessageType.remoteInvokeResultMessageTypeName;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ ValueTask<AddressModel> IAddressSelector.SelectAsync(AddressSelectContext contex
if (context.Address == null)
throw new ArgumentNullException(nameof(context.Address));

var address = context.Address.ToArray();
if (!address.Any())
// var address = context.Address.ToArray();
if (context.Address.Count() == 0)
throw new ArgumentException("没有任何地址信息。", nameof(context.Address));

return address.Length == 1 ? new ValueTask<AddressModel>(address[0]) : new ValueTask<AddressModel>(SelectAsync(context));
return context.Address.Count() == 1 ? new ValueTask<AddressModel>(context.Address.First()) : new ValueTask<AddressModel>(SelectAsync(context));
}

#endregion Implementation of IAddressSelector
Expand Down
Loading

0 comments on commit 8a89fa7

Please sign in to comment.