public Task Dispatch(IIntegrationMessage message, MessageMetaData metaData, IEndpoint endpoint, IOutboxSession outboxSession = null) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } OutboundMessagePipeline messagePipeline = null; if (_endpointOutboundPipeline.ContainsKey(endpoint)) { messagePipeline = _endpointOutboundPipeline[endpoint]; } else { messagePipeline = new OutboundMessagePipeline(endpoint.Settings.OutboundIntegrationFilters, endpoint.Settings.OutboundTransportFilters); _endpointOutboundPipeline[endpoint] = messagePipeline; } var resultContext = messagePipeline.Process(new IntegrationMessageFilterContext(message, metaData, endpoint, FilterDirection.Outbound, null)); if (outboxSession != null)//dispatch through the outbox { OutboxDispatchOptions options = new OutboxDispatchOptions() { }; if (metaData != null) { if (metaData.DispatchDelay.HasValue && !endpoint.SupportsDelayedDispatch) { options.Delay = metaData.DispatchDelay; options.SkipTransientDispatch = true; // for safety because we set delay } else { options.SkipTransientDispatch = metaData.SkipTransientDispatch; } options.ExpiresAtUtc = metaData.ExpiresAtUtc; } return(outboxSession.Dispatch(message.MessageType, resultContext.TransportMessage.Data, resultContext.TransportMessage.MetaData, endpoint, options)); } //dispatch to the endpoint return(DispatchCore(message.MessageType, resultContext.TransportMessage.Data, resultContext.TransportMessage.MetaData, endpoint)); }
private Task _addToContext(string messageTypeIdentifier, byte[] message, MessageMetaData meta, IEndpoint endpoint = null, OutboxDispatchOptions options = null) { options = options ?? new OutboxDispatchOptions(); double delayInSeconds = 0; //send immediately bool skipTransient = _outbox.DisableTransientDispatch; if (!skipTransient) { skipTransient = options.SkipTransientDispatch;//check at the message level } if (options.Delay.HasValue) { delayInSeconds = options.Delay.Value.TotalSeconds; } var priorityDateUtc = DateTime.UtcNow.AddSeconds(delayInSeconds); var outboxMessage = new OutboxMessage( messageTypeIdentifier, message, meta != null ? JsonConvert.SerializeObject(meta) : null, priorityDateUtc, endpoint?.Name, skipTransient, options.ExpiresAtUtc); //add the message for persistance with the dbcontext _dbContext.Add(outboxMessage); if (!outboxMessage.SkipTransientDispatch) { this._transientMessageQueue.Enqueue(outboxMessage); } return(Task.CompletedTask); }
/// <summary> /// Record the message to the outbox within the current transaction/ Unit of Work /// </summary> /// <param name="event"></param> /// <returns></returns> public Task Dispatch(string messageTypeIdentifier, byte[] message, MessageMetaData meta, IEndpoint endpoint = null, OutboxDispatchOptions options = null) { return(this._addToContext(messageTypeIdentifier, message, meta, endpoint, options)); }