public virtual IEnumerable<Type> CreateTopicsForPublisher(Type messageType, IMessageNameFormatter formatter)
		{
			var nm = _address.NamespaceManager;

			foreach (var type in messageType.GetMessageTypes())
			{
				var topic = formatter.GetMessageName(type).ToString();
				
				/*
				 * Type here is both the actual message type and its 
				 * interfaces. In RMQ we could bind the interface type
				 * exchanges to the message type exchange, but because this
				 * is azure service bus, we only have plain topics.
				 * 
				 * This means that for a given subscribed message, we have to
				 * subscribe also to all of its interfaces and their corresponding
				 * topics. In this method, it means that we'll just create
				 * ALL of the types' corresponding topics and publish to ALL of them.
				 * 
				 * On the receiving side we'll have to de-duplicate 
				 * the received messages, potentially (unless we're subscribing only
				 * to one of the interfaces that itself doesn't implement any interfaces).
				 */

				nm.CreateAsync(new TopicDescriptionImpl(topic)).Wait();

				yield return type;
			}
		}
        public static ExchangeBindingSettings GetExchangeBinding(this Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var exchange = new Exchange(messageNameFormatter.GetMessageName(messageType).ToString(), !temporary, temporary);

            var binding = new ExchangeBinding(exchange);

            return binding;
        }
        public static IEnumerable<ExchangeBindingSettings> GetExchangeBindings(this Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            if (!IsBindableMessageType(messageType))
                yield break;

            bool temporary = IsTemporaryMessageType(messageType);

            var exchange = new Exchange(messageNameFormatter.GetMessageName(messageType).ToString(), !temporary, temporary);

            var binding = new ExchangeBinding(exchange);

            yield return binding;
        }
Ejemplo n.º 4
0
        public void OnSubscriptionAdded(SubscriptionAdded message)
        {
            Guard.AgainstNull(_inputAddress, "InputAddress", "The input address was not set");

            Type messageType = Type.GetType(message.MessageName);

            if (messageType == null)
            {
                _log.InfoFormat("Unknown message type '{0}', unable to add subscription", message.MessageName);
                return;
            }

            MessageName messageName = _messageNameFormatter.GetMessageName(messageType);

            _inboundTransport.BindSubscriberExchange(RabbitMqEndpointAddress.Parse(message.EndpointUri),
                                                     messageName.ToString(), IsTemporaryMessageType(messageType));

            _bindings[message.SubscriptionId] = messageName;
        }
Ejemplo n.º 5
0
        void AddEndpointForType(Type messageType)
        {
            using (var management = new RabbitMqEndpointManagement(_address))
            {
                IEnumerable <Type> types = management.BindExchangesForPublisher(messageType, _messageNameFormatter);
                foreach (Type type in types)
                {
                    if (_added.ContainsKey(type))
                    {
                        continue;
                    }

                    MessageName messageName = _messageNameFormatter.GetMessageName(type);

                    IRabbitMqEndpointAddress messageEndpointAddress = _address.ForQueue(messageName.ToString());

                    FindOrAddEndpoint(type, messageEndpointAddress);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the endpoint for the specified message type using the default
        /// exchange/queue convention for naming.
        ///
        /// TODO: FIX!!!
        ///
        /// </summary>
        /// <param name="bus">The bus instance used to resolve the endpoint</param>
        /// <param name="messageType">The message type to convert to a URI</param>
        /// <returns>The IEndpoint instance, resolved from the service bus</returns>
        public static IEndpoint GetEndpoint(this IServiceBus bus, Type messageType)
        {
            var inboundTransport = bus.Endpoint.InboundTransport as InboundRabbitMqTransport;

            if (inboundTransport == null)
            {
                throw new ArgumentException(
                          "The bus must be receiving from a RabbitMQ endpoint to convert message types to endpoints.");
            }

            var inputAddress = inboundTransport.Address.CastAs <IRabbitMqEndpointAddress>();

            IMessageNameFormatter messageNameFormatter = inboundTransport.MessageNameFormatter;

            MessageName messageName = messageNameFormatter.GetMessageName(messageType);

            IRabbitMqEndpointAddress address = inputAddress.ForQueue(messageName.ToString());

            return(bus.GetEndpoint(address.Uri));
        }
        /// <summary>
        /// Adds an endpoint for the message type. This will look up all super-classes
        /// of the message's type (running for those as well) and then create
        /// message sinks corresponding to the type of message that is being published.
        /// </summary>
        /// <param name="messageType">The type of message to add an endpoint for.</param>
        void AddEndpointForType(Type messageType)
        {
            using (var management = new AzureManagementEndpointManagement(_address))
            {
                IEnumerable <Type> types = management.CreateTopicsForPublisher(messageType, _formatter);

                foreach (Type type in types)
                {
                    if (_added.ContainsKey(type))
                    {
                        continue;
                    }

                    MessageName messageName = _formatter.GetMessageName(type);

                    IAzureServiceBusEndpointAddress messageEndpointAddress = _address.ForTopic(messageName.ToString());

                    FindOrAddEndpoint(type, messageEndpointAddress);
                }
            }
        }
Ejemplo n.º 8
0
        public void OnSubscriptionAdded(SubscriptionAdded message)
        {
            Guard.AgainstNull(_inputAddress, "InputAddress", "The input address was not set");

            Type messageType = Type.GetType(message.MessageName);

            if (messageType == null)
            {
                _log.InfoFormat("Unknown message type '{0}', unable to add subscription", message.MessageName);
                return;
            }

            MessageName messageName = _messageNameFormatter.GetMessageName(messageType);

            using (var management = new RabbitMqEndpointManagement(_inputAddress))
            {
                management.BindExchange(_inputAddress.Name, messageName.ToString(), ExchangeType.Fanout, "");
            }

            _bindings[message.SubscriptionId] = messageName;
        }
Ejemplo n.º 9
0
        public void OnSubscriptionAdded(SubscriptionAdded message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Type messageType = Type.GetType(message.MessageName);

            if (messageType == null)
            {
                _log.InfoFormat("Unknown message type '{0}', unable to add subscription", message.MessageName);
                return;
            }

            MessageName messageName      = _formatter.GetMessageName(messageType);
            var         topicDescription = new TopicDescription(messageName.ToString());

            _inboundTransport.AddTopicSubscriber(topicDescription);

            _bindings[message.SubscriptionId] = topicDescription;
        }
 public MessageName GetMessageName(Type type)
 {
     return(_formatter.GetMessageName(type));
 }
 MessageName GetMessageName(Type messageType)
 {
     return(_formatter.GetMessageName(messageType));
 }
Ejemplo n.º 12
0
        public static SendSettings GetSendSettings(this IRabbitMqHost host, Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            bool isTemporary = messageType.IsTemporaryMessageType();

            bool durable = !isTemporary;
            bool autoDelete = isTemporary;

            string name = messageNameFormatter.GetMessageName(messageType).ToString();

            SendSettings settings = new RabbitMqSendSettings(name, ExchangeType.Fanout, durable, autoDelete);

            return settings;
        }
Ejemplo n.º 13
0
        public void BindExchangesForSubscriber(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            MessageName messageName = messageNameFormatter.GetMessageName(messageType);

            BindExchange(_address.Name, messageName.ToString(), ExchangeType.Fanout, "");
        }
        public void BindExchangesForSubscriber(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            MessageName messageName = messageNameFormatter.GetMessageName(messageType);

            BindExchange(_address.Name, messageName.ToString(), ExchangeType.Fanout, "");
        }
        public IEnumerable<Type> BindExchangesForPublisher(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            MessageName messageName = messageNameFormatter.GetMessageName(messageType);

            using (IModel model = _connection.CreateModel())
            {
                model.ExchangeDeclare(messageName.ToString(), ExchangeType.Fanout, true, false, null);

                yield return messageType;

                foreach (Type type in messageType.GetMessageTypes().Skip(1))
                {
                    MessageName interfaceName = messageNameFormatter.GetMessageName(type);

                    model.ExchangeDeclare(interfaceName.ToString(), ExchangeType.Fanout, true, false, null);
                    model.ExchangeBind(interfaceName.ToString(), messageName.ToString(), "");

                    yield return type;
                }

                model.Close(200, "ok");
            }
        }
Ejemplo n.º 16
0
 string IEntityNameFormatter.FormatEntityName <T>()
 {
     return(_formatter.GetMessageName(typeof(T)).ToString());
 }
Ejemplo n.º 17
0
        public IEnumerable<Type> BindExchangesForPublisher(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            AddPublisherBinding();

            IList<Type> messageTypes = new List<Type>();
            _connectionHandler.Use(connection =>
                {
                    MessageName messageName = messageNameFormatter.GetMessageName(messageType);

                    _publisher.ExchangeDeclare(messageName.ToString());
                    messageTypes.Add(messageType);

                    foreach (Type type in messageType.GetMessageTypes().Skip(1))
                    {
                        MessageName interfaceName = messageNameFormatter.GetMessageName(type);

                        _publisher.ExchangeBind(interfaceName.ToString(), messageName.ToString());
                        messageTypes.Add(type);
                    }
                });

            return messageTypes;
        }
        public IEnumerable<Type> SubscribeTopicsForPublisher(Type messageType,
            IMessageNameFormatter messageNameFormatter)
        {
            AddPublisherBinding();

            IList<Type> messageTypes = new List<Type>();
            _connectionHandler.Use(connection =>
                {
                    MessageName messageName = messageNameFormatter.GetMessageName(messageType);

                    _publisher.CreateTopic(messageName.ToString());
                    messageTypes.Add(messageType);

                    foreach (Type type in messageType.GetMessageTypes().Skip(1))
                    {
                        MessageName interfaceName = messageNameFormatter.GetMessageName(type);

                        _publisher.AddTopicSubscription(interfaceName.ToString(), messageName.ToString());
                        messageTypes.Add(type);
                    }
                });

            return messageTypes;
        }