Foundatio

授权协议 Apache-2.0 License
开发语言 C/C++
所属分类 程序开发、 日志工具(Logging)
软件类型 开源软件
地区 不详
投 递 者 越扬
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Foundatio

Build statusNuGet Versionfeedz.ioDiscord

Pluggable foundation blocks for building loosely coupled distributed apps.

Includes implementations in Redis, Azure, AWS, RabbitMQ and in memory (for development).

Why Foundatio?

When building several big cloud applications we found a lack of great solutions (that's not to say there isn't solutions out there) for many key pieces to building scalable distributed applications while keeping the development experience simple. Here are a few examples of why we built and use Foundatio:

  • Wanted to build against abstract interfaces so that we could easily change implementations.
  • Wanted the blocks to be dependency injection friendly.
  • Caching: We were initially using an open source Redis cache client but then it turned into a commercial product with high licensing costs. Not only that, but there weren't any in memory implementations so every developer was required to set up and configure Redis.
  • Message Bus: We initially looked at NServiceBus (great product) but it had high licensing costs (they have to eat too) but was not OSS friendly. We also looked into MassTransit but found Azure support lacking and local set up a pain. We wanted a simple message bus that just worked locally or in the cloud.
  • Storage: We couldn't find any existing project that was decoupled and supported in memory, file storage or Azure Blob Storage.

To summarize, if you want pain free development and testing while allowing your app to scale, use Foundatio!

Implementations

Getting Started (Development)

Foundatio can be installed via the NuGet package manager. If you need help, please open an issue or join our Discord chat room. We’re always here to help if you have any questions!

This section is for development purposes only! If you are trying to use the Foundatio libraries, please get them from NuGet.

  1. You will need to have Visual Studio Code installed.
  2. Open the Foundatio.sln Visual Studio solution file.

Using Foundatio

The sections below contain a small subset of what's possible with Foundatio. We recommend taking a peek at the source code for more information. Please let us know if you have any questions or need assistance!

Caching

Caching allows you to store and access data lightning fast, saving you exspensive operations to create or get data. We provide four different cache implementations that derive from the ICacheClient interface:

  1. InMemoryCacheClient: An in memory cache client implementation. This cache implementation is only valid for the lifetime of the process. It's worth noting that the in memory cache client has the ability to cache the last X items via the MaxItems property. We use this in Exceptionless to only keep the last 250 resolved geoip results.
  2. HybridCacheClient: This cache implementation uses both an ICacheClient and the InMemoryCacheClient and uses an IMessageBus to keep the cache in sync across processes. This can lead to huge wins in performance as you are saving a serialization operation and a call to the remote cache if the item exists in the local cache.
  3. RedisCacheClient: A Redis cache client implementation.
  4. RedisHybridCacheClient: An implementation of HybridCacheClient that uses the RedisCacheClient as ICacheClient and the RedisMessageBus as IMessageBus.
  5. ScopedCacheClient: This cache implementation takes an instance of ICacheClient and a string scope. The scope is prefixed onto every cache key. This makes it really easy to scope all cache keys and remove them with ease.

Sample

using Foundatio.Caching;

ICacheClient cache = new InMemoryCacheClient();
await cache.SetAsync("test", 1);
var value = await cache.GetAsync<int>("test");

Queues

Queues offer First In, First Out (FIFO) message delivery. We provide four different queue implementations that derive from the IQueue interface:

  1. InMemoryQueue: An in memory queue implementation. This queue implementation is only valid for the lifetime of the process.
  2. RedisQueue: An Redis queue implementation.
  3. AzureServiceBusQueue: An Azure Service Bus Queue implementation.
  4. AzureStorageQueue: An Azure Storage Queue implementation.
  5. SQSQueue: An AWS SQS implementation.

Sample

using Foundatio.Queues;

IQueue<SimpleWorkItem> queue = new InMemoryQueue<SimpleWorkItem>();

await queue.EnqueueAsync(new SimpleWorkItem {
    Data = "Hello"
});

var workItem = await queue.DequeueAsync();

Locks

Locks ensure a resource is only accessed by one consumer at any given time. We provide two different locking implementations that derive from the ILockProvider interface:

  1. CacheLockProvider: A lock implementation that uses cache to communicate between processes.
  2. ThrottlingLockProvider: A lock implementation that only allows a certain amount of locks through. You could use this to throttle api calls to some external service and it will throttle them across all processes asking for that lock.
  3. ScopedLockProvider: This lock implementation takes an instance of ILockProvider and a string scope. The scope is prefixed onto every lock key. This makes it really easy to scope all locks and release them with ease.

It's worth noting that all lock providers take a ICacheClient. This allows you to ensure your code locks properly across machines.

Sample

using Foundatio.Lock;

ILockProvider locker = new CacheLockProvider(new InMemoryCacheClient(), new InMemoryMessageBus());
var testLock = await locker.AcquireAsync("test");
// ...
await testLock.ReleaseAsync();

ILockProvider throttledLocker = new ThrottlingLockProvider(new InMemoryCacheClient(), 1, TimeSpan.FromMinutes(1));
var throttledLock = await throttledLocker.AcquireAsync("test");
// ...
await throttledLock.ReleaseAsync();

Messaging

Allows you to publish and subscribe to messages flowing through your application. We provide four different message bus implementations that derive from the IMessageBus interface:

  1. InMemoryMessageBus: An in memory message bus implementation. This message bus implementation is only valid for the lifetime of the process.
  2. RedisMessageBus: A Redis message bus implementation.
  3. RabbitMQMessageBus: A RabbitMQ implementation.
  4. AzureServiceBusMessageBus: An Azure Service Bus implementation.

Sample

using Foundatio.Messaging;

IMessageBus messageBus = new InMemoryMessageBus();
await messageBus.SubscribeAsync<SimpleMessageA>(msg => {
  // Got message
});

await messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" });

Jobs

Allows you to run a long running process (in process or out of process) without worrying about it being terminated prematurely. We provide three different ways of defining a job, based on your use case:

  1. Jobs: All jobs must derive from the IJob interface. We also have a JobBase base class you can derive from which provides a JobContext and logging. You can then run jobs by calling RunAsync() on the job or by creating a instance of the JobRunner class and calling one of the Run methods. The JobRunner can be used to easily run your jobs as Azure Web Jobs.

Sample

using Foundatio.Jobs;

public class HelloWorldJob : JobBase {
  public int RunCount { get; set; }

  protected override Task<JobResult> RunInternalAsync(JobContext context) {
     RunCount++;
     return Task.FromResult(JobResult.Success);
  }
}
var job = new HelloWorldJob();
await job.RunAsync(); // job.RunCount = 1;
await job.RunContinuousAsync(iterationLimit: 2); // job.RunCount = 3;
await job.RunContinuousAsync(cancellationToken: new CancellationTokenSource(10).Token); // job.RunCount > 10;
  1. Queue Processor Jobs: A queue processor job works great for working with jobs that will be driven from queued data. Queue Processor jobs must derive from QueueJobBase<T> class. You can then run jobs by calling RunAsync() on the job or passing it to the JobRunner class. The JobRunner can be used to easily run your jobs as Azure Web Jobs.

Sample

using Foundatio.Jobs;

public class HelloWorldQueueJob : QueueJobBase<HelloWorldQueueItem> {
  public int RunCount { get; set; }

  public HelloWorldQueueJob(IQueue<HelloWorldQueueItem> queue) : base(queue) {}

  protected override Task<JobResult> ProcessQueueEntryAsync(QueueEntryContext<HelloWorldQueueItem> context) {
     RunCount++;

     return Task.FromResult(JobResult.Success);
  }
}

public class HelloWorldQueueItem {
  public string Message { get; set; }
}
// Register the queue for HelloWorldQueueItem.
container.AddSingleton<IQueue<HelloWorldQueueItem>>(s => new InMemoryQueue<HelloWorldQueueItem>());

// To trigger the job we need to queue the HelloWorldWorkItem message.
// This assumes that we injected an instance of IQueue<HelloWorldWorkItem> queue

IJob job = new HelloWorldQueueJob();
await job.RunAsync(); // job.RunCount = 0; The RunCount wasn't incremented because we didn't enqueue any data.

await queue.EnqueueAsync(new HelloWorldWorkItem { Message = "Hello World" });
await job.RunAsync(); // job.RunCount = 1;

await queue.EnqueueAsync(new HelloWorldWorkItem { Message = "Hello World" });
await queue.EnqueueAsync(new HelloWorldWorkItem { Message = "Hello World" });
await job.RunUntilEmptyAsync(); // job.RunCount = 3;
  1. Work Item Jobs: A work item job will run in a job pool among other work item jobs. This type of job works great for things that don't happen often but should be in a job (Example: Deleting an entity that has many children.). It will be triggered when you publish a message on the message bus. The job must derive from the WorkItemHandlerBase class. You can then run all shared jobs via JobRunner class. The JobRunner can be used to easily run your jobs as Azure Web Jobs.

Sample

using System.Threading.Tasks;
using Foundatio.Jobs;

public class HelloWorldWorkItemHandler : WorkItemHandlerBase {
  public override async Task HandleItemAsync(WorkItemContext ctx) {
    var workItem = ctx.GetData<HelloWorldWorkItem>();

    // We can report the progress over the message bus easily.
    // To receive these messages just inject IMessageSubscriber
    // and Subscribe to messages of type WorkItemStatus
    await ctx.ReportProgressAsync(0, "Starting Hello World Job");
    await Task.Delay(TimeSpan.FromSeconds(2.5));
    await ctx.ReportProgressAsync(50, "Reading value");
    await Task.Delay(TimeSpan.FromSeconds(.5));
    await ctx.ReportProgressAsync(70, "Reading value");
    await Task.Delay(TimeSpan.FromSeconds(.5));
    await ctx.ReportProgressAsync(90, "Reading value.");
    await Task.Delay(TimeSpan.FromSeconds(.5));

    await ctx.ReportProgressAsync(100, workItem.Message);
  }
}

public class HelloWorldWorkItem {
  public string Message { get; set; }
}
// Register the shared job.
var handlers = new WorkItemHandlers();
handlers.Register<HelloWorldWorkItem, HelloWorldWorkItemHandler>();

// Register the handlers with dependency injection.
container.AddSingleton(handlers);

// Register the queue for WorkItemData.
container.AddSingleton<IQueue<WorkItemData>>(s => new InMemoryQueue<WorkItemData>());

// The job runner will automatically look for and run all registered WorkItemHandlers.
new JobRunner(container.GetRequiredService<WorkItemJob>(), instanceCount: 2).RunInBackground();
// To trigger the job we need to queue the HelloWorldWorkItem message.
 // This assumes that we injected an instance of IQueue<WorkItemData> queue

 // NOTE: You may have noticed that HelloWorldWorkItem doesn't derive from WorkItemData.
 // Foundatio has an extension method that takes the model you post and serializes it to the
 // WorkItemData.Data property.
 await queue.EnqueueAsync(new HelloWorldWorkItem { Message = "Hello World" });

File Storage

We provide different file storage implementations that derive from the IFileStorage interface:

  1. InMemoryFileStorage: An in memory file implementation. This file storage implementation is only valid for the lifetime of the process.
  2. FolderFileStorage: An file storage implementation that uses the hard drive for storage.
  3. AzureFileStorage: An Azure Blob storage implementation.
  4. S3FileStorage: An AWS S3 file storage implementation.
  5. RedisFileStorage: An Redis file storage implementation.
  6. MinioFileStorage An Minio file storage implementation.
  7. AliyunFileStorage: An Aliyun file storage implementation.
  8. SshNetFileStorage: An SFTP file storage implementation.

We recommend using all of the IFileStorage implementations as singletons.

Sample

using Foundatio.Storage;

IFileStorage storage = new InMemoryFileStorage();
await storage.SaveFileAsync("test.txt", "test");
string content = await storage.GetFileContentsAsync("test.txt")

Metrics

We provide five implementations that derive from the IMetricsClient interface:

  1. InMemoryMetricsClient: An in memory metrics implementation.
  2. RedisMetricsClient: An Redis metrics implementation.
  3. StatsDMetricsClient: An statsd metrics implementation.
  4. MetricsNETClient: An Metrics.NET implementation.
  5. AppMetricsClient: An AppMetrics implementation.
  6. CloudWatchMetricsClient: An AWS CloudWatch implementation.

We recommend using all of the IMetricsClient implementations as singletons.

Sample

IMetricsClient metrics = new InMemoryMetricsClient();
metrics.Counter("c1");
metrics.Gauge("g1", 2.534);
metrics.Timer("t1", 50788);

Sample Application

We have both slides and a sample application that shows off how to use Foundatio.

Thanks to all the people who have contributed

contributors

  • 1 kvo 内部实现原理 a kvo 是基于runtime 机制实现的 b 当某个类的对象第一次被观察时 系统就会在运行期动态的创建该类的一个派生类 当这个派生类中重写基类中任何被观察的setterf setter方法 实现真正的通知机制 person ---》nskvonotifying_person) 2 是否可以把比较耗时的操作放在nsnotifaction中 如果在异步线程fade通知 那

  • Microsoft Windows Workflow Foundation (WWF) 是一个可扩展框架,用于在 Windows 平台上开发工作流解决方案。作为即将问世的 Microsoft WinFX 的组成部分,Windows Workflow Foundation 同时提供了 API 和一些工具,用于开发和执行基于工作流的应用程序。Windows Workflow Foundation 提供

 相关资料
  • 问题内容: 我已经搜索并搜索了所有内容,当然也查阅了相关文档,但是关于Foundation 4的一些事情,我似乎无法理解,涉及Sass的转换方式。 我已使用create project命令使用Compass设置了Foundation,因此Sass正在运行。app.scss文件正在导入“设置”和“基础”,并使用“ watch”进行编译。 我的问题的前半部分:我了解app.css是从gem中的组件文件

  • 本文向大家介绍Team Foundation Server 安装或设置,包括了Team Foundation Server 安装或设置的使用技巧和注意事项,需要的朋友参考一下 示例 有关设置或安装tfs的详细说明。

  • 我正在遵循一位微软云倡导者的教程来设置Azure DevOps和Jenkins集成:https://medium.com/@bbenz/azure-devops-and-jenkins-in-perfect-harmony-8C92FF980723。 当Jenkins成功完成构建时,我无法触发新的Azure DevOps管道发布。 在Jenkins Team Foundation Server(T

  • 我在一个跨度上有一个通过foundation 5的工具提示,如下所示: 这个很管用。然而,我想做的只是在用户单击span(而不是悬停)时显示工具提示。然后单击“关闭”按钮时关闭。当我添加时,我可以做到一半,但这增加了两个工具提示,当我悬停时仍然会感到失望。 任何想法都将不胜感激。Foundation5没有一些交互式内容的弹出,这似乎很奇怪。 谢谢!

  • 问题内容: 我目前正在使用Java进行Selenium Automation,以满足我对测试自动化的需求。到目前为止,我将TestNg用于报告。 早期没有使用任何报告工具进行集成,因此我在JIRA中手动更新了TestNg结果。 客户最近介绍了Visaul Studio Team Foundation Server。我想在这方面了解以下内容。 我们如何在TFS中更新Selenium-TestNG上的

  • 问题内容: 题 是否有可能重复雨燕数值桥接基金会:■ 引用类型,例如,,和类型?具体来说,复制下面介绍的自动预分配桥接。 这种解决方案的预期用法示例: 背景 一些本机Swift数(值)类型可以自动桥接到(引用)类型: 迅数字结构类型的实例,例如,, ,,和,不能由所表示的 类型,因为仅代表一个类类型的实例。但是,启用桥接到时,可以将Swift数值分配给常量和类型变量, 作为 类的 桥接实例。 …

  • 问题内容: 我正在尝试按照有关“使用Xcode 3.2开发PyObjC”的可接受答案的说明进行操作。由于我没有足够的代表对实际问题发表评论,因此我将在此处重新发布它们: 这是让PyObjC在Snow Leopard中工作的方法: 使用Finder,以访客身份访问并连接到http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/。 然后,我在本

  • 问题内容: 我正在使用Zurb的Foundation框架修改应用程序以实现响应性和AngularJS。存在一个错误,即根据Foundation的响应规则隐藏/显示具有的表中显示的数据带有的错误。不幸的是,当角度模型更新时,Foundation不会重新流送新渲染的DOM。 我尝试使用 在广泛的Google搜索中发现的方法,但是实际上并没有触发响应折叠表的重排。我还添加了一条指令来触发一个简单的指令,