Created
August 27, 2014 19:27
-
-
Save larsw/b654562203d4680e40d7 to your computer and use it in GitHub Desktop.
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
internal class MassTransitDispatcher : IObserver<ICommit> | |
{ | |
private readonly IServiceBus _bus; | |
public MassTransitDispatcher(IServiceBus bus) | |
{ | |
_bus = bus; | |
} | |
public void Dispose() | |
{ | |
} | |
public void OnNext(ICommit commit) | |
{ | |
foreach (var @event in commit.Events) | |
{ | |
_bus.Publish(@event); | |
} | |
} | |
public void OnError(Exception error) | |
{ | |
// ... | |
} | |
public void OnCompleted() | |
{ | |
} | |
} |
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
internal class PollingHook : PipelineHookBase | |
{ | |
private readonly IObserveCommits _commitsObserver; | |
public PollingHook(IObserveCommits commitsObserver) | |
{ | |
_commitsObserver = commitsObserver; | |
} | |
public override void PostCommit(ICommit committed) | |
{ | |
base.PostCommit(committed); | |
_commitsObserver.PollNow(); | |
} | |
} |
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
var massTransitDispatcher = new MassTransitDispatcher(_bus); | |
var eventStore = Wireup.Init() | |
// ....... | |
.Build(); | |
var repository = new EventStoreRepository(eventStore, new AggregateFactory(), new ConflictDetector()); | |
var pollingClient = new PollingClient(eventStore.Advanced); | |
var commitObserver = pollingClient.ObserveFrom(null); | |
var subscription = commitObserver.SubscribeSafe(massTransitDispatcher); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment