Beispiel #1
0
        public Task <IExchange> DeclareExchangeAsync(IAdvancedBus advancedBus, Type messageType, string exchangeType)
        {
            var conventions     = advancedBus.Container.Resolve <IConventions>();
            var messageVersions = new MessageVersionStack(messageType);

            return(DeclareVersionedExchangesAsync(advancedBus, conventions, messageVersions, exchangeType));
        }
        public IExchange DeclareExchange(IAdvancedBus advancedBus, Type messageType, string exchangeType)
        {
            var conventions     = advancedBus.Container.Resolve <IConventions>();
            var messageVersions = new MessageVersionStack(messageType);
            var publishExchange = DeclareVersionedExchanges(advancedBus, conventions, messageVersions, exchangeType);

            return(publishExchange);
        }
        private MessageTypeProperty(ITypeNameSerializer typeNameSerializer, Type messageType)
        {
            this.typeNameSerializer = typeNameSerializer;
            var messageVersions = new MessageVersionStack(messageType);

            // MessageVersionStack has most recent version at the bottom of the stack (hence the reverse)
            // and includes the actual message type (hence the first / removeat)
            alternativeTypes = messageVersions
                               .Select(typeNameSerializer.Serialize)
                               .Reverse()
                               .ToList();
            this.messageType = alternativeTypes.First();
            alternativeTypes.RemoveAt(0);
        }
        private IExchange DeclareVersionedExchanges(MessageVersionStack messageVersions, string exchangeType)
        {
            IExchange destinationExchange = null;

            while (!messageVersions.IsEmpty())
            {
                var messageType    = messageVersions.Pop();
                var exchangeName   = conventions.ExchangeNamingConvention(messageType);
                var sourceExchange = DeclareExchange(exchangeName, exchangeType);
                if (destinationExchange != null)
                {
                    advancedBus.Bind(sourceExchange, destinationExchange, "#");
                }
                destinationExchange = sourceExchange;
            }

            return(destinationExchange);
        }
        private async Task <IExchange> DeclareVersionedExchangesAsync(MessageVersionStack messageVersions, string exchangeType)
        {
            IExchange destinationExchange = null;

            while (!messageVersions.IsEmpty())
            {
                var messageType    = messageVersions.Pop();
                var exchangeName   = conventions.ExchangeNamingConvention(messageType);
                var sourceExchange = await DeclareExchangeAsync(exchangeName, exchangeType).ConfigureAwait(false);

                if (destinationExchange != null)
                {
                    await advancedBus.BindAsync(sourceExchange, destinationExchange, "#").ConfigureAwait(false);
                }
                destinationExchange = sourceExchange;
            }

            return(destinationExchange);
        }
        public Task <IExchange> DeclareExchangeAsync(Type messageType, string exchangeType)
        {
            var messageVersions = new MessageVersionStack(messageType);

            return(DeclareVersionedExchangesAsync(messageVersions, exchangeType));
        }
        public IExchange DeclareExchange(Type messageType, string exchangeType)
        {
            var messageVersions = new MessageVersionStack(messageType);

            return(DeclareVersionedExchanges(messageVersions, exchangeType));
        }
        private IExchange DeclareVersionedExchanges(IAdvancedBus advancedBus, IConventions conventions, MessageVersionStack messageVersions, string exchangeType)
        {
            // This works because the message version stack is LIFO from most superseded message type to the actual message type
            IExchange destinationExchange = null;

            while (!messageVersions.IsEmpty())
            {
                var messageType    = messageVersions.Pop();
                var exchangeName   = conventions.ExchangeNamingConvention(messageType);
                var sourceExchange = DeclareExchange(advancedBus, exchangeName, exchangeType);

                if (destinationExchange != null)
                {
                    advancedBus.Bind(sourceExchange, destinationExchange, "#");
                }

                destinationExchange = sourceExchange;
            }
            return(destinationExchange);
        }
Beispiel #9
0
        private Task <IExchange> DeclareVersionedExchanges(IAdvancedBus advancedBus, IConventions conventions, MessageVersionStack messageVersions, string exchangeType)
        {
            var destinationExchangeTask = TaskHelpers.FromResult <IExchange>(null);

            while (!messageVersions.IsEmpty())
            {
                var messageType  = messageVersions.Pop();
                var exchangeName = conventions.ExchangeNamingConvention(messageType);
                destinationExchangeTask = destinationExchangeTask.Then(destinationExchange => DeclareExchangeAsync(advancedBus, exchangeName, exchangeType).Then(sourceExchange =>
                {
                    if (destinationExchange != null)
                    {
                        return(advancedBus.BindAsync(sourceExchange, destinationExchange, "#").Then(() => sourceExchange));
                    }
                    return(TaskHelpers.FromResult(sourceExchange));
                }));
            }
            return(destinationExchangeTask);
        }