Represents a connection with a message broker
Inheritance: IConnection
        private void init(string host, int port)
        {
            ReceivedNumber = 0;
              isFinished = false;
              ReceivedMessages = new List<string>();
              ListionTopics = new List<string>();

              Uri uriSample = new Uri("activemq:tcp://" + host + ":" + port);
              ConnectionFactory confSample = new ConnectionFactory(uriSample);
              connection = (Connection)confSample.CreateConnection();
              connection.Start();
              session = (Session)connection.CreateSession();
        }
Ejemplo n.º 2
0
        public Session(Connection connection, SessionId sessionId, AcknowledgementMode acknowledgementMode)
        {
            this.info = new SessionInfo();
            this.info.SessionId = sessionId;
            this.connection = connection;
            this.connection.Oneway(this.info);

            this.acknowledgementMode = acknowledgementMode;
            this.requestTimeout = connection.RequestTimeout;
            this.dispatchAsync = connection.DispatchAsync;
            this.transactionContext = new TransactionContext(this);

            Uri brokerUri = connection.BrokerUri;

            // Set propertieDs on session using parameters prefixed with "session."
            if(!String.IsNullOrEmpty(brokerUri.Query) && !brokerUri.OriginalString.EndsWith(")"))
            {
                string query = brokerUri.Query.Substring(brokerUri.Query.LastIndexOf(")") + 1);
                StringDictionary options = URISupport.ParseQuery(query);
                options = URISupport.GetProperties(options, "session.");
                URISupport.SetProperties(this, options);
            }

            this.ConsumerTransformer = connection.ConsumerTransformer;
            this.ProducerTransformer = connection.ProducerTransformer;

            this.executor = new SessionExecutor(this, this.consumers);

            if(connection.IsStarted)
            {
                this.Start();
            }

            connection.AddSession(this);
        }
Ejemplo n.º 3
0
        internal AdvisoryConsumer(Connection connection, ConsumerId consumerId) : base()
        {
            this.connection = connection;
            this.info = new ConsumerInfo();
            this.info.ConsumerId = consumerId;
            this.info.Destination = AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC;
            this.info.PrefetchSize = 1000;
            this.info.NoLocal = true;

            this.connection.addDispatcher(consumerId, this);
            this.connection.SyncRequest(this.info);
        }
Ejemplo n.º 4
0
 public NetTxSession(Connection connection, SessionId id)
     : base(connection, id, AcknowledgementMode.AutoAcknowledge)
 {
     TransactionContext.InitializeDtcTxContext();
 }
Ejemplo n.º 5
0
		public void init()
		{
			sent = new List<Command>();
			received = new List<Command>();
			exceptions = new List<Exception>();
			sessionIdx = 1;
			consumerIdx = 1;
			producerIdx = 1;
            this.connection = null;
            this.msgCount = MESSAGE_COUNT;
            this.interrupted = false;
            this.resumed = false;
		}
Ejemplo n.º 6
0
        public void FailoverTransportFailOnProcessingReceivedMessageTest()
        {
            string uri = "failover:(tcp://${activemqhost}:61616)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));
            using(connection = factory.CreateConnection() as Connection )
            {
                connection.ConnectionInterruptedListener +=
                    new ConnectionInterruptedListener(TransportInterrupted);
                connection.ConnectionResumedListener +=
                    new ConnectionResumedListener(TransportResumed);

                connection.Start();
                using(ISession session = connection.CreateSession())
                {
                    IDestination destination = session.GetQueue("Test?consumer.prefetchSize=1");
                    PurgeQueue(connection, destination);
                    PutMsgIntoQueue(session, destination);

                    using(IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        consumer.Listener += OnMessage;
                        BreakConnection();
                        WaitForMessagesToArrive();
                    }
                }
            }

            Assert.IsTrue(this.interrupted);
            Assert.IsTrue(this.resumed);
        }
Ejemplo n.º 7
0
        public TransactionContext(Session session)
		{
            this.session = session;
            this.connection = session.Connection;
        }
Ejemplo n.º 8
0
		protected virtual void ConfigureConnection(Connection connection)
		{
			connection.AsyncClose = this.AsyncClose;
			connection.AsyncSend = this.AsyncSend;
			connection.CopyMessageOnSend = this.CopyMessageOnSend;
			connection.AlwaysSyncSend = this.AlwaysSyncSend;
			connection.DispatchAsync = this.DispatchAsync;
			connection.SendAcksAsync = this.SendAcksAsync;
			connection.AcknowledgementMode = this.acknowledgementMode;
			connection.UseCompression = this.useCompression;
			connection.RequestTimeout = this.requestTimeout;
			connection.ProducerWindowSize = this.producerWindowSize;
			connection.MessagePrioritySupported = this.messagePrioritySupported;
			connection.RedeliveryPolicy = this.redeliveryPolicy.Clone() as IRedeliveryPolicy;
			connection.PrefetchPolicy = this.prefetchPolicy.Clone() as PrefetchPolicy;
			connection.CompressionPolicy = this.compressionPolicy.Clone() as ICompressionPolicy;
			connection.ConsumerTransformer = this.consumerTransformer;
			connection.ProducerTransformer = this.producerTransformer;
            connection.WatchTopicAdvisories = this.watchTopicAdvisories;
		}
Ejemplo n.º 9
0
        internal void Shutdown()
        {
            Tracer.InfoFormat("Executing Shutdown on Session with Id {0}", this.info.SessionId);

            if (this.closed)
            {
                return;
            }

            lock (myLock)
            {
                if (this.closed || this.closing)
                {
                    return;
                }

                try
                {
                    this.closing = true;

                    // Stop all message deliveries from this Session
                    this.executor.Stop(this.closeStopTimeout);

                    lock (consumers.SyncRoot)
                    {
                        foreach (MessageConsumer consumer in consumers.Values)
                        {
                            consumer.FailureError = this.connection.FirstFailureError;
                            consumer.Shutdown();
                            this.lastDeliveredSequenceId =
                                Math.Max(this.lastDeliveredSequenceId, consumer.LastDeliveredSequenceId);
                        }
                    }
                    consumers.Clear();

                    lock (producers.SyncRoot)
                    {
                        foreach (MessageProducer producer in producers.Values)
                        {
                            producer.Shutdown();
                        }
                    }
                    producers.Clear();

                    // If in a local transaction we just roll back at this point.
                    if (this.IsTransacted && this.transactionContext.InLocalTransaction)
                    {
                        try
                        {
                            this.transactionContext.Rollback();
                        }
                        catch
                        {
                        }
                    }

                    Connection.RemoveSession(this);
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Error during session close: {0}", ex);
                }
                finally
                {
                    this.closed  = true;
                    this.closing = false;
                }
            }
        }