Transport for Rebus that doesn't actually send/receive anything at all. Kind-of like /dev/null in Linux. Useful for scenarios where you're forced to inject a Rebus instance but don't care about the functionality using it at all.
$ dotnet add package Rebus.FakeNo-op implementations of Rebus Transport, SubscriptionStorage, and SagaStorage that silently discard all operations. Kind-of like /dev/null in Linux.
dotnet add package Rebus.Fake
Or via NuGet Package Manager:
Install-Package Rebus.Fake
I've found this useful for scenarios where I'm forced to inject a Rebus instance but I don't care about the functionality using it at all. I also don't want messages that I know will never be consumed, getting collected in-memory.
Example use case: An application intended for both online and offline use. When hosted in an online environment it communicates with external services using Rebus, but when hosted offline and those external services are not needed, it's simpler to inject Rebus with fake components and drop all messages that the application attempts to send.
Important: The official core InMemory transport is better for testing. I do NOT recommend using Rebus.Fake for unit/integration tests. Use Rebus.Fake for production scenarios where messages should be discarded.
Rebus.Fake provides three no-op implementations:
| Component | Description |
|---|---|
| FakeTransport | Silently discards all sent messages, never receives anything |
| FakeSubscriptionStorage | Accepts subscribe/unsubscribe operations but never returns subscribers |
| FakeSagaStorage | Accepts saga operations but never persists or retrieves saga data |
using Rebus.Activation;
using Rebus.Config;
using Rebus.Routing.TypeBased;
using var activator = new BuiltinHandlerActivator();
using var bus = Configure.With(activator)
.Transport(t => t.UseFakeTransportAsOneWayClient())
.Routing(r => r.TypeBased().Map<MyMessage>("dummy-queue"))
.Start();
await bus.Send(new MyMessage());
using Rebus.Activation;
using Rebus.Config;
using var activator = new BuiltinHandlerActivator();
using var bus = Configure.With(activator)
.Transport(t => t.UseFakeTransport("inputQueueName"))
.Subscriptions(s => s.UseFakeSubscriptionStorage())
.Start();
await bus.Subscribe<MyEvent>();
await bus.Publish(new MyEvent());
using Rebus.Activation;
using Rebus.Config;
using var activator = new BuiltinHandlerActivator();
using var bus = Configure.With(activator)
.Transport(t => t.UseFakeTransport("inputQueueName"))
.Subscriptions(s => s.UseFakeSubscriptionStorage())
.Sagas(s => s.UseFakeSagaStorage())
.Start();
MIT