Inheritance: ConnectionFactory, INetTxConnectionFactory
        public void TestConfigureRecoveryPolicyLogger(string location, bool autoCreate)
        {
            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616" +
                                           "?nms.RecoveryPolicy.RecoveryLoggerType=file" +
                                           "&nms.RecoveryPolicy.RecoveryLogger.Location={0}" +
                                           "&nms.RecoveryPolicy.RecoveryLogger.AutoCreateLocation={1}",
                                           location, autoCreate);

            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            using(INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(location, logger.Location);
                Assert.AreEqual(autoCreate, logger.AutoCreateLocation);
            }
        }
Ejemplo n.º 2
0
        public void TestURI(string connectionURI)
        {
            {
                Uri uri = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(connectionURI));
                NetTxConnectionFactory factory = new NetTxConnectionFactory(uri);
                Assert.IsNotNull(factory);
                using(IConnection connection = factory.CreateConnection("", ""))
                {
                    Assert.IsNotNull(connection);
                    
                    using(ISession session = connection.CreateSession())
                    {
                        IDestination destination = session.CreateTemporaryTopic();
                        using(IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.Close();
                        }
                        
                        using(IMessageConsumer consumer = session.CreateConsumer(destination))
                        {
                            consumer.Close();
                        }
                        
                        session.Close();
                    }
                    
                    connection.Close();
                }
            }

            {
                NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
                Assert.IsNotNull(factory);
                using(IConnection connection = factory.CreateConnection("", ""))
                {
                    Assert.IsNotNull(connection);

                    using(ISession session = connection.CreateSession())
                    {
                        Assert.IsNotNull(session as INetTxSession);

                        IDestination destination = session.CreateTemporaryTopic();
                        using(IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.Close();
                        }
                        
                        using(IMessageConsumer consumer = session.CreateConsumer(destination))
                        {
                            consumer.Close();
                        }
                        
                        session.Close();
                    }
                    
                    connection.Close();
                }
            }
        }       
Ejemplo n.º 3
0
        public void TestTransactedProduceAndConsume(
            [Values("tcp://${activemqhost}:61616")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using(INetTxConnection connection = factory.CreateNetTxConnection())
            {
                connection.Start();

                using(INetTxSession session = connection.CreateNetTxSession())
                {
                    IDestination destination = session.CreateTemporaryQueue();
                    using(IMessageProducer producer = session.CreateProducer(destination))
                    {
                        using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            Assert.IsNotNull(Transaction.Current);
                            for(int i = 0; i < MSG_COUNT; ++i)
                            {
                                producer.Send(session.CreateTextMessage("Hello World"));
                            }

                            scoped.Complete();
                        }
                    }

                    using(IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Thread.Sleep(100);

                        using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            for(int i = 0; i < MSG_COUNT; ++i)
                            {
                                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
                                Assert.IsNotNull(msg, "Message was null for index: " + i);
                            }
                            scoped.Complete();
                        }
                    }

                    // No more messages should be in the Q, non rolled back or otherwise.
                    using(IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Thread.Sleep(100);
                        IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
                        Assert.IsNull(msg, "Message was not null.");
                    }

                    session.Close();
                }

                connection.Close();
            }
        }
        public void TestConfigureRecoveryPolicyLoggerType(
            [Values("tcp://${activemqhost}:61616?nms.RecoveryPolicy.RecoveryLoggerType=file")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using(INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
            }
        }
Ejemplo n.º 5
0
        private void Run()
        {
            var connectionFactory = new NetTxConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61616)?randomize=false&timeout=5000")
                {
                    AcknowledgementMode = AcknowledgementMode.Transactional,
                    PrefetchPolicy = { QueuePrefetch = 1 }
                };

            using (var connection = connectionFactory.CreateNetTxConnection())
            {
                currentconnection = connection;
                connection.Start();
                using (var session = connection.CreateNetTxSession())
                {
                    this.session = session;
                    var eventDestination = SessionUtil.GetDestination(session, "queue://Consumer.NMS.VirtualTopic.EventMessage");
                    var commandDestination = SessionUtil.GetDestination(session, "queue://subscribernms");
                    using (var eventConsumer = session.CreateConsumer(eventDestination))
                    using (var commandConsumer = session.CreateConsumer(commandDestination))
                    {
                        eventConsumer.Listener += OnEventMessage;
                        commandConsumer.Listener += this.OnCommandMessage;

                        Console.WriteLine("Consumer started. Press q to quit");
                        while (Console.ReadKey().KeyChar != 'q')
                        {
                        }
                    }
                }
                connection.Stop();
            }
        }
        public void TestConfigureRecoveryPolicyLoggerTypeWithInvalidType(
            [Values("tcp://${activemqhost}:61616?nms.RecoveryPolicy.RecoveryLoggerType=invalid")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory =
                new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using(IConnection connection = factory.CreateConnection()){}
        }
        public void TestConnectionFactorySetParams(
            [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
            string connectionURI,
            [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
            AcknowledgementMode ackMode,
            [Values(true, false)]
            bool asyncSend,
            [Values(true, false)]
            bool alwaysSyncSend,
            [Values(true, false)]
            bool asyncClose,
            [Values(true, false)]
            bool copyMessageOnSend,
            [Values(3000, 1000)]
            int requestTimeout,
            [Values(true, false)]
            bool sendAcksAsync,
            [Values(true, false)]
            bool dispatchAsync)
        {
            NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            factory.AcknowledgementMode = ackMode;
            factory.AsyncSend = asyncSend;
            factory.AlwaysSyncSend = alwaysSyncSend;
            factory.AsyncClose = asyncClose;
            factory.CopyMessageOnSend = copyMessageOnSend;
            factory.RequestTimeout = requestTimeout;
            factory.SendAcksAsync = sendAcksAsync;
            factory.DispatchAsync = dispatchAsync;

            using(Connection connection = factory.CreateConnection() as Connection)
            {
                Assert.AreEqual(ackMode, connection.AcknowledgementMode);
                Assert.AreEqual(asyncSend, connection.AsyncSend);
                Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
                Assert.AreEqual(asyncClose, connection.AsyncClose);
                Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
                Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
                Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
                Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
            }
        }
        public void TestConnectionFactoryParseParams(
            [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
            string baseConnectionURI,
            [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
            AcknowledgementMode ackMode,
            [Values(true, false)]
            bool asyncSend,
            [Values(true, false)]
            bool alwaysSyncSend,
            [Values(true, false)]
            bool asyncClose,
            [Values(true, false)]
            bool copyMessageOnSend,
            [Values(3000, 1000)]
            int requestTimeout,
            [Values(true, false)]
            bool sendAcksAsync,
            [Values(true, false)]
            bool dispatchAsync)
        {
            string connectionURI = string.Format("{0}?" +
                                   "connection.AckMode={1}&" +
                                   "connection.AsyncSend={2}&" +
                                   "connection.AlwaysSyncSend={3}&" +
                                   "connection.AsyncClose={4}&" +
                                   "connection.CopyMessageOnSend={5}&" +
                                   "connection.RequestTimeout={6}&" +
                                   "connection.SendAcksAsync={7}&" +
                                   "connection.DispatchAsync={8}",
                                   baseConnectionURI, ackMode, asyncSend, alwaysSyncSend, asyncClose, copyMessageOnSend, requestTimeout, sendAcksAsync, dispatchAsync);

            NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            using(Connection connection = factory.CreateConnection() as Connection)
            {
                Assert.AreEqual(ackMode, connection.AcknowledgementMode);
                Assert.AreEqual(asyncSend, connection.AsyncSend);
                Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
                Assert.AreEqual(asyncClose, connection.AsyncClose);
                Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
                Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
                Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
                Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
            }
        }