Skip to content

Instantly share code, notes, and snippets.

@larsw
Created August 27, 2014 19:27
Show Gist options
  • Save larsw/b654562203d4680e40d7 to your computer and use it in GitHub Desktop.
Save larsw/b654562203d4680e40d7 to your computer and use it in GitHub Desktop.
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()
{
}
}
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();
}
}
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