Exemplo n.º 1
0
 public MessageContext(MessageMetaData meta, IEndpoint endpoint, MessagingService messagingService, MessageTypeProperties props = null)
 {
     MetaData         = meta;
     Endpoint         = endpoint;
     MessagingService = messagingService;
     Props            = props;
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 8
0
        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;
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 10
0
 public virtual Task Dispatch(string messageTypeIdenfifier, byte[] message, MessageMetaData metaData = null)
 {
     return(Transport.Dispatch(messageTypeIdenfifier, message, this, metaData));
 }
Exemplo n.º 11
0
 object ISaga.FindKey(IIntegrationMessage message, MessageMetaData meta) => FindKey(message, meta);
Exemplo n.º 12
0
 /// <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));
 }
Exemplo n.º 13
0
 /// <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));
 }
Exemplo n.º 14
0
 /// <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));
 }
Exemplo n.º 15
0
 public TransportMessage(string messageTypeIdentifier, byte[] data, MessageMetaData meta)
 {
     this.MessageTypeIdentifier = messageTypeIdentifier;
     this.Data     = data;
     this.MetaData = meta;
 }
Exemplo n.º 16
0
        public Task Reply(IIntegrationReply reply, MessageMetaData replyMetaData = null)
        {
            var replyToEndpoint = this.GetEndpointForReply();

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

            return(Dispatch(@event, metaData, outbox));
        }
Exemplo n.º 20
0
 /// <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));
 }
Exemplo n.º 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));
        }
Exemplo n.º 22
0
 /// <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));
 }
Exemplo n.º 23
0
        public Task PublishSynchronously(IIntegrationEvent @event, MessageMetaData metaData = null)
        {
            var endpoint = MessagingMap.FindEndpoint(@event);

            return(Dispatch(@event, metaData));
        }
Exemplo n.º 24
0
 /// <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));
 }
Exemplo n.º 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));
 }
Exemplo n.º 26
0
 /// <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));
 }
Exemplo n.º 27
0
 public K FindKey(IIntegrationMessage message, MessageMetaData meta)
 {
     return(_keyMappers[message.GetType()].Invoke(message, meta));
 }