Exemple #1
0
 public MessageContext(MessageMetaData meta, IEndpoint endpoint, MessagingService messagingService, MessageTypeProperties props = null)
 {
     MetaData         = meta;
     Endpoint         = endpoint;
     MessagingService = messagingService;
     Props            = props;
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        /************ 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));
        }
Exemple #6
0
        /// <summary>
        /// Send a serialized message to an endpoint bypassing the outbound pipeline
        /// useful for services relay messages like the outbox
        ///</summary>
        public Task DispatchCore(string messageTypeIdentifier, byte[] message, MessageMetaData metaData, IEndpoint endpoint)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            return(endpoint.Dispatch(messageTypeIdentifier, message, metaData));
        }
Exemple #7
0
        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));
        }
        public void PopulateForReplyTo(MessageMetaData commandMetaData)
        {
            if (commandMetaData == null)
            {
                return;
            }

            if (this.SessionId == null)
            {
                this.SessionId = commandMetaData.SessionId;
            }
            if (this.CorrelationId == null)
            {
                this.CorrelationId = commandMetaData.CorrelationId;
            }
        }
Exemple #9
0
        /// <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));
        }
Exemple #10
0
 public virtual Task Dispatch(string messageTypeIdenfifier, byte[] message, MessageMetaData metaData = null)
 {
     return(Transport.Dispatch(messageTypeIdenfifier, message, this, metaData));
 }
Exemple #11
0
 object ISaga.FindKey(IIntegrationMessage message, MessageMetaData meta) => FindKey(message, meta);
 /// <summary>
 /// Send command using the configured outbox
 /// </summary>
 /// <param name="command"></param>
 /// <param name="metaData"></param>
 /// <returns></returns>
 public Task Send(IIntegrationCommand command, MessageMetaData metaData = null)
 {
     return(_messagingService.Send(command, _outbox, metaData));
 }
 /// <summary>
 /// Publish event using a preserialized form of the event using the configured outbox
 /// the outbound message filter pipeline will still be used
 /// </summary>
 /// <param name="messageTypeIdenfier"></param>
 /// <param name="event"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task Publish(string messageTypeIdenfier, byte[] @event, MessageMetaData options = null)
 {
     return(_messagingService.Publish(messageTypeIdenfier, @event, _outbox, options));
 }
 /// <summary>
 /// Send a preserialized Command skipping the outbox, the outbound message filter pipeline will still be honored
 /// </summary>
 /// <param name="messageTypeIdenfier"></param>
 /// <param name="command"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task SendSynchronously(string messageTypeIdenfier, byte[] command, MessageMetaData options = null)
 {
     return(_messagingService.SendSynchronously(messageTypeIdenfier, command, options));
 }
Exemple #15
0
 public TransportMessage(string messageTypeIdentifier, byte[] data, MessageMetaData meta)
 {
     this.MessageTypeIdentifier = messageTypeIdentifier;
     this.Data     = data;
     this.MetaData = meta;
 }
Exemple #16
0
        public Task Reply(IIntegrationReply reply, MessageMetaData replyMetaData = null)
        {
            var replyToEndpoint = this.GetEndpointForReply();

            return(MessagingService.Reply(reply, replyToEndpoint, this.OutboxSession, replyMetaData, this.MetaData));
        }
Exemple #17
0
 public virtual void SetReplyToForCommand(IIntegrationCommand command, MessageMetaData meta)
 {
     Transport.SetReplyToForCommand(this, command, meta);
 }
Exemple #18
0
        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");
        }
Exemple #19
0
        public Task Publish(IIntegrationEvent @event, IOutboxSession outbox, MessageMetaData metaData = null)
        {
            var endpoint = MessagingMap.FindEndpoint(@event);

            return(Dispatch(@event, metaData, outbox));
        }
 /// <summary>
 /// Send Command skipping the outbox, the outbound message filter pipeline will still be honored
 /// </summary>
 /// <param name="command"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task SendSynchronously(IIntegrationCommand command, MessageMetaData options = null)
 {
     return(_messagingService.SendSynchronously(command, options));
 }
Exemple #21
0
        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));
        }
 /// <summary>
 /// Publish an event using the configured outbox
 /// </summary>
 /// <param name="event"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task Publish(IIntegrationEvent @event, MessageMetaData options = null)
 {
     return(_messagingService.Publish(@event, _outbox, options));
 }
Exemple #23
0
        public Task PublishSynchronously(IIntegrationEvent @event, MessageMetaData metaData = null)
        {
            var endpoint = MessagingMap.FindEndpoint(@event);

            return(Dispatch(@event, metaData));
        }
 /// <summary>
 /// Publish Event skipping the outbox, the outbound message filter pipeline will still be honored
 /// </summary>
 /// <param name="event"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task PublishSynchronously(IIntegrationEvent @event, MessageMetaData options = null)
 {
     return(_messagingService.PublishSynchronously(@event, options));
 }
Exemple #25
0
 internal Task Reply(IIntegrationReply reply, IEndpoint endpoint, IOutboxSession outbox, MessageMetaData metaData = null, MessageMetaData commandMetaData = null)
 {
     metaData = metaData ?? new MessageMetaData();
     metaData.PopulateForReplyTo(commandMetaData);
     return(Dispatch(reply, metaData, endpoint, outbox));
 }
 /// <summary>
 /// Send command using a preserialized form of the command using the configured outbox
 /// the outbound message filter pipeline will still be used
 /// </summary>
 /// <param name="messageTypeIdenfier"></param>
 /// <param name="command"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task Send(string messageTypeIdenfier, byte[] command, MessageMetaData options = null)
 {
     return(_messagingService.Send(messageTypeIdenfier, command, _outbox, options));
 }
Exemple #27
0
 public K FindKey(IIntegrationMessage message, MessageMetaData meta)
 {
     return(_keyMappers[message.GetType()].Invoke(message, meta));
 }