public Task Publish(string messageTypeIdenfifier, byte[] @event, IOutboxSession outbox, MessageMetaData metaData = null) { metaData = metaData ?? new MessageMetaData(); var endpoint = MessagingMap.FindEndpoint(messageTypeIdenfifier); return(Dispatch(new WrappedCommand(messageTypeIdenfifier, @event), metaData, endpoint, outbox)); }
private void _setReplyTo(IEndpoint commandEndpoint, IIntegrationCommand command, MessageMetaData commandMeta) { if (commandMeta == null) { throw new InvalidOperationException("Command cannot be sent. Unable to set replyTo on null MessageMetaData"); } if (!String.IsNullOrEmpty(commandMeta.ReplyTo)) { return; } if (!String.IsNullOrEmpty(commandMeta.ReplyToEndpointName)) { var replyToEndpoint = MessagingMap.FindEndpointByName(commandMeta.ReplyToEndpointName); replyToEndpoint.SetReplyToForCommand(command, commandMeta); return; } else if (MessagingMap.DefaultReplyToEndpoint != null) { MessagingMap.DefaultReplyToEndpoint.SetReplyToForCommand(command, commandMeta); return; } throw new InvalidOperationException("Command cannot be sent because replyTo endpoint could not be determined"); }
public Task Dispatch(IIntegrationMessage message, MessageMetaData metaData = null, IOutboxSession outbox = null) { var endpoint = MessagingMap.FindEndpoint(message) ?? throw new ApplicationException($"Unable to dispatch message. Type: {message.GetType()} Message Type: {message.MessageType}"); return(Dispatch(message, metaData, endpoint, outbox)); }
public async Task StopAsync(CancellationToken cancellationToken = default(CancellationToken)) { foreach (var endpoint in MessagingMap.FindAllEndpoints()) { await endpoint.StopAsync();// cancellationToken); } await _outboxManager.StopAsync(); }
public Task SendSynchronously(string messageTypeIdenfifier, byte[] command, MessageMetaData metaData = null) { metaData = metaData ?? new MessageMetaData(); var endpoint = MessagingMap.FindEndpoint(messageTypeIdenfifier); _setReplyTo(endpoint, null, metaData); return(Dispatch(new WrappedCommand(messageTypeIdenfifier, command), metaData, endpoint)); }
public Task SendSynchronously(IIntegrationCommand command, MessageMetaData metaData = null) { metaData = metaData ?? new MessageMetaData(); var endpoint = MessagingMap.FindEndpoint(command); _setReplyTo(endpoint, command, metaData); return(Dispatch(command, metaData)); }
/************ Message Dispatching ***********/ public Task Send(IIntegrationCommand command, IOutboxSession outbox, MessageMetaData metaData = null) { metaData = metaData ?? new MessageMetaData(); var endpoint = MessagingMap.FindEndpoint(command); _setReplyTo(endpoint, command, metaData); return(Dispatch(command, metaData, outbox)); }
public void AddEndpoint(IEndpoint endpoint) { if (endpoint.Transport == null) { throw new InvalidOperationException($"Endpoint: {endpoint.Name} must be configured with a Transport"); } MessagingMap.AddEndpoint(endpoint.Name, endpoint); //we only need to bind routes to endpoints that we write messages to because we need an address/connectionString to send them to //as opposed to inbound messages which just show up at the endpoint and can validated / filtered there if (endpoint.IsWriter) { foreach (Type messageType in endpoint.BoundMessageTypes) { var props = MessagingMap.AddMessageTypeIfNotExists(messageType); MessagingMap.AddEndpointRoute(props.MessageTypeIdentifier, endpoint); } foreach (string identifier in endpoint.BoundMessageIdentifiers) { MessagingMap.AddEndpointRoute(identifier, endpoint); } if (endpoint.Settings.IsEventDefault) { MessagingMap.SetDefaultPublishToEndpoint(endpoint); } if (endpoint.Settings.IsReplyDefault) { MessagingMap.SetDefaultReplyToEndpoint(endpoint); } //convention can be overriden by any endpoint marked as default if (endpoint.Name.Equals("Events", StringComparison.OrdinalIgnoreCase) && MessagingMap.DefaultPublishToEndpoint == null) { MessagingMap.SetDefaultPublishToEndpoint(endpoint); } if (endpoint.Name.Equals("Replies", StringComparison.OrdinalIgnoreCase) && MessagingMap.DefaultReplyToEndpoint == null) { MessagingMap.SetDefaultReplyToEndpoint(endpoint); } } }
/// <summary> /// Send a serialized message to an endpoint bypassing the outbound pipeline /// useful for services relay messages like the outbox /// </summary> /// <param name="messageTypeIdentifier"></param> /// <param name="message"></param> /// <param name="metaData"></param> /// <param name="endpointName"></param> /// <returns></returns> public Task DispatchCore(string messageTypeIdentifier, byte[] message, MessageMetaData metaData, string endpointName, bool isTransient = false) { var endpoint = endpointName != null?MessagingMap.FindEndpointByName(endpointName) : MessagingMap.FindEndpoint(messageTypeIdentifier); if (endpoint == null) { throw new ApplicationException($"Unable to dispatch message. Endpoint not found. MessageTypeIdentifier: {messageTypeIdentifier}. Endpoint: {endpointName}"); } if (isTransient && metaData != null) { if (metaData.SkipTransientDispatch) { throw new ApplicationException($"Unable to dispatch transient message. SkipTransient was set to True. MessageTypeIdentifier: {messageTypeIdentifier}. Endpoint: {endpointName}"); } if (metaData.DispatchDelay.HasValue && !endpoint.SupportsDelayedDispatch) { throw new ApplicationException($"Unable to dispatch transient message. Delay not supported by transport. MessageTypeIdentifier: {messageTypeIdentifier}. Endpoint: {endpointName}"); } } return(DispatchCore(messageTypeIdentifier, message, metaData, endpoint)); }
/// <summary> /// Register all framework components (message types, handlers, extractors, etc..) /// </summary> /// <param name="assemblies"></param> public static void InitializeTypes(params Assembly[] assemblies) { MessagingMap.InitializeTypes(assemblies); }
public Task PublishSynchronously(IIntegrationEvent @event, MessageMetaData metaData = null) { var endpoint = MessagingMap.FindEndpoint(@event); return(Dispatch(@event, metaData)); }
public Task Publish(IIntegrationEvent @event, IOutboxSession outbox, MessageMetaData metaData = null) { var endpoint = MessagingMap.FindEndpoint(@event); return(Dispatch(@event, metaData, outbox)); }