-
-
Notifications
You must be signed in to change notification settings - Fork 364
Getting started
This is a very basic example on how to get started.
Since we will be using MSMQ as the transport for this example, you need to make sure you have MSMQ installed on your machine ("Programs & Features" / "Turn Windows features on or off" / "MSMQ Server Core"). Rebus works with several other transports as well (i.e. Azure Service Bus, Amazon SQS, RabbitMQ, SQL Server, etc.), so MSMQ is not a requirement, it's just what we're using for this example.
Create a C# project - any kind of project really - and use NuGet to
Install-Package Rebus -ProjectName <your-project>
Install-Package Rebus.Msmq -ProjectName <your-project>
and then find someplace where you can write the following magic spells (in this case, we're pretending to be in a console application):
// we have the container adapter in a variable here, but you should stash it
// in a static field somewhere, and then dispose it when your app shuts down
using var activator = new BuiltinHandlerActivator();
Configure.With(activator)
.Transport(t => t.UseMsmq("inputqueue"))
.Start();
Console.WriteLine("Press enter to quit");
Console.ReadLine();
Try and run the application now - it should log some statements to the screen about having created some worker threads and stuff.
Now try and add the following line right before the Configure.With(...)
thing starts:
activator.Register(() => new PrintDateTime());
where the PrintDateTime
handler looks like this:
public class PrintDateTime : IHandleMessages<DateTime>
{
public async Task Handle(DateTime currentDateTime)
{
Console.WriteLine("The time is {0}", currentDateTime);
}
}
and then make your app send the current time to itself by doing something like this (before the Console.ReadLine()
, obviously ;)):
var timer = new System.Timers.Timer();
timer.Elapsed += delegate { activator.Bus.SendLocal(DateTime.Now).Wait(); };
timer.Interval = 1000;
timer.Start();
which will make the app send the current time to itself every second.
The code shown here can be found in a fully functional and runnable version (using the Windsor container adapter) here: https://github.com/rebus-org/RebusSamples/tree/master/TimePrinter
Basic stuff
- Home
- Introduction
- Getting started
- Different bus modes
- How does rebus compare to other .net service buses?
- 3rd party extensions
- Rebus versions
Configuration
Scenarios
Areas
- Logging
- Routing
- Serialization
- Pub sub messaging
- Process managers
- Message context
- Data bus
- Correlation ids
- Container adapters
- Automatic retries and error handling
- Message dispatch
- Thread safety and instance policies
- Timeouts
- Timeout manager
- Transactions
- Delivery guarantees
- Idempotence
- Unit of work
- Workers and parallelism
- Wire level format of messages
- Handler pipeline
- Polymorphic message dispatch
- Persistence ignorance
- Saga parallelism
- Transport message forwarding
- Testing
- Outbox
- Startup/shutdown
Transports (not a full list)
Customization
- Extensibility
- Auto flowing user context extensibility example
- Back off strategy
- Message compression and encryption
- Fail fast on certain exception types
Pipelines
- Log message pipelines
- Incoming messages pipeline
- Incoming step context
- Outgoing messages pipeline
- Outgoing step context
Prominent application services