Skip to content

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 messages are published, an instance of Bus can be configured using the BusBuilder type. To configure a producer application to publish a StatusUpdate message to a direct exchange named "status-update-exchange" on localhost, you would use the following configuration:

Bus bus = new BusBuilder()
  .Configure(ctx => ctx.Publish<StatusUpdate>().WithExchange("status-update-exchange"))
  .Build();
bus.Connect();
Clone this wiki locally