Foundatio.RabbitMQ 11.0.6

Prefix Reserved
dotnet add package Foundatio.RabbitMQ --version 11.0.6                
NuGet\Install-Package Foundatio.RabbitMQ -Version 11.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Foundatio.RabbitMQ" Version="11.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Foundatio.RabbitMQ --version 11.0.6                
#r "nuget: Foundatio.RabbitMQ, 11.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Foundatio.RabbitMQ as a Cake Addin
#addin nuget:?package=Foundatio.RabbitMQ&version=11.0.6

// Install Foundatio.RabbitMQ as a Cake Tool
#tool nuget:?package=Foundatio.RabbitMQ&version=11.0.6                

FoundatioFoundatio

Build status NuGet Version feedz.io Discord

Pluggable foundation blocks for building loosely coupled distributed apps.

Includes implementations in Redis, Azure, AWS, RabbitMQ, Kafka 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 (another great product) but found Azure support lacking at the time and local set up a pain (for in memory). 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. KafkaMessageBus: A Kafka implementation.
  5. 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

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Foundatio.RabbitMQ:

Repository Stars
exceptionless/Exceptionless
Exceptionless application
Version Downloads Last updated
11.0.6 68 11/26/2024
11.0.5 911 9/28/2024
11.0.4 100 9/27/2024
11.0.2 269 8/31/2024
11.0.0 101 8/31/2024
10.7.1 7,339 3/27/2024
10.7.0 5,845 1/5/2024
10.6.1 3,853 6/23/2023
10.6.0 11,228 1/1/2023
10.5.0 6,590 5/18/2022
10.4.0 3,293 3/8/2022
10.3.0 1,182 1/20/2022
10.2.2 3,335 9/23/2021
10.2.0 3,966 8/6/2021
10.0.2 10,824 1/20/2021
10.0.0 4,108 9/16/2020
10.0.0-beta9 1,514 8/25/2020
10.0.0-beta8 876 8/3/2020
10.0.0-beta7 881 7/29/2020
10.0.0-beta6 1,345 7/8/2020
10.0.0-beta5 1,063 6/20/2020
10.0.0-beta4 1,468 6/14/2020
10.0.0-beta3 939 6/6/2020
10.0.0-beta2 878 5/26/2020
10.0.0-beta10 881 9/15/2020
10.0.0-beta1 913 5/26/2020
9.0.0 4,750 1/16/2020
8.1.1527 3,332 8/30/2019
8.1.1517 3,810 5/14/2019
8.1.1512 2,291 4/16/2019
8.0.1503 1,317 2/24/2019
8.0.1501 1,153 2/22/2019
7.0.1488 1,991 9/7/2018
7.0.1484 1,599 5/9/2018
6.0.1466 1,673 11/30/2017
5.1.1454 1,674 5/5/2017
5.0.1336 1,669 3/14/2017
5.0.1334 1,723 3/13/2017
5.0.1331 1,722 3/12/2017
5.0.1329-pre 1,360 3/12/2017
5.0.1328-pre 1,381 3/12/2017
5.0.1327-pre 1,387 3/12/2017
5.0.1326-pre 1,414 3/12/2017
5.0.1324-pre 1,416 3/12/2017
4.3.1323-pre 1,432 3/11/2017
4.3.1317 1,659 2/23/2017
4.3.1316 1,592 2/22/2017
4.3.1315 1,589 2/22/2017
4.3.1314 1,597 2/20/2017
4.3.1312 1,627 2/20/2017
4.3.1311-pre 1,404 2/20/2017
4.3.1307 1,589 2/16/2017
4.3.1306 1,599 2/15/2017
4.3.1305 1,639 2/15/2017
4.3.1304-pre 1,363 2/15/2017
4.3.1303-pre 1,352 2/14/2017
4.3.1301 1,575 2/14/2017
4.3.1299 1,641 2/14/2017
4.3.1293 1,659 2/12/2017
4.3.1292 1,651 2/10/2017
4.3.1291 1,611 2/10/2017
4.3.1290 1,622 2/10/2017
4.3.1289 1,653 2/9/2017
4.3.1288 1,671 2/9/2017
4.3.1286 1,653 2/8/2017
4.3.1282 1,662 2/5/2017
4.3.1281 1,751 2/5/2017
4.3.1280 1,660 2/5/2017
4.3.1276-pre 1,471 2/5/2017
4.3.1177-pre 1,343 9/2/2016
4.3.1164-pre 1,337 8/21/2016
4.2.1205-pre 1,671 9/19/2016
4.2.1183 1,524 9/9/2016
4.2.1179 1,499 9/8/2016
4.2.1176 1,512 9/2/2016
4.2.1172 1,493 9/1/2016
4.2.1171-pre 1,342 9/1/2016
4.2.1169 1,526 8/22/2016
4.2.1167-pre 1,316 8/22/2016
4.2.1166-pre 1,332 8/22/2016
4.2.1161 1,509 8/10/2016
4.2.1156-pre 1,311 8/2/2016
4.2.1155 1,536 8/1/2016
4.2.1150 1,518 7/20/2016
4.2.1149-pre 1,365 7/19/2016
4.2.1148-pre 1,326 7/19/2016
4.2.1147-pre 1,359 7/19/2016
4.2.1146-pre 1,357 7/19/2016
4.2.1137 1,545 7/19/2016
4.2.1129-pre 1,307 7/19/2016
4.2.1128-pre 1,345 7/19/2016
4.2.1127-pre 1,333 7/19/2016
4.2.1126-pre 1,338 7/19/2016
4.2.1125-pre 1,339 7/19/2016
4.2.1123-pre 1,320 7/19/2016
4.2.1119-pre 1,315 7/18/2016
4.2.1113-pre 1,325 7/16/2016
4.2.1108-pre 1,389 7/15/2016
4.2.1107-pre 1,364 7/15/2016