Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sapiens
Created April 12, 2016 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sapiens/347a33389b5404331d2cb680152e6890 to your computer and use it in GitHub Desktop.
Save sapiens/347a33389b5404331d2cb680152e6890 to your computer and use it in GitHub Desktop.
dbus example
//config
ServiceBus.ConfigureWith(new AutofacBusConfigurator(_boot.Container))
.ForMonolith(bus =>
{
bus.PersistAuditsWith(new InMemoryAuditStorage())
.WithoutErrorsQueues()
.ConfigureSagas(s=>s.WithoutSagas())
;
bus.WithSqlServerStorages(_boot.DbConnection,
d => d.EnableProcessorStorage().EnableReserveIdStorage())
.AutoConfigureFrom(typeof (ConfigTask_2_DomainBus).Assembly)
.HostnameIs("dmap")
.ConfigureProcessors(proc =>
{
proc
.AddWithAttributeConvention(Processors.Commands, typeof (ConfigTask_2_DomainBus).Assembly,c=>c.PollingInterval=TimeSpan.FromMinutes(10))
.AddWithAttributeConvention(Processors.Events, typeof (ConfigTask_2_DomainBus).Assembly, c => c.PollingInterval = TimeSpan.FromMinutes(10));
});
});
//usage example
[DomainBus(Processors.Events)]
public class CreateConsistencyNote
{
private readonly IDispatchMessages _bus;
public CreateConsistencyNote(IDispatchMessages bus)
{
_bus = bus;
}
public void Handle(AssetCreated evnt)
{
if (evnt.Type!=AssetType.EntityCommandModel) return;
//idempotentcy!!!
var cmdId = _bus.ReserveIdsFor(this, evnt.Id, 1).First();
var cmd=new CreateAsset()
{
Id=cmdId,
ProjectId = evnt.ProjectId,
Type = AssetType.Note,
Name = "Consistency Rules",
OperationId = evnt.Id,
ParentId = evnt.EntityId
};
_bus.Send(cmd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment