Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RabbitBroker"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="InvalidOperationException">the broker is used without configuration</exception>
        public RabbitBroker(ServerBrokerConfiguration configuration)
        {
            Configuration = configuration;

            if (Configuration == null)
            {
                Trace.WriteLine("the broker is used without configuration", TraceLevel.Error.ToString());
                throw new InvalidOperationException("the broker is used without configuration");
            }
        }
        /// <summary>
        /// Loads the server from connection string.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns></returns>
        /// <exception cref="InvalidConfigurationException">Failed to load configuration {payload}</exception>
        public static ServerBrokerConfiguration LoadServerFromConnectionString(this string payload)
        {
            var config = new ServerBrokerConfiguration();

            if (!LoadFromConnectionString <ServerBrokerConfiguration>(payload, config))
            {
                throw new InvalidConfigurationException($"Failed to load configuration {payload}");
            }
            return(config);
        }
Example #3
0
        public void TestSerializeDeserializeJSon()
        {
            string server = new ServerBrokerConfiguration()
            {
                Name      = "n1",
                Hostname  = "localhost",
                UserName  = "******",
                Password  = "******",
                Port      = 15672,
                UseLogger = true,
            }.SaveToJSon();

            var server2 = server.LoadServerFromJson();

            Assert.AreEqual(server2.Hostname, "localhost");
        }