private void handle(object command, AcknowledgeDelegate acknowledge, Func <object, Endpoint, string, CommandHandlingResult> handler, Endpoint commandOriginEndpoint, string route) { try { var result = handler(command, commandOriginEndpoint, route); acknowledge(result.RetryDelay, !result.Retry); } catch (Exception e) { m_Logger.WarnException("Failed to handle command of type " + (command == null?"null":command.GetType().Name), e); acknowledge(m_FailedCommandRetryDelay, false); } }
public void Dispatch(object command, CommandPriority priority, AcknowledgeDelegate acknowledge, Endpoint commandOriginEndpoint, string route) { Func <object, Endpoint, string, CommandHandlingResult> handler; if (!m_Handlers.TryGetValue(command.GetType(), out handler)) { m_Logger.Warn("Failed to handle command {0} in bound context {1}, no handler was registered for it", command, m_BoundedContext); acknowledge(m_FailedCommandRetryDelay, false); return; } m_TaskFactories[priority].StartNew(() => handle(command, acknowledge, handler, commandOriginEndpoint, route)); }
private void Dispatch(object message, AcknowledgeDelegate acknowledge, Dictionary <string, string> headers) { Func <object, CommandHandlingResult> handler; if (!m_Handlers.TryGetValue(message.GetType(), out handler)) { throw new InvalidOperationException(string.Format("Failed to handle message {0}, no handler was registered for it", message)); } try { var result = handler(message); acknowledge(result.RetryDelay, !result.Retry); } catch (Exception e) { acknowledge(FAILED_COMMAND_RETRY_DELAY, false); } }
private void DispatchUnknown(string type, AcknowledgeDelegate acknowledge) { if (m_HandlerDefault == null) { throw new InvalidOperationException($"Failed to handle unknown message: {type}, no default handler registered"); } try { m_HandlerDefault(type); } catch (Exception e) { } finally { acknowledge(0, true); } }
private void Handle( object command, AcknowledgeDelegate acknowledge, CommandHandlerInfo commandHandlerInfo, Endpoint commandOriginEndpoint, string route) { string commandType = command?.GetType().Name ?? "Unknown command type"; var telemtryOperation = TelemetryHelper.InitTelemetryOperation( "Cqrs handle command", commandHandlerInfo.HandlerTypeName, commandType, _boundedContext); try { var result = _commandInterceptorsProcessor.RunInterceptorsAsync( command, commandHandlerInfo.HandlerObject, commandHandlerInfo.EventPublisher, (c, e) => commandHandlerInfo.Handler(c, e, commandOriginEndpoint, route)) .ConfigureAwait(false) .GetAwaiter() .GetResult(); acknowledge(result.RetryDelay, !result.Retry); } catch (Exception e) { _log.WriteError(commandHandlerInfo.HandlerTypeName, commandType, e); acknowledge(_failedCommandRetryDelay, false); TelemetryHelper.SubmitException(telemtryOperation, e); } finally { TelemetryHelper.SubmitOperationResult(telemtryOperation); } }
public void Dispacth(object @event, AcknowledgeDelegate acknowledge) { List <Func <object, CommandHandlingResult> > list; if (@event == null) { //TODO: need to handle null deserialized from messaging throw new ArgumentNullException("event"); } if (!m_Handlers.TryGetValue(@event.GetType(), out list)) { acknowledge(0, true); return; } foreach (var handler in list) { CommandHandlingResult result; try { result = handler(@event); } catch (Exception e) { m_Logger.WarnException("Failed to handle event of type " + @event.GetType().Name, e); result = new CommandHandlingResult { Retry = true, RetryDelay = m_FailedEventRetryDelay }; } if (result.Retry) { acknowledge(result.RetryDelay, !result.Retry); return; } } acknowledge(0, true); }
private void ProcessMessage( BinaryMessage binaryMessage, Type type, Action <object, Dictionary <string, string> > callback, AcknowledgeDelegate ack, Endpoint endpoint) { object message = null; try { message = m_SerializationManager.Deserialize(endpoint.SerializationFormat, binaryMessage.Bytes, type); } catch (Exception e) { _log.WriteError( nameof(ProcessMessage), $"Failed to deserialize message. Transport: {endpoint.TransportId}, Destination: {endpoint.Destination}, Message Type: {type.Name}", e); //TODO: need to unack without requeue ack(DEFAULT_UNACK_DELAY, false); } try { callback(message, binaryMessage.Headers); } catch (Exception e) { _log.WriteError( nameof(ProcessMessage), $"Failed to handle message. Transport: {endpoint.TransportId}, Destination: {endpoint.Destination}, Message Type: {type.Name}", e); ack(DEFAULT_UNACK_DELAY, false); } }
public void Dispatch( object command, AcknowledgeDelegate acknowledge, Endpoint commandOriginEndpoint, string route) { if (!_handlers.TryGetValue(command.GetType(), out var handlerInfo)) { _log.WriteWarning( nameof(CommandDispatcher), nameof(Dispatch), $"Failed to handle command of type {command.GetType().Name} in bound context {_boundedContext}, no handler was registered for it"); acknowledge(_failedCommandRetryDelay, false); return; } Handle( command, acknowledge, handlerInfo, commandOriginEndpoint, route); }
private void processMessage(BinaryMessage binaryMessage, Type type, Action <object> callback, AcknowledgeDelegate ack, Endpoint endpoint) { object message = null; try { message = m_SerializationManager.Deserialize(endpoint.SerializationFormat, binaryMessage.Bytes, type); } catch (Exception e) { m_Logger.ErrorException(string.Format("Failed to deserialize message. Transport: {0}, Destination: {1}, Message Type: {2}", endpoint.TransportId, endpoint.Destination, type.Name), e); //TODO: need to unack without requeue ack(DEFAULT_UNACK_DELAY, false); } try { callback(message); } catch (Exception e) { m_Logger.ErrorException(string.Format("Failed to handle message. Transport: {0}, Destination: {1}, Message Type: {2}", endpoint.TransportId, endpoint.Destination, type.Name), e); ack(DEFAULT_UNACK_DELAY, false); } }