/// <summary>
        ///     Creates a policy on the cluster
        /// </summary>
        /// <param name="source"></param>
        /// <param name="policy">Policy to create</param>
        /// <param name="cancellationToken"></param>
        public static void CreatePolicy(
            [NotNull] this IManagementClient source,
            [NotNull] Policy policy,
            CancellationToken cancellationToken = default
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            source.CreatePolicyAsync(policy, cancellationToken)
            .GetAwaiter()
            .GetResult();
        }
Esempio n. 2
0
        public async Task Should_be_able_to_create_policies()
        {
            const string     policyName = "asamplepolicy";
            const HaMode     haMode     = HaMode.All;
            const HaSyncMode haSyncMode = HaSyncMode.Automatic;
            await managementClient.CreatePolicyAsync(new Policy
            {
                Name       = policyName,
                Pattern    = "averyuncommonpattern",
                Vhost      = vhostName,
                Definition = new PolicyDefinition
                {
                    HaMode     = haMode,
                    HaSyncMode = haSyncMode
                }
            }).ConfigureAwait(false);

            Assert.Equal(1, (await managementClient.GetPoliciesAsync().ConfigureAwait(false)).Count(
                             p => p.Name == policyName &&
                             p.Vhost == vhostName &&
                             p.ApplyTo == ApplyMode.All &&
                             p.Definition.HaMode == haMode &&
                             p.Definition.HaSyncMode == haSyncMode));
        }
Esempio n. 3
0
        public async Task Should_be_able_to_create_all_the_defitions_in_a_policy()
        {
            const string     policyName           = "a-sample-all-definitions-in-a-policy";
            const int        priority             = 999;
            const HaMode     haMode               = HaMode.All;
            const HaSyncMode haSyncMode           = HaSyncMode.Automatic;
            const string     alternateExchange    = "a-sample-alternate-exchange";
            const string     deadLetterExchange   = "a-sample-dead-letter-exchange";
            const string     deadLetterRoutingKey = "a-sample-dead-letter-exchange-key";
            const uint       messageTtl           = 5000;
            const uint       expires              = 10000;
            const uint       maxLength            = 500;
            await managementClient.CreatePolicyAsync(new Policy
            {
                Name       = policyName,
                Pattern    = "averyuncommonpattern",
                Vhost      = vhostName,
                Definition = new PolicyDefinition
                {
                    HaMode               = haMode,
                    HaSyncMode           = haSyncMode,
                    AlternateExchange    = alternateExchange,
                    DeadLetterExchange   = deadLetterExchange,
                    DeadLetterRoutingKey = deadLetterRoutingKey,
                    MessageTtl           = messageTtl,
                    Expires              = expires,
                    MaxLength            = maxLength
                },
                Priority = priority
            }).ConfigureAwait(false);

            Assert.Equal(1, (await managementClient.GetPoliciesAsync().ConfigureAwait(false)).Count(
                             p => p.Name == policyName &&
                             p.Vhost == vhostName &&
                             p.Priority == priority &&
                             p.Definition.HaMode == haMode &&
                             p.Definition.HaSyncMode == haSyncMode &&
                             p.Definition.AlternateExchange == alternateExchange &&
                             p.Definition.DeadLetterExchange == deadLetterExchange &&
                             p.Definition.DeadLetterRoutingKey == deadLetterRoutingKey &&
                             p.Definition.MessageTtl == messageTtl &&
                             p.Definition.Expires == expires &&
                             p.Definition.MaxLength == maxLength));
        }