Esempio n. 1
0
        /// <summary>
        /// Deletes all dynamic shovels on a specified RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="vhost">The virtual host where the dynamic shovel resides.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <IReadOnlyList <Result> > DeleteAllShovels(this IBrokerObjectFactory factory,
                                                                            string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var result = await factory.Object <Shovel>()
                         .GetAll(cancellationToken)
                         .ConfigureAwait(false);

            if (result.HasFaulted)
            {
                return(new List <Result>());
            }

            var shovels = result
                          .Select(x => x.Data)
                          .Where(x => x.VirtualHost == vhost && x.Type == ShovelType.Dynamic)
                          .ToList();

            var results = new List <Result>();

            foreach (var shovel in shovels)
            {
                var deleteResult = await factory.Object <Shovel>()
                                   .Delete(shovel.Name, vhost, cancellationToken)
                                   .ConfigureAwait(false);

                results.Add(deleteResult);
            }

            return(results);
        }
Esempio n. 2
0
 protected BaseSnapshotLens(IBrokerObjectFactory factory)
 {
     _factory   = factory;
     _observers = new List <IObserver <SnapshotContext <T> > >();
     _snapshots = new Dictionary <string, SnapshotResult <T> >();
     _timeline  = new Lazy <SnapshotHistory <T> >(() => new SnapshotHistoryImpl <T>(_snapshots));
 }
Esempio n. 3
0
        public GetAllChannelBenchmarks()
        {
            var services = GetContainerBuilder("Benchmarks/TestData/ChannelInfo.json")
                           .BuildServiceProvider();

            _service = services.GetService <IBrokerObjectFactory>();
        }
Esempio n. 4
0
        public SnapshotFactory(IBrokerObjectFactory factory)
        {
            _factory = factory;
            _cache   = new Dictionary <string, object>();

            if (!TryRegisterAll())
            {
                throw new HareDuSnapshotInitException("Could not register snapshot lenses.");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns all dynamic shovels that have been created.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <ResultList <ShovelInfo> > GetAllShovels(this IBrokerObjectFactory factory, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Shovel>()
                   .GetAll(cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 6
0
        public SnapshotFactory(HareDuConfig config)
        {
            _config  = config;
            _factory = new BrokerObjectFactory(_config);
            _cache   = new Dictionary <string, object>();

            if (!TryRegisterAll())
            {
                throw new HareDuSnapshotInitException("Could not register snapshot lenses.");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the specified binding between source exchange and destination exchange on the specified RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="sourceBinding">Source binding of the exchange.</param>
        /// <param name="destinationBinding">Destination binding of the exchange.</param>
        /// <param name="vhost">The virtual host where the binding is defined.</param>
        /// <param name="bindingKey">The routing pattern for a source to destination binding.</param>
        /// <param name="configurator">Describes how the binding will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateExchangeBinding(this IBrokerObjectFactory factory,
                                                                string sourceBinding, string destinationBinding, string vhost, string bindingKey = null, Action <BindingConfigurator> configurator = null, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Binding>()
                   .Create(sourceBinding, destinationBinding, BindingType.Exchange, vhost, bindingKey, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a user on the current RabbitMQ server.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="username">RabbitMQ broker username.</param>
        /// <param name="password">RabbitMQ broker password.</param>
        /// <param name="passwordHash">RabbitMQ broker password hash.</param>
        /// <param name="configurator">Describes how the user permission will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateUser(this IBrokerObjectFactory factory,
                                                     string username, string password, string passwordHash = null, Action <UserConfigurator> configurator = null, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <User>()
                   .Create(username, password, passwordHash, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 9
0
        /// <summary>
        /// Purges all messages in the specified queue on the specified RabbitMQ virtual host on the current node.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="queue">Name of the RabbitMQ broker queue.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> EmptyQueue(this IBrokerObjectFactory factory,
                                                     string queue, string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Queue>()
                   .Empty(queue, vhost, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 10
0
        /// <summary>
        /// Creates specified queue on the specified RabbitMQ virtual host and node.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="queue">Name of the RabbitMQ broker queue.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="node">Name of the RabbitMQ node.</param>
        /// <param name="configurator">Describes how the queue will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateQueue(this IBrokerObjectFactory factory,
                                                      string queue, string vhost, string node, Action <QueueConfigurator> configurator, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Queue>()
                   .Create(queue, vhost, node, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a new topic permission for the specified user per a particular RabbitMQ exchange and virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="username">RabbitMQ broker username to apply topic permission to.</param>
        /// <param name="exchange">Name of the RabbitMQ exchange.</param>
        /// <param name="vhost">Name of the RabbitMQ virtual host.</param>
        /// <param name="configurator">Describes how the topic permission will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateTopicPermission(this IBrokerObjectFactory factory,
                                                                string username, string exchange, string vhost, Action <TopicPermissionsConfigurator> configurator, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <TopicPermissions>()
                   .Create(username, exchange, vhost, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 12
0
        /// <summary>
        /// Rebalances all queues in all RabbitMQ virtual hosts.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> RebalanceAllQueues(this IBrokerObjectFactory factory,
                                                             CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <BrokerSystem>()
                   .RebalanceAllQueues(cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 13
0
        /// <summary>
        /// Deletes the specified binding between exchange and queue on the specified RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="sourceBinding">Source binding of the queue.</param>
        /// <param name="destinationBinding">Destination binding of the queue.</param>
        /// <param name="propertiesKey">Combination of routing key and hash of its arguments.</param>
        /// <param name="vhost">The virtual host where the binding is defined.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> DeleteQueueBinding(this IBrokerObjectFactory factory,
                                                             string sourceBinding, string destinationBinding, string propertiesKey, string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Binding>()
                   .Delete(sourceBinding, destinationBinding, propertiesKey, vhost, BindingType.Queue, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 14
0
        /// <summary>
        /// Deletes the specified exchange on the target RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="exchange">Name of the RabbitMQ exchange.</param>
        /// <param name="vhost">Name of the RabbitMQ virtual host.</param>
        /// <param name="configurator">Describes how the queue will be deleted.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> DeleteExchange(this IBrokerObjectFactory factory,
                                                         string exchange, string vhost, Action <ExchangeDeletionConfigurator> configurator = null, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Exchange>()
                   .Delete(exchange, vhost, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 15
0
        /// <summary>
        /// Deletes the specified global parameter on the current RabbitMQ node.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="parameter">Name of the RabbitMQ parameter.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> DeleteGlobalParameter(this IBrokerObjectFactory factory,
                                                                string parameter, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <GlobalParameter>()
                   .Delete(parameter, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a scoped parameter for a particular RabbitMQ component and virtual host on the current server.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="parameter">Name of the RabbitMQ parameter.</param>
        /// <param name="value">Value of the RabbitMQ parameter.</param>
        /// <param name="component">Name of the RabbitMQ component.</param>
        /// <param name="vhost">Name of the RabbitMQ virtual host.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateScopeParameter <T>(this IBrokerObjectFactory factory,
                                                                   string parameter, T value, string component, string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <ScopedParameter>()
                   .Create(parameter, value, component, vhost, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 17
0
        /// <summary>
        /// Deletes a dynamic shovel on a specified RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="shovel">The name of the dynamic shovel.</param>
        /// <param name="vhost">The virtual host where the dynamic shovel resides.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> DeleteShovel(this IBrokerObjectFactory factory,
                                                       string shovel, string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Shovel>()
                   .Delete(shovel, vhost, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 18
0
        /// <summary>
        /// Deletes the specified user on the current RabbitMQ server.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="username">RabbitMQ broker username.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> DeleteUserPermissions(this IBrokerObjectFactory factory, string username,
                                                                string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <UserPermissions>()
                   .Delete(username, vhost, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 19
0
        /// <summary>
        /// Returns the memory usage information on the specified RabbitMQ node.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="node">Name of the RabbitMQ node.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result <NodeMemoryUsageInfo> > GetNodeMemoryUsage(this IBrokerObjectFactory factory,
                                                                                    string node, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <Node>()
                   .GetMemoryUsage(node, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 20
0
        /// <summary>
        /// Starts up the specified RabbitMQ virtual host on the specified node.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="node">Name of the RabbitMQ server node.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> StartupVirtualHost(this IBrokerObjectFactory factory,
                                                             string vhost, string node, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <VirtualHost>()
                   .Startup(vhost, node, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 21
0
        /// <summary>
        /// Creates the specified RabbitMQ virtual host on the current server.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="configurator">Describes how the virtual host will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateVirtualHost(this IBrokerObjectFactory factory,
                                                            string vhost, Action <VirtualHostConfigurator> configurator, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <VirtualHost>()
                   .Create(vhost, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 22
0
        /// <summary>
        /// Performs a health check on the specified RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result <ServerHealthInfo> > GetVirtualHostHealth(this IBrokerObjectFactory factory,
                                                                                   string vhost, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <VirtualHost>()
                   .GetHealth(vhost, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 23
0
        /// <summary>
        /// Creates the specified operator policy on the target RabbitMQ virtual host.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="policy">Name of the operator policy.</param>
        /// <param name="pattern">The pattern to apply the policy on.</param>
        /// <param name="vhost">The virtual host for which the policy should be applied to.</param>
        /// <param name="configurator">Describes how the operator policy will be created by setting arguments through set methods.</param>
        /// <param name="appliedTo">The broker object for which the policy is to be applied to.</param>
        /// <param name="priority"></param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateOperatorPolicy(this IBrokerObjectFactory factory, string policy,
                                                               string pattern, string vhost, Action <OperatorPolicyConfigurator> configurator,
                                                               OperatorPolicyAppliedTo appliedTo = default, int priority = default, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <OperatorPolicy>()
                   .Create(policy, pattern, vhost, configurator, appliedTo, priority, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a user permission and assign it to a user on a specific virtual host on the current RabbitMQ server.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="username">RabbitMQ broker username.</param>
        /// <param name="vhost">Name of the RabbitMQ broker virtual host.</param>
        /// <param name="configurator">Describes how the user permissions will be created.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result> CreateUserPermissions(this IBrokerObjectFactory factory,
                                                                string username, string vhost, Action <UserPermissionsConfigurator> configurator, CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (configurator.IsNull())
            {
                configurator = x =>
                {
                    x.UsingConfigurePattern(".*");
                    x.UsingReadPattern(".*");
                    x.UsingWritePattern(".*");
                };
            }

            return(await factory.Object <UserPermissions>()
                   .Create(username, vhost, configurator, cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 25
0
 public BrokerConnectivityImpl(IBrokerObjectFactory factory)
     : base(factory)
 {
     _observers = new List <IDisposable>();
 }
Esempio n. 26
0
 public BrokerQueuesImpl(IBrokerObjectFactory factory)
     : base(factory)
 {
     _observers = new List <IDisposable>();
 }
Esempio n. 27
0
        public CreateBenchmarks()
        {
            var services = GetContainerBuilder().BuildServiceProvider();

            _service = services.GetService <IBrokerObjectFactory>();
        }
Esempio n. 28
0
 public ClusterImpl(IBrokerObjectFactory factory)
     : base(factory)
 {
     _observers = new List <IDisposable>();
 }
Esempio n. 29
0
        /// <summary>
        /// Returns various bits of random information that describe the RabbitMQ system.
        /// </summary>
        /// <param name="factory">The object factory that implements the underlying functionality.</param>
        /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception>
        public static async Task <Result <SystemOverviewInfo> > GetBrokerSystemOverview(this IBrokerObjectFactory factory,
                                                                                        CancellationToken cancellationToken = default)
        {
            if (factory.IsNull())
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(await factory.Object <BrokerSystem>()
                   .GetSystemOverview(cancellationToken)
                   .ConfigureAwait(false));
        }