项目作者: imranmomin

项目描述 :
Couchbase storage provider for Hangfire
高级语言: C#
项目地址: git://github.com/imranmomin/Hangfire.Couchbase.git
创建时间: 2018-04-03T14:31:36Z
项目社区:https://github.com/imranmomin/Hangfire.Couchbase

开源协议:MIT License

下载


Hangfire.Couchbase

Official Site
Latest version
Build status

This repo will add a Couchbase N1QL storage support to Hangfire - fire-and-forget, delayed and recurring tasks runner for .NET. Scalable and reliable background job runner. Supports multiple servers, CPU and I/O intensive, long-running and short-running jobs.

Installation

Hangfire.Couchbase is available as a NuGet package. Install it using the NuGet Package Console window:

  1. PM> Install-Package Hangfire.Couchbase

Usage

1. Using the ClientConfiguration to initialize the server
  1. ClientConfiguration configuration = new ClientConfiguration {
  2. BucketConfigs = new Dictionary<string, BucketConfiguration> {
  3. {"default", new BucketConfiguration {
  4. PoolConfiguration = new PoolConfiguration {
  5. MaxSize = 6,
  6. MinSize = 4,
  7. SendTimeout = 12000
  8. },
  9. DefaultOperationLifespan = 123,
  10. Password = "password",
  11. Username = "username",
  12. BucketName = "default"
  13. }}
  14. }
  15. };
  16. GlobalConfiguration.Configuration.UseCouchbaseStorage(configuration, "<defaultBucket>");

If you’re using Couchbase 5.0+, then you’ll need to supply RBAC credentials:

  1. ClientConfiguration configuration = new ClientConfiguration {
  2. BucketConfigs = new Dictionary<string, BucketConfiguration> {
  3. {"default", new BucketConfiguration {
  4. PoolConfiguration = new PoolConfiguration {
  5. MaxSize = 6,
  6. MinSize = 4,
  7. SendTimeout = 12000
  8. },
  9. DefaultOperationLifespan = 123,
  10. BucketName = "default"
  11. }}
  12. }
  13. };
  14. configuration.SetAuthenticator(new PasswordAuthenticator("<username>", "<password>"));
  15. GlobalConfiguration.Configuration.UseCouchbaseStorage(configuration, "<defaultBucket>");
2. Using the XML configuration to intialzie .Net application
  1. <configSections>
  2. <sectionGroup name="couchbaseClients">
  3. <section name="couchbase" type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient" ></section>
  4. </sectionGroup>
  5. </configSections>
  6. <couchbaseClients>
  7. <couchbase>
  8. <servers>
  9. <add uri="http://localhost:8091"></add>
  10. </servers>
  11. <buckets>
  12. <add name="default" password="password" ></add>
  13. </buckets>
  14. <serializer name="CustomSerializer" type="Hangfire.Couchbase.Json.DocumentDefaultSerializer, Hangfire.Couchbase" ></serializer>
  15. </couchbase>
  16. </couchbaseClients>
  1. GlobalConfiguration.Configuration.UseCouchbaseStorage("couchbaseClients/couchbase", "<defaultBucket>");
3. Using the JSON configuration for .Net Core application
  1. {
  2. "couchbase": {
  3. "basic": {
  4. "servers": [
  5. "http://localhost:8091/"
  6. ],
  7. "buckets": [
  8. {
  9. "name": "default",
  10. "password": "password"
  11. }
  12. ],
  13. "serializer": "Hangfire.Couchbase.Json.DocumentDefaultSerializer, Hangfire.Couchbase"
  14. }
  15. }
  16. }
  1. IConfigurationBuilder builder = new ConfigurationBuilder()
  2. .SetBasePath(Directory.GetCurrentDirectory())
  3. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
  4. IConfigurationRoot configuration = builder.Build();
  5. GlobalConfiguration.Configuration.UseCouchbaseStorage(configuration, "couchbase:basic", "<defaultBucket>");

You can also customize some of the options to fine tune the job server. The below are defaults; if no overrides found

  1. Hangfire.Couchbase.CouchbaseStorageOptions options = new Hangfire.Couchbase.CouchbaseStorageOptions
  2. {
  3. RequestTimeout = TimeSpan.FromSeconds(30),
  4. ExpirationCheckInterval = TimeSpan.FromMinutes(2),
  5. CountersAggregateInterval = TimeSpan.FromMinutes(2),
  6. QueuePollInterval = TimeSpan.FromSeconds(15)
  7. };
  8. GlobalConfiguration.Configuration.UseCouchbaseStorage(configuration, "<defaultBucket>", options);

Questions? Problems?

Open-source project are developing more smoothly, when all discussions are held in public.

If you have any questions or problems related to Hangfire.Couchbase itself or this storage implementation or want to discuss new features, please create under issues and assign the correct label for discussion.

If you’ve discovered a bug, please report it to the GitHub Issues. Detailed reports with stack traces, actual and expected behavours are welcome.