Created
April 12, 2016 22:03
-
-
Save sapiens/347a33389b5404331d2cb680152e6890 to your computer and use it in GitHub Desktop.
dbus example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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