Hi, I have a feeling this is a real newbee question.
I have a handler/dispatcher that subscribes to $all and writes the events to a view. Pretty simple stuff. I have a console app that modifies an aggregate and publishes a few messages.
When I start the handler it reads all the previous messages and updates my view, but when I run the other app and have it call the aggregate my handler does not seem to receive them.
most of this is jacked directly from dispatcher discussions on this news group and/or the recommended repository. the Start method calls the RecoverSubscription() method as does the HandleSubscriptionDropped.
Any help would be appreciated.
thanks,
R
Here’s my code.
private void RecoverSubscription()
{
_lastProcessedPosition = _mongoRepository.Get(x => x.HandlerType == _handlerType)
?? new LastProcessedPosition {HandlerType = _handlerType, CommitPosition = 0, PreparePosition = 0};
var position = new Position(_lastProcessedPosition.CommitPosition, _lastProcessedPosition.PreparePosition);
_subscription = _gesConnection.SubscribeToAllFrom(position, false, HandleNewEvent, null, HandleSubscriptionDropped, new UserCredentials(“admin”, “changeit”));
}
private void HandleNewEvent(EventStoreCatchUpSubscription subscription, ResolvedEvent @event)
{
if (@event.Event.EventType.StartsWith("$")) { return; }
_rawEvent = @event;
_event = ProcessRawEvent();
if (_event == null) { return; }
HandleEvent(_rawEvent.Event.EventType);
}
protected object ProcessRawEvent()
{
if (_rawEvent.OriginalEvent.Metadata.Length > 0 && _rawEvent.OriginalEvent.Data.Length > 0)
return DeserializeEvent(_rawEvent.OriginalEvent.Metadata, _rawEvent.OriginalEvent.Data);
return null;
}
private static object DeserializeEvent(byte[] metadata, byte[] data)
{
var eventClrTypeName = JObject.Parse(Encoding.UTF8.GetString(metadata)).Property(“EventClrTypeName”).Value;
return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), Type.GetType((string)eventClrTypeName));
}