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);
            }
        }
Esempio n. 2
0
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            try
            {
                _nameFormatter = new RabbitMqMessageNameFormatter();

                ConnectionFactory connectionFactory = host.Settings.GetConnectionFactory();
                using (IConnection connection = connectionFactory.CreateConnection())
                    using (IModel model = connection.CreateModel())
                    {
                        model.ExchangeDelete("input_queue");
                        model.QueueDelete("input_queue");

                        model.ExchangeDelete("input_queue_skipped");
                        model.QueueDelete("input_queue_skipped");

                        model.ExchangeDelete("input_queue_error");
                        model.QueueDelete("input_queue_error");

                        model.ExchangeDelete("input_queue_delay");
                        model.QueueDelete("input_queue_delay");

                        OnCleanupVirtualHost(model);

                        model.Abort(200, "Cleanup complete");
                        connection.Abort(200, "Cleanup complete");
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Esempio n. 3
0
 public ActiveMqHostTopology(IMessageNameFormatter messageNameFormatter, Uri hostAddress, IActiveMqTopologyConfiguration topologyConfiguration)
     : base(topologyConfiguration)
 {
     _messageNameFormatter  = messageNameFormatter;
     _hostAddress           = hostAddress;
     _topologyConfiguration = topologyConfiguration;
 }
Esempio n. 4
0
        public RabbitMqReceiveEndpointBuilder(IConsumePipe consumePipe, IMessageNameFormatter messageNameFormatter)
        {
            _consumePipe          = consumePipe;
            _messageNameFormatter = messageNameFormatter;

            _exchangeBindings = new List <ExchangeBindingSettings>();
        }
Esempio n. 5
0
 public AmazonSqsHostTopology(IMessageNameFormatter messageNameFormatter, Uri hostAddress, IAmazonSqsTopologyConfiguration configuration)
     : base(configuration)
 {
     _messageNameFormatter = messageNameFormatter;
     _hostAddress          = hostAddress;
     _configuration        = configuration;
 }
Esempio n. 6
0
 public ServiceBusPublishEndpointProvider(IServiceBusHost host, ISendEndpointProvider sendEndpointProvider)
 {
     _host = host;
     _sendEndpointProvider = sendEndpointProvider;
     _nameFormatter        = host.MessageNameFormatter;
     _publishObservable    = new PublishObservable();
 }
        /// <summary>
        /// c'tor
        /// </summary>
        /// <param name="bus"></param>
        public PublishEndpointInterceptor([NotNull] ServiceBus bus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }
            _bus = bus;

            var inbound = bus.Endpoint.InboundTransport as InboundAzureServiceBusTransport;

            if (inbound == null)
            {
                throw new ConfigurationException(
                          "The bus must be configured to receive from an Azure ServiceBus Endpoint for this interceptor to work.");
            }
            _inbound   = inbound;
            _formatter = inbound.MessageNameFormatter;

            var address = inbound.Address as IAzureServiceBusEndpointAddress;

            if (address == null)
            {
                throw new ConfigurationException("The bus inbound address must be an azure service bus address");
            }

            _address = address;
            _added   = new ConcurrentCache <Type, UnsubscribeAction>();
        }
		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 ServiceBusPublishEndpointProvider(IServiceBusHost host, ISendEndpointProvider sendEndpointProvider)
 {
     _host = host;
     _sendEndpointProvider = sendEndpointProvider;
     _nameFormatter = host.MessageNameFormatter;
     _publishObservable = new PublishObservable();
 }
        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);

                    // Create topics for inherited types before trying to setup the subscription
                    _publisher.CreateTopic(interfaceName.Name.ToString());

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

            return(messageTypes);
        }
 public ServiceBusReceiveEndpointBuilder(IConsumePipe consumePipe, IMessageNameFormatter messageNameFormatter, bool subscribeMessageTopics)
 {
     _consumePipe            = consumePipe;
     _messageNameFormatter   = messageNameFormatter;
     _subscribeMessageTopics = subscribeMessageTopics;
     _topicSubscriptions     = new List <TopicSubscriptionSettings>();
 }
        public IEnumerable <Type> BindExchangesForPublisher(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            AddPublisherBinding();

            IList <Type> messageTypes = new List <Type>();

            _connectionHandler.Use(connection =>
            {
                MessageName messageName = messageNameFormatter.GetMessageName(messageType);

                bool temporary = IsTemporaryMessageType(messageType);

                _publisher.ExchangeDeclare(messageName.ToString(), temporary);

                messageTypes.Add(messageType);

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

                    bool isTemporary = IsTemporaryMessageType(type);

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

            return(messageTypes);
        }
Esempio n. 13
0
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            try
            {
                _nameFormatter = new RabbitMqMessageNameFormatter();

                var connectionFactory = host.Settings.GetConnectionFactory();
                using (
                    var connection = host.Settings.ClusterMembers?.Any() ?? false
                        ? connectionFactory.CreateConnection(host.Settings.ClusterMembers, host.Settings.Host)
                        : connectionFactory.CreateConnection())
                    using (var model = connection.CreateModel())
                    {
                        model.ExchangeDelete("input_queue");
                        model.QueueDelete("input_queue");

                        model.ExchangeDelete("input_queue_skipped");
                        model.QueueDelete("input_queue_skipped");

                        model.ExchangeDelete("input_queue_error");
                        model.QueueDelete("input_queue_error");

                        model.ExchangeDelete("input_queue_delay");
                        model.QueueDelete("input_queue_delay");

                        OnCleanupVirtualHost(model);
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Esempio n. 14
0
        public AzureServiceBusInboundTransport([NotNull] IAzureServiceBusEndpointAddress address,
                                               [NotNull] ConnectionHandler <AzureServiceBusConnection> connectionHandler,
                                               [NotNull] AzureManagement management,
                                               [CanBeNull] IMessageNameFormatter formatter   = null,
                                               [CanBeNull] ReceiverSettings receiverSettings = null)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (connectionHandler == null)
            {
                throw new ArgumentNullException("connectionHandler");
            }
            if (management == null)
            {
                throw new ArgumentNullException("management");
            }

            _address           = address;
            _connectionHandler = connectionHandler;
            _management        = management;
            _formatter         = formatter ?? new AzureServiceBusMessageNameFormatter();
            _receiverSettings  = receiverSettings; // can be null all the way to usage in Receiver.

            _logger.DebugFormat("created new inbound transport for '{0}'", address);
        }
Esempio n. 15
0
 public AmazonSqsMessageNameFormatter()
 {
     _formatter = new AmazonArnMessageNameFormatter(
         genericArgumentSeparator: "__",
         genericTypeSeparator: "--",
         namespaceSeparator: "-",
         nestedTypeSeparator: "_");
 }
        public ServiceBusHostTopology(IServiceBusTopologyConfiguration configuration, Uri hostAddress, IMessageNameFormatter messageNameFormatter = null)
            : base(configuration)
        {
            _configuration = configuration;
            _hostAddress   = hostAddress;

            _messageNameFormatter = messageNameFormatter ?? new ServiceBusMessageNameFormatter(false);
        }
Esempio n. 17
0
        public ServiceBusHostTopology(IServiceBusTopologyConfiguration configuration, Uri hostAddress)
            : base(configuration)
        {
            _configuration = configuration;
            _hostAddress   = hostAddress;

            _messageNameFormatter = new ServiceBusMessageNameFormatter();
        }
Esempio n. 18
0
 public AmazonSqsHostTopology(IAmazonSqsHostConfiguration hostConfiguration, IMessageNameFormatter messageNameFormatter,
                              IAmazonSqsTopologyConfiguration configuration)
     : base(hostConfiguration, configuration)
 {
     _hostConfiguration    = hostConfiguration;
     _messageNameFormatter = messageNameFormatter;
     _configuration        = configuration;
 }
Esempio n. 19
0
 public RabbitMqHostTopology(IRabbitMqHostConfiguration hostConfiguration, IMessageNameFormatter messageNameFormatter, Uri hostAddress,
                             IRabbitMqTopologyConfiguration configuration)
     : base(hostConfiguration, configuration)
 {
     _messageNameFormatter = messageNameFormatter;
     _hostAddress          = hostAddress;
     _configuration        = configuration;
 }
Esempio n. 20
0
 public RabbitMqPublishEndpointProvider(IRabbitMqHost host, IMessageSerializer serializer, Uri sourceAddress)
 {
     _host                 = host;
     _serializer           = serializer;
     _sourceAddress        = sourceAddress;
     _messageNameFormatter = host.MessageNameFormatter;
     _cachedEndpoints      = new ConcurrentDictionary <Type, Lazy <ISendEndpoint> >();
     _publishObservable    = new PublishObservable();
 }
Esempio n. 21
0
        public ServiceBusHost(ServiceBusHostSettings settings)
        {
            _settings = settings;
            _messagingFactory = new Lazy<Task<MessagingFactory>>(CreateMessagingFactory);
            _namespaceManager = new Lazy<Task<NamespaceManager>>(CreateNamespaceManager);
            _rootNamespaceManager = new Lazy<Task<NamespaceManager>>(CreateRootNamespaceManager);

            _messageNameFormatter = new ServiceBusMessageNameFormatter();
        }
 public RabbitMqPublishEndpointProvider(IRabbitMqHost host, IMessageSerializer serializer, Uri sourceAddress)
 {
     _host = host;
     _serializer = serializer;
     _sourceAddress = sourceAddress;
     _messageNameFormatter = host.MessageNameFormatter;
     _cachedEndpoints = new ConcurrentDictionary<Type, Lazy<ISendEndpoint>>();
     _publishObservable = new PublishObservable();
 }
Esempio n. 23
0
        public ServiceBusHost(ServiceBusHostSettings settings)
        {
            _settings             = settings;
            _messagingFactory     = new Lazy <Task <MessagingFactory> >(CreateMessagingFactory);
            _namespaceManager     = new Lazy <Task <NamespaceManager> >(CreateNamespaceManager);
            _rootNamespaceManager = new Lazy <Task <NamespaceManager> >(CreateRootNamespaceManager);

            _messageNameFormatter = new ServiceBusMessageNameFormatter();
        }
Esempio n. 24
0
 public RabbitMqHostTopology(IExchangeTypeSelector exchangeTypeSelector, IMessageNameFormatter messageNameFormatter,
                             Uri hostAddress, IRabbitMqTopologyConfiguration configuration)
     : base(configuration)
 {
     _exchangeTypeSelector = exchangeTypeSelector;
     _messageNameFormatter = messageNameFormatter;
     _hostAddress          = hostAddress;
     _configuration        = configuration;
 }
 public InboundRabbitMqTransport(IRabbitMqEndpointAddress address,
     ConnectionHandler<RabbitMqConnection> connectionHandler,
     bool purgeExistingMessages,
     IMessageNameFormatter messageNameFormatter)
 {
     _address = address;
     _connectionHandler = connectionHandler;
     _purgeExistingMessages = purgeExistingMessages;
     _messageNameFormatter = messageNameFormatter;
 }
        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;
        }
Esempio n. 27
0
 public InboundRabbitMqTransport(IRabbitMqEndpointAddress address,
                                 ConnectionHandler <RabbitMqConnection> connectionHandler,
                                 bool purgeExistingMessages,
                                 IMessageNameFormatter messageNameFormatter)
 {
     _address               = address;
     _connectionHandler     = connectionHandler;
     _purgeExistingMessages = purgeExistingMessages;
     _messageNameFormatter  = messageNameFormatter;
 }
Esempio n. 28
0
        public static TopicSubscriptionSettings GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = new TopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());

            var binding = new TopicSubscription(topicDescription);

            return(binding);
        }
 public RabbitMqTransportFactory()
 {
     _inboundConnections = new ConcurrentCache <ConnectionFactory, ConnectionHandler <RabbitMqConnection> >(
         new ConnectionFactoryEquality());
     _outboundConnections = new ConcurrentCache <ConnectionFactory, ConnectionHandler <RabbitMqConnection> >(
         new ConnectionFactoryEquality());
     _connectionFactoryBuilders =
         new ConcurrentCache <ConnectionFactory, ConnectionFactoryBuilder>(new ConnectionFactoryEquality());
     _messageNameFormatter = new RabbitMqMessageNameFormatter();
 }
Esempio n. 30
0
 public RabbitTransportFactory()
 {
     _publisherConfirmSettings = new PublisherConfirmSettings();
     _inboundConnections       = new ConcurrentCache <ConnectionFactory, IConnectionHandler <TransportConnection> >(
         new ConnectionFactoryEquality());
     _outboundConnections = new ConcurrentCache <ConnectionFactory, IConnectionHandler <TransportConnection> >(
         new ConnectionFactoryEquality());
     _connectionFactoryBuilders =
         new ConcurrentCache <ConnectionFactory, IConnectionFactoryBuilder>(new ConnectionFactoryEquality());
     _messageNameFormatter = new MessageNameFormatter();
 }
        public static Uri GetTopicAddress(this IMessageNameFormatter messageNameFormatter, IServiceBusHost host, Type messageType)
        {
            string messageName = messageNameFormatter.GetMessageName(messageType).ToString();

            var builder = new UriBuilder(host.Settings.ServiceUri)
            {
                Path = messageName
            };

            return(builder.Uri);
        }
Esempio n. 32
0
        public ServiceBusHost(ServiceBusHostSettings settings)
        {
            _settings                = settings;
            _messagingFactory        = new Lazy <Task <MessagingFactory> >(CreateMessagingFactory);
            _sessionMessagingFactory = new Lazy <Task <MessagingFactory> >(CreateNetMessagingFactory);
            _namespaceManager        = new Lazy <Task <NamespaceManager> >(CreateNamespaceManager);
            _rootNamespaceManager    = new Lazy <Task <NamespaceManager> >(CreateRootNamespaceManager);

            _messageNameFormatter = new ServiceBusMessageNameFormatter();

            _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {_settings.ServiceUri}");
        }
Esempio n. 33
0
        public ServiceBusHost(ServiceBusHostSettings settings)
        {
            _settings = settings;
            _messagingFactory = new Lazy<Task<MessagingFactory>>(CreateMessagingFactory);
            _sessionMessagingFactory = new Lazy<Task<MessagingFactory>>(CreateNetMessagingFactory);
            _namespaceManager = new Lazy<Task<NamespaceManager>>(CreateNamespaceManager);
            _rootNamespaceManager = new Lazy<Task<NamespaceManager>>(CreateRootNamespaceManager);

            _messageNameFormatter = new ServiceBusMessageNameFormatter();

            _supervisor = new TaskSupervisor($"{TypeMetadataCache<ServiceBusHost>.ShortName} - {_settings.ServiceUri}");
        }
		public TopicSubscriptionObserver(
			[NotNull] IMessageNameFormatter formatter,
			[NotNull] InboundTransportImpl inboundTransport)
		{
			if (formatter == null) throw new ArgumentNullException("formatter");
			if (inboundTransport == null) throw new ArgumentNullException("inboundTransport");

			_formatter = formatter;
			_inboundTransport = inboundTransport;

			_bindings = new Dictionary<Guid, TopicDescription>();
		}
        public RabbitMqSubscriptionBinder(IServiceBus bus)
        {
            _bindings = new Dictionary<Guid, MessageName>();

            _inboundTransport = bus.Endpoint.InboundTransport as InboundRabbitMqTransport;
            if (_inboundTransport == null)
                throw new ConfigurationException(
                    "The bus must be receiving from a RabbitMQ endpoint for this interceptor to work");

            _inputAddress = _inboundTransport.Address.CastAs<IRabbitMqEndpointAddress>();

            _messageNameFormatter = _inboundTransport.MessageNameFormatter;
        }
        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;
        }
        public static TopicSubscriptionSettings GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = new TopicDescription(messageNameFormatter.GetMessageName(messageType).ToString())
            {
                EnableBatchedOperations  = true,
                EnableExpress            = temporary,
                DefaultMessageTimeToLive = TimeSpan.FromDays(365)
            };

            var binding = new TopicSubscription(topicDescription);

            return(binding);
        }
Esempio n. 38
0
        public RabbitMqSubscriptionBinder(IServiceBus bus)
        {
            _bindings = new Dictionary <Guid, MessageName>();

            _inboundTransport = bus.Endpoint.InboundTransport as InboundRabbitMqTransport;
            if (_inboundTransport == null)
            {
                throw new ConfigurationException(
                          "The bus must be receiving from a RabbitMQ endpoint for this interceptor to work");
            }

            _inputAddress = _inboundTransport.Address.CastAs <IRabbitMqEndpointAddress>();

            _messageNameFormatter = _inboundTransport.MessageNameFormatter;
        }
Esempio n. 39
0
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            _nameFormatter = new RabbitMqMessageNameFormatter();

            ConnectionFactory connectionFactory = host.Settings.GetConnectionFactory();

            using (IConnection connection = connectionFactory.CreateConnection())
                using (IModel model = connection.CreateModel())
                {
                    model.ExchangeDelete("input_queue");
                    model.QueueDelete("input_queue");

                    OnCleanupVirtualHost(model);
                }
        }
Esempio n. 40
0
        public RabbitMqTransportFactory(IEnumerable <KeyValuePair <Uri, ConnectionFactoryBuilder> > connectionFactoryBuilders)
        {
            _connections = new ConcurrentCache <ConnectionFactory, ConnectionHandler <RabbitMqConnection> >(
                new ConnectionFactoryEquality());

            Dictionary <ConnectionFactory, ConnectionFactoryBuilder> builders = connectionFactoryBuilders
                                                                                .Select(x => new KeyValuePair <ConnectionFactory, ConnectionFactoryBuilder>(
                                                                                            RabbitMqEndpointAddress.Parse(x.Key).ConnectionFactory, x.Value))
                                                                                .ToDictionary(x => x.Key, x => x.Value);

            _connectionFactoryBuilders = new ConcurrentCache <ConnectionFactory, ConnectionFactoryBuilder>(builders,
                                                                                                           new ConnectionFactoryEquality());

            _messageNameFormatter = new RabbitMqMessageNameFormatter();
        }
        public InboundAzureServiceBusTransport(IAzureServiceBusEndpointAddress address,
            ConnectionHandler<AzureServiceBusConnection> connectionHandler,
            IMessageNameFormatter formatter = null,
            IInboundSettings inboundSettings = null)
        {
            if (address == null)
                throw new ArgumentNullException("address");
            if (connectionHandler == null)
                throw new ArgumentNullException("connectionHandler");

            _address = address;
            _connectionHandler = connectionHandler;
            _formatter = formatter ?? new AzureServiceBusMessageNameFormatter();
            _inboundSettings = inboundSettings;

            _logger.DebugFormat("created new inbound transport for '{0}'", address);
        }
		public InboundTransportImpl([NotNull] AzureServiceBusEndpointAddress address,
			[NotNull] ConnectionHandler<ConnectionImpl> connectionHandler,
			[NotNull] AzureManagement management, 
			[CanBeNull] IMessageNameFormatter formatter = null,
			[CanBeNull] ReceiverSettings receiverSettings = null)
		{
			if (address == null) throw new ArgumentNullException("address");
			if (connectionHandler == null) throw new ArgumentNullException("connectionHandler");
			if (management == null) throw new ArgumentNullException("management");

			_address = address;
			_connectionHandler = connectionHandler;
			_management = management;
			_formatter = formatter ?? new AzureMessageNameFormatter();
			_receiverSettings = receiverSettings; // can be null all the way to usage in Receiver.

			_logger.DebugFormat("created new inbound transport for '{0}'", address);
		}
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            _nameFormatter = new RabbitMqMessageNameFormatter();

            ConnectionFactory connectionFactory = host.Settings.GetConnectionFactory();
            using (IConnection connection = connectionFactory.CreateConnection())
            using (IModel model = connection.CreateModel())
            {
                model.ExchangeDelete("input_queue");
                model.QueueDelete("input_queue");

                OnCleanupVirtualHost(model);
            }
        }
 public RabbitMqTransportFactory()
 {
     _connectionCache = new ReaderWriterLockedDictionary<Uri, ConnectionHandler<RabbitMqConnection>>();
     _connectionFactoryBuilders = new Dictionary<Uri, ConnectionFactoryBuilder>();
     _messageNameFormatter = new RabbitMqMessageNameFormatter();
 }
Esempio n. 45
0
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            try
            {
                _nameFormatter = new RabbitMqMessageNameFormatter();

                ConnectionFactory connectionFactory = host.Settings.GetConnectionFactory();
                using (IConnection connection = connectionFactory.CreateConnection())
                using (IModel model = connection.CreateModel())
                {
                    model.ExchangeDelete("input_queue");
                    model.QueueDelete("input_queue");

                    model.ExchangeDelete("input_queue_skipped");
                    model.QueueDelete("input_queue_skipped");

                    model.ExchangeDelete("input_queue_error");
                    model.QueueDelete("input_queue_error");

                    model.ExchangeDelete("input_queue_delay");
                    model.QueueDelete("input_queue_delay");

                    OnCleanupVirtualHost(model);

                    model.Abort(200, "Cleanup complete");
                    connection.Abort(200, "Cleanup complete");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        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");
            }
        }
        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;
        }
        void CleanUpVirtualHost(IRabbitMqHost host)
        {
            try
            {
                _nameFormatter = new RabbitMqMessageNameFormatter();

                var connectionFactory = host.Settings.GetConnectionFactory();
                using (
                    var connection = host.Settings.ClusterMembers?.Any() ?? false
                        ? connectionFactory.CreateConnection(host.Settings.ClusterMembers, host.Settings.Host)
                        : connectionFactory.CreateConnection())
                using (var model = connection.CreateModel())
                {
                    model.ExchangeDelete("input_queue");
                    model.QueueDelete("input_queue");

                    model.ExchangeDelete("input_queue_skipped");
                    model.QueueDelete("input_queue_skipped");

                    model.ExchangeDelete("input_queue_error");
                    model.QueueDelete("input_queue_error");

                    model.ExchangeDelete("input_queue_delay");
                    model.QueueDelete("input_queue_delay");

                    OnCleanupVirtualHost(model);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        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 MsmqTransportFactory()
 {
     _messageNameFormatter = new DefaultMessageNameFormatter("::", "--", ":", "-");
 }
        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;
        }
        public void BindExchangesForSubscriber(Type messageType, IMessageNameFormatter messageNameFormatter)
        {
            MessageName messageName = messageNameFormatter.GetMessageName(messageType);

            BindExchange(_address.Name, messageName.ToString(), ExchangeType.Fanout, "");
        }
 public LoopbackTransportFactory()
 {
     _transports = new ConcurrentCache<Uri, LoopbackTransport>();
     _messageNameFormatter = new DefaultMessageNameFormatter("::", "--", ":", "-");
 }
 public ServiceBusMessageNameFormatter()
 {
     _formatter = new DefaultMessageNameFormatter("::", "--", "/", "-");
 }
 public RabbitMqMessageNameFormatter()
 {
     _formatter = new DefaultMessageNameFormatter("::", "--", ":", "-");
 }