{"id":25002091,"url":"https://github.com/skwasjer/rebus.correlate","last_synced_at":"2025-10-08T09:50:02.302Z","repository":{"id":61950266,"uuid":"194955453","full_name":"skwasjer/Rebus.Correlate","owner":"skwasjer","description":"Rebus integration of Correlate to correlate message flow via any supported Rebus transport.","archived":false,"fork":false,"pushed_at":"2024-07-09T00:46:43.000Z","size":110,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-03T18:52:16.218Z","etag":null,"topics":["c-sharp","correlate","correlation-context","correlation-id","messaging","rebus"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skwasjer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-03T01:04:11.000Z","updated_at":"2022-09-08T14:49:03.000Z","dependencies_parsed_at":"2023-11-25T05:19:06.100Z","dependency_job_id":"1d50511b-f7e3-49b8-8236-1ee09c40fcfa","html_url":"https://github.com/skwasjer/Rebus.Correlate","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skwasjer%2FRebus.Correlate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skwasjer%2FRebus.Correlate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skwasjer%2FRebus.Correlate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skwasjer%2FRebus.Correlate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skwasjer","download_url":"https://codeload.github.com/skwasjer/Rebus.Correlate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237197286,"owners_count":19270557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","correlate","correlation-context","correlation-id","messaging","rebus"],"created_at":"2025-02-04T21:23:44.781Z","updated_at":"2025-10-08T09:49:57.261Z","avatar_url":"https://github.com/skwasjer.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rebus.Correlate\n\n[Rebus](https://github.com/rebus-org/Rebus) integration of [Correlate](https://github.com/skwasjer/Correlate) to correlate message flow via any supported Rebus transport.\n\n## Installation\n\nInstall Rebus.Correlate via the Nuget package manager or `dotnet` cli.\n\n```powershell\ndotnet add package Rebus.Correlate\n```\n\n---\n\n[![Main workflow](https://github.com/skwasjer/Rebus.Correlate/actions/workflows/main.yml/badge.svg)](https://github.com/skwasjer/Rebus.Correlate/actions/workflows/main.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=skwasjer_Rebus.Correlate\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=skwasjer_Rebus.Correlate)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=skwasjer_Rebus.Correlate\u0026metric=coverage)](https://sonarcloud.io/component_measures?id=skwasjer_Rebus.Correlate\u0026metric=coverage)\n\n| | | |\n|---|---|---|\n| `Rebus.Correlate` | [![NuGet](https://img.shields.io/nuget/v/Rebus.Correlate.svg)](https://www.nuget.org/packages/Rebus.Correlate/) [![NuGet](https://img.shields.io/nuget/dt/Rebus.Correlate.svg)](https://www.nuget.org/packages/Rebus.Correlate/) | Correlate integration with Rebus. |\n\n## Correlation ID flow\n\nThe Correlate library provides an ambient correlation context scope, that makes it easy to track a Correlation ID passing through microservices.\n\nThis library provides pipeline steps for Rebus for incoming and outgoing messages, and takes precedence over Rebus' own `FlowCorrelationIdStep`.\n\n### Outgoing messages\nWhen an ambient correlation context is present, the Correlation ID associated with this context is attached to the outgoing message. When no ambient correlation context is active, a new Correlation ID is generated instead using the `ICorrelationIdFactory`.\n\n\u003e If a CorrelationID header is already present, no action is performed.\n\n### Incoming messages\nFor each new incoming message a new ambient correlation context is created. \nIf the incoming message contains a Correlation ID header, this id is associated with the correlation context. If no Correlation ID header is present, a new Correlation ID is generated instead using the `ICorrelationIdFactory`.\n\n## Usage ###\n\nConfigure Rebus to use Correlate.\n\n### Using built-in configuration extensions ###\n\nUse Rebus' built-in configuration extensions to enable Correlate.\n\n```csharp\nILoggerFactory loggerFactory = new LoggerFactory();\nloggerFactory.AddConsole();\n\nConfigure.With(....)\n    .Options(o =\u003e o.EnableCorrelate(loggerFactory))\n    .(...)\n```\n\n### Using a `IServiceProvider`\n\nAlternatively, use `IServiceProvider` to configure Rebus with Correlate.\n\nAdd package dependencies:\n- [Rebus.ServiceProvider](https://github.com/rebus-org/Rebus.ServiceProvider) \n- [Correlate.DependencyInjection](https://github.com/skwasjer/Correlate)\n\n```csharp\nservices\n    .AddLogging(logging =\u003e logging.AddConsole())\n    .AddCorrelate()\n    .AddRebus((configure, serviceProvider) =\u003e configure\n        .Options(o =\u003e o.EnableCorrelate(serviceProvider))\n        .(...)\n    );\n```\n\n### Using a custom DI adapter\n\nFor example, provided the Correlate dependencies are registered with Autofac:\n\n```csharp\nvar builder = new ContainerBuilder();\n... // Register Correlate dependencies.\nvar container = builder.Build();\nvar scope = container.BeginLifetimeScope(); // Dispose on app shutdown.\n\nConfigure.With(....)\n    .Options(o =\u003e o.EnableCorrelate(new DependencyResolverAdapter(scope.ResolveOptional)))\n    .(...)\n```\n\n## Send/publish message in an ambient correlation context scope\n\nThis example illustrates how messages that are sent/published, inherit the Correlation ID from the ambient correlation context.\n\n```csharp\npublic class MyService\n{\n    private IAsyncCorrelationManager _asyncCorrelationManager;\n    private IBus _bus;\n\n    public MyService(IAsyncCorrelationManager asyncCorrelationManager, IBus bus)\n    {\n        _asyncCorrelationManager = asyncCorrelationManager;\n        _bus = bus;\n    }\n\n    public async Task DoWork()\n    {\n        // Without ambient correlation context, the message is still published \n        // with a Correlation ID, but it is generated specifically for this message.\n        await _bus.Publish(new DoWorkCalledEvent());\n\n        // Perform work in new correlation context.\n        await _asyncCorrelationManager.CorrelateAsync(async () =\u003e\n        {\n            // This command will be sent with the Correlation ID from\n            // the ambient correlation context.\n            await _bus.Send(new DoSomethingElseCommand());\n\n            // Do other work in ambient correlation context,\n            // like call other microservice (using Correlate support)\n            // ...\n\n            // This event will be published with the same Correlation ID.\n            await _bus.Publish(new WorkFinishedEvent());\n        });\n    }\n}\n```\n\n\u003e Note: when using Correlate integration for ASP.NET Core, each request is already scoped to a correlation context, and so there is no need to wrap the send/publish of messages with `IAsyncCorrelationManager`/`ICorrelationManager`.\n\n## Handle message in an ambient correlation context scope\n\nWith Correlate enabled, any incoming message is handled in its own ambient correlation context automatically. If you wish to access the Correlation ID, inject the `ICorrelationContextAccessor` into your handler.\n\n```csharp\npublic class MyHandler : IHandleMessages\u003cMyMessage\u003e\n{\n    private ICorrelationContextAccessor _correlationContextAccessor;\n\n    public MyHandler(ICorrelationContextAccessor correlationContextAccessor)\n    {\n        _correlationContextAccessor = correlationContextAccessor;\n    }\n\n    public Task Handle(MyMessage message)\n    {\n        string correlationId = _correlationContextAccessor.CorrelationContext.CorrelationId; \n    }\n}\n```\n\n\u003e Do not keep a reference to the `CorrelationContext`, always use the `ICorrelationContextAccessor` to get the current context.\n\n## More info\n\nSee [Correlate](https://github.com/skwasjer/Correlate) documentation for further integration with ASP.NET Core, `IHttpClientFactory` and for other extensions/libraries.\n\n### Supported .NET targets\n- .NET 6.0\n- .NET Standard 2.1/2.0\n\n### Build requirements\n- Visual Studio 2022\n- .NET 6 SDK\n- .NET 5 SDK\n- .NET Core 3.1 SDK\n\n#### Contributions\nPR's are welcome. Please rebase before submitting, provide test coverage, and ensure the AppVeyor build passes. I will not consider PR's otherwise.\n\n#### Contributors\n- skwas (author/maintainer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskwasjer%2Frebus.correlate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskwasjer%2Frebus.correlate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskwasjer%2Frebus.correlate/lists"}