Apache.NMS.Test.NMSTestSupport.ReplaceEnvVar C# (CSharp) Method

ReplaceEnvVar() public static method

Replace embedded variable markups with environment variable values. Variable markups are of the following form: ${varname}
public static ReplaceEnvVar ( string srcText ) : string
srcText string
return string
        public static string ReplaceEnvVar(string srcText)
        {
            // NOTE: Might be able to refactor to be more generic and support full variable
            // names that can be pulled from the environment.  Currently, we only support limited
            // hard-coded variable names.

            string defaultBroker = GetEnvVar("NMSTestBroker", "activemqhost");

            srcText = ReplaceEnvVar(srcText, "ActiveMQHost", defaultBroker);
            srcText = ReplaceEnvVar(srcText, "ActiveMQBackupHost", defaultBroker);

            srcText = ReplaceEnvVar(srcText, "TIBCOHost", defaultBroker);
            srcText = ReplaceEnvVar(srcText, "TIBCOBackupHost", defaultBroker);

            srcText = ReplaceEnvVar(srcText, "MSMQHost", defaultBroker);
            srcText = ReplaceEnvVar(srcText, "MSMQBackupHost", defaultBroker);
            return srcText;
        }

Same methods

NMSTestSupport::ReplaceEnvVar ( string srcText, string varName, string defaultValue ) : string

Usage Example

        public void TestURIForRedeliverPolicyHandling()
        {
            string uri1 = "activemq:tcp://${activemqhost}:61616" +
                          "?nms.RedeliveryPolicy.BackOffMultiplier=10" +
                          "&nms.RedeliveryPolicy.InitialRedeliveryDelay=2000" +
                          "&nms.RedeliveryPolicy.UseExponentialBackOff=true" +
                          "&nms.RedeliveryPolicy.UseCollisionAvoidance=true" +
                          "&nms.RedeliveryPolicy.CollisionAvoidancePercent=20";

            string uri2 = "activemq:tcp://${activemqhost}:61616" +
                          "?nms.RedeliveryPolicy.backOffMultiplier=50" +
                          "&nms.RedeliveryPolicy.initialRedeliveryDelay=4000" +
                          "&nms.RedeliveryPolicy.useExponentialBackOff=false" +
                          "&nms.RedeliveryPolicy.useCollisionAvoidance=false" +
                          "&nms.RedeliveryPolicy.collisionAvoidancePercent=10";

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri1));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;

                Assert.AreEqual(10, amqConnection.RedeliveryPolicy.BackOffMultiplier);
                Assert.AreEqual(2000, amqConnection.RedeliveryPolicy.InitialRedeliveryDelay);
                Assert.AreEqual(true, amqConnection.RedeliveryPolicy.UseExponentialBackOff);
                Assert.AreEqual(true, amqConnection.RedeliveryPolicy.UseCollisionAvoidance);
                Assert.AreEqual(20, amqConnection.RedeliveryPolicy.CollisionAvoidancePercent);
            }

            factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri2));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(50, amqConnection.RedeliveryPolicy.BackOffMultiplier);
                Assert.AreEqual(4000, amqConnection.RedeliveryPolicy.InitialRedeliveryDelay);
                Assert.AreEqual(false, amqConnection.RedeliveryPolicy.UseExponentialBackOff);
                Assert.AreEqual(false, amqConnection.RedeliveryPolicy.UseCollisionAvoidance);
                Assert.AreEqual(10, amqConnection.RedeliveryPolicy.CollisionAvoidancePercent);
            }
        }
All Usage Examples Of Apache.NMS.Test.NMSTestSupport::ReplaceEnvVar