-
Notifications
You must be signed in to change notification settings - Fork 23
Publish
derekgreer edited this page Jun 22, 2012
·
6 revisions
Messages are published with RabbitBus using the IBus.Publish()
method. For example, the following publishes a StatusUpdate
message using an existing instance of Bus
:
bus.Publish(new StatusUpdate("OK"));
The StatusUpdate
type is a simple class which might be defined as follows:
[Serializable]
public class StatusUpdate
{
public StatusUpdate(string status)
{
Status = status;
}
public string Status { get; set; }
}
By default, RabbitBus publishes non-registered messages to an auto-deleted, non-persistent, non-durable direct exchange matching the name of the message being published. The following example publishes a StatusUpdate
message using the default routing configuration:
var bus = new Bus();
bus.Publish(new StatusUpdate("OK"));
bus.Close();
To specify how RabbitBus publishes messages, an instance of IBus
can be configured using the BusBuilder
type. The following example publishes a StatusUpdate
message to a direct exchange named "status-update-exchange" on localhost:
Bus bus = new BusBuilder()
.Configure(ctx => ctx.Publish<StatusUpdate>().WithExchange("status-update-exchange"))
.Build();
bus.Connect();