-
Notifications
You must be signed in to change notification settings - Fork 923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这是我写的一个SurgingDemo,还烦请问使用姿势是否正确 #54
Comments
姿势很正确,如果有缓存拦截的demo就更好了 |
@fanliang11 其实我想把缓存拦截的写上去,刚在群里也看到了,但是有点小疑问,对“GetUserName_name_{0}“ 这个参数不理解 [InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", "GetUserName_name_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)] |
1.传递的方法参数如果是model类型,就需要设置 [CacheKey(1)]来标识缓存key, 比如传递UserModel, [ProtoContract]
public class UserModel
{
[CacheKey(1)]
public int UserId { get; set; }
[CacheKey(2)]
public string Name { get; set; }
public int Age { get; set; }
} |
哎呀,我好像理解错了,抱歉。 |
我配的缓存拦截好像没起作用,没写入到Redis,是不是哪里还需要配置?拦截器配置我看到示例是放到Client 和ApiGateway IUserService
[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis, Time = 480)]
Task<UserDto> GetUserById(Int64 id);
[InterceptMethod(CachingMethod.Put, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]
Task<Boolean> UpdateUser(UserDto user);
[InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]
Task<Boolean> DeleteUser(Int64 userId);
UserDto
[ProtoContract]
public class UserDto
{
[ProtoMember(1)]
[CacheKey(1)]
public long Id { get; set; }
[ProtoMember(2)]
public string PhoneNumber { get; set; }
[ProtoMember(3)]
public string Name { get; set; }
} |
你需要设置RequestCacheEnabled = true和 option.AddClientIntercepted(typeof(CacheProviderInterceptor)); [Command(Strategy = StrategyType.Failover, RequestCacheEnabled = true, InjectionNamespaces = new string[] { "Surging.IModuleServices.Common" })] builder.AddMicroService(option =>
{
option.AddClient();
option.AddClientIntercepted(typeof(CacheProviderInterceptor));
//option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
option.UseDotNettyTransport();
option.UseRabbitMQTransport();
//option.UseKafkaMQTransport(kafkaOption =>
//{
// kafkaOption.Servers = "127.0.0.1";
//});
//option.UseProtoBufferCodec();
option.UseMessagePackCodec();
builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
}); |
缓存还是没起作用,是写入到Redis没错吧。 [Service(Date = "2018-3-2", Director = "Bill", Name = "获取用户信息")]
[Command(Strategy = StrategyType.Failover, RequestCacheEnabled = true, InjectionNamespaces = new string[] { "Bill.Demo.IModuleServices.Users" })]
[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis, Time = 480)]
Task<UserDto> GetUserById(Int64 id); |
已修复不能获取服务条目的BUG,请下载最新的代码 |
你好,更新了代码出现了新的问题。Surging提供的Client跑起来没问题,但是在我的Web客户端有问题, 发现使用ServiceHostBuilder 使用了 .UseServiceCache()
.UseProxy()
.UseLog4net()
.UseClient() 还麻烦看看Web下应该如何配置 |
不要用.UseServiceCache(),请更新master版本,请用原来的配置 |
更新了的。在 WebHostBuilder 使用不了 .UseServiceCache().UseProxy().UseLog4net().UseClient() Surging.Services.Client 、Bill.Demo.Web 两者配置有些不同,Bill.Demo.Web我是根据Surging.ApiGateway来配的 |
用你原来的配置。不要去更改任何配置 |
作者你好,
这是我写的一个SurgingDemo,还烦请问使用姿势是否正确 -_-...
如果用的不对的地方,还请指正,谢谢
本示例git surging 到本地,再另外新建的Demo,通过引用Surging项目到Demo来实现,这样加深学习。
ORM使用的是Dapper
SurgingDemo
The text was updated successfully, but these errors were encountered: