Ejemplo n.º 1
0
        /// <summary>
        /// Creates cluster publish subscribe settings from provided configuration with the same layout as `akka.cluster.pub-sub`.
        /// </summary>
        public static DistributedPubSubSettings Create(Config config)
        {
            RoutingLogic routingLogic     = null;
            var          routingLogicName = config.GetString("routing-logic");

            switch (routingLogicName)
            {
            case "random":
                routingLogic = new RandomLogic();
                break;

            case "round-robin":
                routingLogic = new RoundRobinRoutingLogic();
                break;

            case "broadcast":
                routingLogic = new BroadcastRoutingLogic();
                break;

            case "consistent-hashing":
                throw new ArgumentException("Consistent hashing routing logic cannot be used by the pub-sub mediator");

            default:
                throw new ArgumentException("Unknown routing logic is tried to be applied to the pub-sub mediator: " +
                                            routingLogicName);
            }

            return(new DistributedPubSubSettings(
                       config.GetString("role"),
                       routingLogic,
                       config.GetTimeSpan("gossip-interval"),
                       config.GetTimeSpan("removed-time-to-live"),
                       config.GetInt("max-delta-elements")));
        }
        /// <summary>
        /// Creates cluster publish subscribe settings from provided configuration with the same layout as `akka.cluster.pub-sub`.
        /// </summary>
        /// <param name="config">TBD</param>
        /// <exception cref="ArgumentException">TBD</exception>
        /// <returns>TBD</returns>
        public static DistributedPubSubSettings Create(Config config)
        {
            if (config.IsNullOrEmpty())
            {
                throw ConfigurationException.NullOrEmptyConfig <DistributedPubSubSettings>();
            }

            RoutingLogic routingLogic     = null;
            var          routingLogicName = config.GetString("routing-logic");

            switch (routingLogicName)
            {
            case "random":
                routingLogic = new RandomLogic();
                break;

            case "round-robin":
                routingLogic = new RoundRobinRoutingLogic();
                break;

            case "broadcast":
                routingLogic = new BroadcastRoutingLogic();
                break;

            case "consistent-hashing":
                throw new ArgumentException("Consistent hashing routing logic cannot be used by the pub-sub mediator");

            default:
                throw new ArgumentException("Unknown routing logic is tried to be applied to the pub-sub mediator: " +
                                            routingLogicName);
            }

            // TODO: This will fail if DistributedPubSub.DefaultConfig() is not inside the fallback chain.
            // TODO: "gossip-interval" key depends on Config.GetTimeSpan() to return a TimeSpan.Zero default.
            // TODO: "removed-time-to-live" key depends on Config.GetTimeSpan() to return a TimeSpan.Zero default.
            // TODO: "max-delta-elements" key depends on Config.GetInt() to return a 0 default.
            return(new DistributedPubSubSettings(
                       config.GetString("role", null),
                       routingLogic,
                       config.GetTimeSpan("gossip-interval"),
                       config.GetTimeSpan("removed-time-to-live"),
                       config.GetInt("max-delta-elements"),
                       config.GetBoolean("send-to-dead-letters-when-no-subscribers")));
        }