最近这段时间接触了些新的东西:Orleans框架。今天是春节前最后一天班,把我这段时间学习的东西总结一下分享给大家。
一、什么是Orleans
(文档地址。这里我就直接翻译官方的介绍,有点地方翻译的有些蹩脚大家见谅。后面在使用场景上我会结合我们自己项目来说)
A straightforward approach to building distributed, high-scale applications in .NET
一个简单直接的大规模分布式的.Net应用
Orleans is a framework that provides a straightforward approach to building distributed high-scale computing applications, without the need to learn and apply complex concurrency or other scaling patterns. It was created by Microsoft Research and designed for use in the cloud.
Orleans 是一个提供简单直接的大规模分布式的计算应用,而不需要去了解复杂的高并发和其他相关。由微软研究和设计用于云端。
Orleans has been used extensively in Microsoft Azure by several Microsoft product groups, most notably by 343 Industries as a platform for all of Halo 4 and Halo 5 cloud services, as well as by a growing number of other companies.
Orleans 已经被几个微软的产品组用在Microsoft Azure云。值得一提的就是343公司《光环4》和《光环5》的云平台服务,和越来越多的其他公司
Orleans as a Stateful Middle Tier
Orleans 作为一个有状态的中间层
Orleans provides an intuitive way of building a stateful middle tier, where various business logic entities appear as sea of isolated globally addressable .NET objects (grains) of different application defined types distributed across a cluster of servers (silos).
Orleans提供一个直观的方式建造一个有状态的中间层,各种业务逻辑对象存在于一个可以全局定位的独立的不通应用类型.NET对象 的集群海洋里。
二、用法
public interface IMyGrain : IGrainWithStringKey
{
Task<string> SayHello(string name);
}
The implementation is executed inside the Orleans framework:
实现是在Orleans框架里执行的
public class MyGrain : IMyGrain
{
public Task<string> SayHello(string name)
{
return Task.FromResult($"Hello {name}");
}
}
You can then invoke the grain by obtaining a proxy object (a grain reference), and calling the methods:
你可以通过获取一个代理对象(一个谷物的接口)触发一个grain,并且掉用他的方法。
var grain = GrainClient.GrainFactory.GetGrain<IMyGrain>("grain1");
await grain.SayHello("World");
三、总结
Orleans就是一个把高并发等复杂的细节隐藏在后面的分布式框架,让我们能快速的实现一个大规模可扩展的分布式应用。
在Orleans编程的世界里,你最主要有两个关注点:
1、定义接口
2、所有方法皆异步
当然还有很多其他的feature和注意点,需要我们去探索