public MessageConsumer(Session sess, AcknowledgementMode ackMode, IDestination dest, string selector)
        {
            // UNUSED_PARAM(selector);		// Selectors are not currently supported

            if (null == sess ||
                null == sess.Connection ||
                null == sess.Connection.Context)
            {
                throw new NMSConnectionException();
            }

            Destination theDest = dest as Destination;

            if (null == theDest)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }
            else if (null == theDest.Name)
            {
                throw new InvalidDestinationException("The destination object was not given a physical name.");
            }
            else if (theDest.IsTemporary)
            {
                String physicalName = theDest.Name;

                if (String.IsNullOrEmpty(physicalName))
                {
                    throw new InvalidDestinationException("Physical name of Destination should be valid: " + theDest);
                }
            }

            this.session             = sess;
            this.destination         = theDest;
            this.acknowledgementMode = ackMode;
        }
Exemple #2
0
        public void TestSyncReceiveConsumerClose(AcknowledgementMode ackMode)
        {
            // Launch a thread to perform IMessageConsumer.Receive().
            // If it doesn't fail in less than three seconds, no exception was thrown.
            Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));

            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    ITemporaryQueue queue = session.CreateTemporaryQueue();
                    using (this.timeoutConsumer = session.CreateConsumer(queue))
                    {
                        receiveThread.Start();
                        if (receiveThread.Join(3000))
                        {
                            Assert.Fail("IMessageConsumer.Receive() returned without blocking.  Test failed.");
                        }
                        else
                        {
                            // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
                            this.timeoutConsumer.Close();
                            receiveThread.Join(10000);
                            if (receiveThread.IsAlive)
                            {
                                // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
                                receiveThread.Interrupt();
                                Assert.Fail("IMessageConsumer.Receive() thread is still alive, Close should have killed it.");
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 public override void TestConsumerReceiveBeforeMessageDispatched(
     [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
             AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
     AcknowledgementMode ackMode)
 {
     base.TestConsumerReceiveBeforeMessageDispatched(ackMode);
 }
Exemple #4
0
 public override void TestSyncReceiveConsumerClose(
     [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
             AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
     AcknowledgementMode ackMode)
 {
     base.TestSyncReceiveConsumerClose(ackMode);
 }
Exemple #5
0
 public override void TestNoTimeoutConsumer(
     [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
             AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
     AcknowledgementMode ackMode)
 {
     base.TestNoTimeoutConsumer(ackMode);
 }
Exemple #6
0
        protected virtual Session CreateMQTTSession(AcknowledgementMode ackMode)
        {
            CheckConnected();
            int sessionId = Interlocked.Increment(ref sessionCounter);

            return(new Session(this, ackMode, sessionId));
        }
Exemple #7
0
 internal NmsPooledConnection CreatePooledConnection(AcknowledgementMode acknowledgementMode)
 {
     var conn = this.Credentials == null
         ? this.ConnectionFactory.CreateConnection()
         : this.ConnectionFactory.CreateConnection(this.Credentials.Username, this.Credentials.Password);
     return new NmsPooledConnection(conn, AcknowledgementMode.AutoAcknowledge);
 }
        public void TestRecvRecvCommit(AcknowledgementMode ackMode)
        {
            ISession session = connection.CreateSession(ackMode);

            IMessageProducer producer = session.CreateProducer(queue);

            producer.Send(session.CreateTextMessage("Msg1"));
            producer.Send(session.CreateTextMessage("Msg2"));
            if (session.Transacted)
            {
                session.Commit();
            }
            // now lets Receive it
            IMessageConsumer consumer = session.CreateConsumer(queue);
            ITextMessage     answer   = (ITextMessage)consumer.ReceiveNoWait();

            Assert.AreEqual(answer.Text, "Msg1", "Should have received a message!");
            answer = (ITextMessage)consumer.ReceiveNoWait();
            Assert.AreEqual(answer.Text, "Msg2", "Should have received a message!");
            if (session.Transacted)
            {
                session.Commit();
            }
            answer = (ITextMessage)consumer.ReceiveNoWait();
            Assert.IsNull(answer, "Should have not received a message!");
        }
Exemple #9
0
        protected void RunTestDurableConsumer(AcknowledgementMode ackMode)
        {
            SendDurableMessage();

            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
                {
                    ITopic topic = SessionUtil.GetTopic(session, DURABLE_TOPIC);
                    using (IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID, DURABLE_SELECTOR, false))
                    {
                        IMessage msg = consumer.Receive(receiveTimeout);
                        Assert.IsNotNull(msg, "Did not receive first durable message.");
                        msg.Acknowledge();
                        SendDurableMessage();

                        msg = consumer.Receive(receiveTimeout);
                        Assert.IsNotNull(msg, "Did not receive second durable message.");
                        msg.Acknowledge();

                        if (AcknowledgementMode.Transactional == ackMode)
                        {
                            session.Commit();
                        }
                    }
                }
            }
        }
        protected NmsMessageConsumer(NmsConsumerId consumerId, NmsSession session, IDestination destination, string name, string selector, bool noLocal)
        {
            Session             = session;
            acknowledgementMode = session.AcknowledgementMode;

            if (destination.IsTemporary)
            {
                session.Connection.CheckConsumeFromTemporaryDestination((NmsTemporaryDestination)destination);
            }

            Info = new NmsConsumerInfo(consumerId)
            {
                Destination        = destination,
                Selector           = selector,
                NoLocal            = noLocal,
                SubscriptionName   = name,
                LocalMessageExpiry = Session.Connection.ConnectionInfo.LocalMessageExpiry,
                IsDurable          = IsDurableSubscription
            };
            deliveryTask = new MessageDeliveryTask(this);

            Session.Connection.CreateResource(Info).ConfigureAwait(false).GetAwaiter().GetResult();


            Session.Add(this);

            if (Session.IsStarted)
            {
                Start();
            }
        }
        public void TestNoTimeoutConsumer(
            [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
                    AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode)
        {
            // Launch a thread to perform IMessageConsumer.Receive().
            // If it doesn't fail in less than three seconds, no exception was thrown.
            Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));

            using (IConnection connection = CreateConnection())
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    ITemporaryQueue queue = session.CreateTemporaryQueue();
                    using (this.timeoutConsumer = session.CreateConsumer(queue))
                    {
                        receiveThread.Start();
                        if (receiveThread.Join(3000))
                        {
                            Assert.Fail("IMessageConsumer.Receive() returned without blocking.  Test failed.");
                        }
                        else
                        {
                            // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
                            receiveThread.Interrupt();
                        }
                    }
                }
            }
        }
        public void TextMessageSRExample()
        {
            using (IConnection connection = Factory.CreateConnection())
            {
                AcknowledgementMode acknowledgementMode = AcknowledgementMode.AutoAcknowledge;
                ISession            session             = connection.CreateSession(acknowledgementMode);

                IDestination destination = session.GetQueue("FOO.BAR");

                // lets create a consumer and producer
                IMessageConsumer consumer = session.CreateConsumer(destination);
                consumer.Listener += new MessageListener(OnMessage);

                IMessageProducer producer = session.CreateProducer(destination);
                producer.Persistent = true;

                // lets send a message
                ITextMessage request = session.CreateTextMessage(
                    "HelloWorld!");
                request.NMSCorrelationID          = "abc";
                request.Properties["NMSXGroupID"] = "cheese";
                request.Properties["myHeader"]    = "James";

                producer.Send(request);

                WaitForMessageToArrive();
            }
        }
Exemple #13
0
        //[Test]
        public virtual void TestConsumerReceiveBeforeMessageDispatched(
            string testDestRef,
            //[Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
            //	AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode)
        {
            // Launch a thread to perform a delayed send.
            Thread sendThread = new Thread(DelayedProducerThreadProc);

            using (IConnection connection = CreateConnection())
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    IDestination destination = GetClearDestinationByNodeReference(session, testDestRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        ThreadArg arg = new ThreadArg();

                        arg.connection  = connection;
                        arg.session     = session;
                        arg.destination = destination;

                        sendThread.Start(arg);
                        IMessage message = consumer.Receive(TimeSpan.FromMinutes(1));
                        Assert.IsNotNull(message);
                    }
                }
            }
        }
Exemple #14
0
 private NmsContext(NmsConnection connection, AcknowledgementMode acknowledgementMode,
                    AtomicLong connectionRefCount)
 {
     this.connection          = connection;
     this.AcknowledgementMode = acknowledgementMode;
     this.connectionRefCount  = connectionRefCount;
 }
Exemple #15
0
        /// <summary>
        /// Creates a new session to work on this connection
        /// </summary>
        public ISession CreateSession(AcknowledgementMode sessionAcknowledgementMode)
        {
            SessionInfo info    = CreateSessionInfo(sessionAcknowledgementMode);
            Session     session = new Session(this, info, sessionAcknowledgementMode, this.dispatchAsync);

            // Set properties on session using parameters prefixed with "session."
            if (!String.IsNullOrEmpty(brokerUri.Query) && !brokerUri.OriginalString.EndsWith(")"))
            {
                // Since the Uri class will return the end of a Query string found in a Composite
                // URI we must ensure that we trim that off before we proceed.
                string           query   = brokerUri.Query.Substring(brokerUri.Query.LastIndexOf(")") + 1);
                StringDictionary options = URISupport.ParseQuery(query);
                options = URISupport.GetProperties(options, "session.");
                URISupport.SetProperties(session, options);
            }

            session.ConsumerTransformer = this.ConsumerTransformer;
            session.ProducerTransformer = this.ProducerTransformer;

            if (IsStarted)
            {
                session.Start();
            }

            sessions.Add(session);
            return(session);
        }
Exemple #16
0
 /// <summary>
 /// Creates a new ActiveMQConnection instance with the specified underlying IConnection and optionally specifying the default acknowledgement
 /// mode for new sessions.
 /// </summary>
 /// <param name="connection">The IConnection instance which this ActiveMQConnection should wrap.</param>
 /// <param name="acknowledgementMode">Optionally specify the default acknowledgement mode for new sessions.</param>
 internal NmsConnection(IConnection connection, Apache.NMS.AcknowledgementMode acknowledgementMode)
 {
     this.connection = connection;
     this.id = idCounter++;
     this.acknowledgementMode = acknowledgementMode;
     this.WireUpEvents();
 }
        public void TestDurableConsumer(
            [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
                    AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode)
        {
            string TEST_DURABLE_TOPIC = DURABLE_TOPIC + ":TestDurableConsumer";

            try
            {
                RegisterDurableConsumer(TEST_CLIENT_AND_CONSUMER_ID, TEST_DURABLE_TOPIC, TEST_CLIENT_AND_CONSUMER_ID,
                                        null, false);
                RunTestDurableConsumer(TEST_DURABLE_TOPIC, ackMode);
                if (AcknowledgementMode.Transactional == ackMode)
                {
                    RunTestDurableConsumer(TEST_DURABLE_TOPIC, ackMode);
                }
            }
            finally
            {
                // Pause to allow Stomp to unregister at the broker.
                Thread.Sleep(500);

                UnregisterDurableConsumer(TEST_CLIENT_AND_CONSUMER_ID, TEST_CLIENT_AND_CONSUMER_ID);
            }
        }
 public MessageConsumer(Session session, int consumerId, Destination dest, AcknowledgementMode acknowledgementMode)
 {
     this.session = session;
     this.id = consumerId;
     this.destination = dest;
     this.acknowledgementMode = acknowledgementMode;
 }
 public void TestSendWhileClosed(
     [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
             AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
     AcknowledgementMode ackMode)
 {
     base.TestSendWhileClosed(ackMode, DEFAULT_TEST_TOPIC);
 }
 public void TestDurableConsumerSelectorChange(
     [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
             AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
     AcknowledgementMode ackMode)
 {
     base.TestDurableConsumerSelectorChange(ackMode, DEFAULT_TEST_TOPIC);
 }
        public async Task <ISession> CreateSessionAsync(AcknowledgementMode acknowledgementMode)
        {
            CheckClosedOrFailed();
            await CreateNmsConnectionAsync().Await();

            NmsSession session = new NmsSession(this, GetNextSessionId(), acknowledgementMode);

            try
            {
                await session.Begin().Await();

                sessions.TryAdd(session.SessionInfo.Id, session);
                if (started)
                {
                    session.Start();
                }

                return(session);
            }
            catch (NMSException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ExceptionSupport.Wrap(ex, "Failed to establish amqp Session.");
            }
        }
        /// <summary>
        /// Gets the destination settings.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public AMQDestinationSettings GetDestinationSettings(string name)
        {
            var attributes = GetAttributes("destinationSettings", name);

            var destination = new AMQDestinationSettings(attributes["name"], attributes["path"])
            {
                Path         = StringHelper.FullTrim(StringHelper.IfNullOrEmptyUseDefault(attributes["path"], string.Empty)),
                Selector     = StringHelper.IfNullOrEmptyUseDefault(attributes["selector"], null),
                SubscriberId = StringHelper.IfNullOrEmptyUseDefault(attributes["subscriberId"], null),
                Durable      = StringHelper.IfNullOrEmptyUseDefault(attributes["durable"], "false") == "true",

                DeliveryMode = MsgDeliveryMode.Persistent,
                AckMode      = AcknowledgementMode.AutoAcknowledge
            };

            var             deliveryMode    = StringHelper.IfNullOrEmptyUseDefault(attributes["deliveryMode"], "persistent");
            MsgDeliveryMode msgDeliveryMode = MsgDeliveryMode.Persistent;

            Enum.TryParse(deliveryMode, true, out msgDeliveryMode);
            destination.DeliveryMode = msgDeliveryMode;

            var ackMode = StringHelper.IfNullOrEmptyUseDefault(attributes["ackMode"], "autoacknowledge");
            AcknowledgementMode msgAckMode = AcknowledgementMode.AutoAcknowledge;

            Enum.TryParse(ackMode, true, out msgAckMode);
            destination.AckMode = msgAckMode;

            return(destination);
        }
Exemple #23
0
 public NmsConnection CreateConnection(AcknowledgementMode acknowledgementMode)
 {
     var conn = this.Credentials == null
         ? this.ConnectionFactory.CreateConnection()
         : this.ConnectionFactory.CreateConnection(this.Credentials.Username, this.Credentials.Password);
     return new NmsConnection(conn);
 }
Exemple #24
0
        public void TestConsumerReceiveBeforeMessageDispatched(AcknowledgementMode ackMode)
        {
            // Launch a thread to perform a delayed send.
            Thread sendThread = new Thread(DelayedProducerThreadProc);

            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    ITemporaryQueue queue = session.CreateTemporaryQueue();
                    using (IMessageConsumer consumer = session.CreateConsumer(queue))
                    {
                        ThreadArg arg = new ThreadArg();

                        arg.connection  = connection;
                        arg.session     = session;
                        arg.destination = queue;

                        sendThread.Start(arg);
                        IMessage message = consumer.Receive(TimeSpan.FromMinutes(1));
                        Assert.IsNotNull(message);
                    }
                }
            }
        }
Exemple #25
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);
        }
Exemple #26
0
 //[Test]
 public virtual void TestSendCommitNonTransaction(
     //[Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge)]
     AcknowledgementMode ackMode,
     //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode, string testQueueRef)
 {
     using (IConnection connection = CreateConnection(GetTestClientId()))
     {
         connection.Start();
         using (ISession session = connection.CreateSession(ackMode))
         {
             IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
             using (IMessageConsumer consumer = session.CreateConsumer(destination))
                 using (IMessageProducer producer = session.CreateProducer(destination))
                 {
                     producer.DeliveryMode = deliveryMode;
                     ITextMessage firstMsgSend = session.CreateTextMessage("SendCommitNonTransaction Message");
                     producer.Send(firstMsgSend);
                     try
                     {
                         session.Commit();
                         Assert.Fail("Should have thrown an InvalidOperationException.");
                     }
                     catch (InvalidOperationException)
                     {
                     }
                 }
         }
     }
 }
        public ISession CreateSession(AcknowledgementMode acknowledgementMode)
        {
            CheckClosedOrFailed();
            CreateNmsConnection();

            NmsSession session = new NmsSession(this, SessionIdGenerator.GenerateId(), acknowledgementMode)
            {
                SessionInfo = { requestTimeout = ConnectionInfo.requestTimeout }
            };

            try
            {
                session.Begin().ConfigureAwait(false).GetAwaiter().GetResult();
                sessions.TryAdd(session.SessionInfo.Id, session);
                if (started)
                {
                    session.Start();
                }

                return(session);
            }
            catch (NMSException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ExceptionSupport.Wrap(ex, "Failed to establish amqp Session.");
            }
        }
Exemple #28
0
 public void TestSendCommitNonTransaction(AcknowledgementMode ackMode, MsgDeliveryMode deliveryMode)
 {
     using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
     {
         connection.Start();
         using (ISession session = connection.CreateSession(ackMode))
         {
             IDestination destination = session.CreateTemporaryQueue();
             using (IMessageConsumer consumer = session.CreateConsumer(destination))
                 using (IMessageProducer producer = session.CreateProducer(destination))
                 {
                     producer.DeliveryMode   = deliveryMode;
                     producer.RequestTimeout = receiveTimeout;
                     ITextMessage firstMsgSend = session.CreateTextMessage("SendCommitNonTransaction Message");
                     producer.Send(firstMsgSend);
                     try
                     {
                         session.Commit();
                         Assert.Fail("Should have thrown an InvalidOperationException.");
                     }
                     catch (InvalidOperationException)
                     {
                     }
                 }
         }
     }
 }
Exemple #29
0
        public MessageConsumer(Session session, AcknowledgementMode acknowledgementMode, IDestination destination, string selector)
        {
            if (null == Connection.Context)
            {
                throw new NMSConnectionException();
            }

            this.session             = session;
            this.acknowledgementMode = acknowledgementMode;
            this.messageSubscriber   = Connection.Context.Socket(ZSocketType.SUB);
            if (null == this.messageSubscriber)
            {
                throw new ResourceAllocationException();
            }

            string clientId = session.Connection.ClientId;

            this.contextBinding = session.Connection.BrokerUri.LocalPath;
            this.destination    = new Queue(this.contextBinding);
            if (!string.IsNullOrEmpty(clientId))
            {
                this.messageSubscriber.StringToIdentity(clientId, Encoding.Unicode);
            }

            this.messageSubscriber.Connect(contextBinding);
            this.messageSubscriber.Subscribe(selector ?? string.Empty, Encoding.ASCII);
        }
Exemple #30
0
        public NmsMessageConsumer(Id consumerId, NmsSession session, IDestination destination, string name, string selector, bool noLocal)
        {
            Session             = session;
            acknowledgementMode = session.AcknowledgementMode;

            if (destination.IsTemporary)
            {
                session.Connection.CheckConsumeFromTemporaryDestination((NmsTemporaryDestination)destination);
            }

            Info = new ConsumerInfo(consumerId, Session.SessionInfo.Id)
            {
                Destination        = destination,
                Selector           = selector,
                NoLocal            = noLocal,
                SubscriptionName   = name,
                LocalMessageExpiry = Session.Connection.ConnectionInfo.LocalMessageExpiry
            };
            deliveryTask = new MessageDeliveryTask(this);

            if (Session.IsStarted)
            {
                Start();
            }
        }
 public MessageConsumer(Session session, int consumerId, Destination dest, AcknowledgementMode acknowledgementMode)
 {
     this.session             = session;
     this.id                  = consumerId;
     this.destination         = dest;
     this.acknowledgementMode = acknowledgementMode;
 }
Exemple #32
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);
        }
 public TextMessageSource(Lazy <IConnection> lazyConnection, IEnumerable <IMessageDeserializer <TMessage> > deserializers,
                          IDestination destination, AcknowledgementMode mode = AcknowledgementMode.AutoAcknowledge, string selector = null,
                          Encoding encoding = null, Func <IDictionary, bool> propertyFilter = null)
     : base(lazyConnection, deserializers, destination, mode, selector, propertyFilter)
 {
     _encoding = encoding ?? Encoding.UTF8;
 }
        /// <summary>
        /// Creates a new session to work on this connection
        /// </summary>
        public ISession CreateSession(AcknowledgementMode sessionAcknowledgementMode)
        {
            SessionInfo info = CreateSessionInfo(sessionAcknowledgementMode);

            SyncRequest(info, this.RequestTimeout);
            Session session = new Session(this, info, sessionAcknowledgementMode, this.dispatchAsync);

            // 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(session, options);
            }

            session.ConsumerTransformer = this.ConsumerTransformer;
            session.ProducerTransformer = this.ProducerTransformer;

            if (IsStarted)
            {
                session.Start();
            }

            sessions.Add(session);
            return(session);
        }
Exemple #35
0
        protected ISession CreateSession(AcknowledgementMode acknowledgementMode = AcknowledgementMode.AutoAcknowledge)
        {
            try
            {
                if (!connection.IsStarted)
                {
                    connection.Start();
                }

                return(this.connection.CreateSession(acknowledgementMode));
            }
            catch (Apache.NMS.ActiveMQ.IOException ex)
            {
                CounterException();
                throw ex;
            }
            catch (Apache.NMS.ActiveMQ.ConnectionClosedException ex)
            {
                CounterException();
                throw ex;
            }
            catch (Exception ex)
            {
                CounterException();
                throw ex;
            }
        }
Exemple #36
0
 public NmsSessionPool(NmsConnection connection, AcknowledgementMode acknowledgementMode, NmsConnectionPoolSettings settings)
 {
     this.connection = connection;
     this.AcknowledgementMode = acknowledgementMode;
     this.idleSessions = new Queue<NmsPooledSession>();
     this.referencedSessions = new HashSet<NmsPooledSession>();
     this.settings = settings;
 }
Exemple #37
0
 public NmsConnection(IConnectionFactory connectionFactory, Apache.NMS.AcknowledgementMode acknowledgementMode, NmsCredentials credentials)
 {
     this.connection = (credentials == null)
         ? connectionFactory.CreateConnection()
         : connectionFactory.CreateConnection(credentials.Username, credentials.Password);
     this.acknowledgementMode = acknowledgementMode;
     this.id = idCounter++;
     this.WireUpEvents();
 }
Exemple #38
0
 public Session(Connection connection, AcknowledgementMode acknowledgementMode)
 {
     this.connection = connection;
     this.acknowledgementMode = acknowledgementMode;
     MessageConverter = connection.MessageConverter;
     if (this.acknowledgementMode == AcknowledgementMode.Transactional)
     {
         MessageQueueTransaction = new MessageQueueTransaction();
     }
 }
Exemple #39
0
                public Session(Connection connection, SessionInfo info, AcknowledgementMode acknowledgementMode)
                {
                        this.connection = connection;
                        this.info = info;
                        this.acknowledgementMode = acknowledgementMode;
						this.asyncSend = connection.AsyncSend;
                        transactionContext = new TransactionContext(this);
                        dispatchingThread = new DispatchingThread(new DispatchingThread.DispatchFunction(DispatchAsyncMessages));
                        dispatchingThread.ExceptionListener += new DispatchingThread.ExceptionHandler(dispatchingThread_ExceptionListener);
                }
Exemple #40
0
        private Org.Apache.Qpid.Messaging.Session qpidSession = null; // Don't create until Start()

        public Session(Connection connection, int sessionId, AcknowledgementMode acknowledgementMode)
        {
            this.connection = connection;
            this.acknowledgementMode = acknowledgementMode;
            MessageConverter = connection.MessageConverter;
            id = sessionId;
            if (this.acknowledgementMode == AcknowledgementMode.Transactional)
            {
                // TODO: transactions
                throw new NotSupportedException("Transactions are not supported by Qpid/Amqp");
            }
            if (connection.IsStarted)
            {
                this.Start();
            }
            connection.AddSession(this);
        }
        public void SetUp()
        {
            A.Fake<IConnectionFactory>();
            _connection = A.Fake<IConnection>();
            _lazyConnection = new Lazy<IConnection>(() =>
            {
                _connection.Start();
                return _connection;
            });
            _session = A.Fake<ISession>();
            _consumer = A.Fake<IMessageConsumer>();
            _deserializer = A.Fake<IMessageDeserializer<ITestMessage>>();
            _observer = A.Fake<IObserver<ITestMessage>>();
            _destination = A.Fake<IDestination>();
            _acknowledgementMode = AcknowledgementMode.AutoAcknowledge;

            A.CallTo(() => _connection.CreateSession(A<Apache.NMS.AcknowledgementMode>.Ignored)).Returns(_session);
            A.CallTo(() => _session.CreateConsumer(_destination)).Returns(_consumer);

            _source = new MessageSource<ITestMessage>(_lazyConnection, new[] {_deserializer}, _destination,
                _acknowledgementMode);
        }
 /// <summary>
 /// Creates a new session to work on this connection
 /// </summary>
 public ISession CreateSession(AcknowledgementMode acknowledgementMode)
 {
     SessionInfo info = CreateSessionInfo(acknowledgementMode);
     SyncRequest(info);
     Session session = new Session(this, info, acknowledgementMode);
     sessions.Add(session);
     return session;
 }
 protected SessionInfo CreateSessionInfo(AcknowledgementMode acknowledgementMode)
 {
     SessionInfo answer = new SessionInfo();
     SessionId sessionId = new SessionId();
     sessionId.ConnectionId = info.ConnectionId.Value;
     lock (this)
     {
         sessionId.Value = ++sessionCounter;
     }
     answer.SessionId = sessionId;
     return answer;
 }
Exemple #44
0
		protected void RunTestDurableConsumer(string topicName, AcknowledgementMode ackMode)
		{
			SendDurableMessage(topicName);
			SendDurableMessage(topicName);

			using(IConnection connection = CreateConnection(TEST_CLIENT_AND_CONSUMER_ID))
			{
				connection.Start();
				using(ISession session = connection.CreateSession(ackMode))
				{
					ITopic topic = SessionUtil.GetTopic(session, topicName);
					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, TEST_CLIENT_AND_CONSUMER_ID, null, false))
					{
						IMessage msg = consumer.Receive(receiveTimeout);
						Assert.IsNotNull(msg, "Did not receive first durable message.");
						msg.Acknowledge();

						msg = consumer.Receive(receiveTimeout);
						Assert.IsNotNull(msg, "Did not receive second durable message.");
						msg.Acknowledge();

						if(AcknowledgementMode.Transactional == ackMode)
						{
							session.Commit();
						}
					}
				}
			}
		}
 public ISession CreateSession(AcknowledgementMode acknowledgementMode)
 {
     return new StubSession(messageText);
 }
Exemple #46
0
 /// <summary>
 /// Creates a new session to work on this connection
 /// </summary>
 public ISession CreateSession(AcknowledgementMode mode)
 {
     return new Session(this, GetNextSessionId(), mode);
 }
 public ISession CreateSession(AcknowledgementMode acknowledgementMode, TimeSpan requestTimeout)
 {
     throw new NotImplementedException();
 }
Exemple #48
0
 /// <summary>
 /// Creates a new session to work on this connection
 /// </summary>
 public ISession CreateSession(AcknowledgementMode sessionAcknowledgementMode)
 {
     return CreateAtiveMQSession(sessionAcknowledgementMode);
 }
        /// <summary>
        /// Template method for obtaining a (potentially cached) Session.
        /// </summary>
        /// <param name="con">The connection to operate on.</param>
        /// <param name="mode">The session ack mode.</param>
        /// <returns>the Session to use, or <code>null</code> to indicate
	    /// creation of a raw standard Session</returns>  
        public virtual ISession GetSession(IConnection con, AcknowledgementMode mode)
        {
            return null;
        }
 protected override Session CreateAtiveMQSession(AcknowledgementMode ackMode)
 {
     CheckConnected();
     return new NetTxSession(this, NextSessionId);
 }
Exemple #51
0
 /// <summary>
 /// Fluent setter for the default acknowledgement mode for this connection.
 /// </summary>
 /// <param name="mode">The default acknowledgement mode to use for this connection.</param>
 /// <returns></returns>
 public NmsConnection AcknowledgementMode(AcknowledgementMode mode)
 {
     this.acknowledgementMode = mode;
     return this;
 }
Exemple #52
0
        public INmsSession GetSession(AcknowledgementMode acknowledgementMode)
        {
            this.AssertNotDestroyed();

            ISession newSession = this.connection.CreateSession(acknowledgementMode);
            return new NmsSession(this.connection, newSession);
        }
Exemple #53
0
 public SessionKey(AcknowledgementMode ackMode)
 {
     this.ackMode = ackMode;
 }
Exemple #54
0
 INmsSession INmsConnection.GetSession(AcknowledgementMode acknowledgementMode)
 {
     return this.GetConnection().GetSession(acknowledgementMode);
 }
        /// <summary>
        /// Obtaining a cached Session.
        /// </summary>
        /// <param name="con">The connection to operate on.</param>
        /// <param name="mode">The session ack mode.</param>
        /// <returns>The Session to use
        /// </returns>
        public override ISession GetSession(IConnection con, AcknowledgementMode mode)
        {
            LinkedList sessionList;
            lock (cachedSessions)
            {
                sessionList = (LinkedList) cachedSessions[mode];
                if (sessionList == null)
                {
                    sessionList = new LinkedList();
                    cachedSessions.Add(mode, sessionList);
                }
            }

            ISession session = null;
            lock (sessionList)
            {
                if (sessionList.Count > 0)
                {
                    session = (ISession) sessionList[0];
                    sessionList.RemoveAt(0);
                }
            }
            if (session != null)
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Found cached Session for mode " + mode + ": "
                              + (session is IDecoratorSession ? ((IDecoratorSession) session).TargetSession : session));
                }
            } else
            {
                ISession targetSession = con.CreateSession(mode);                
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Creating cached Session for mode " + mode + ": " + targetSession);
                }
                session = GetCachedSessionWrapper(targetSession, sessionList);
            }
            return session;
        }
 public ISession CreateSession(AcknowledgementMode acknowledgementMode)
 {
     ISession session = singleConnectionFactory.GetSession(target, acknowledgementMode);
     if (session != null)
     {
         return session;
     }
     return target.CreateSession(acknowledgementMode);
 }
        public MessageConsumer(Session session, AcknowledgementMode acknowledgementMode, MessageQueue messageQueue)
        {
            this.session = session;
            this.acknowledgementMode = acknowledgementMode;
			this.messageQueue = messageQueue;
        }
        public ISession CreateSession(AcknowledgementMode mode)
        {
            // Later on a cache of SessionPool's based on the Ack mode could
            // be created to allow for use of all the different Ack types.

//            PooledSession session = sessionPool.BorrowSession();
//            this.loanedSessions.Add(session);
//            return session;
            return null;
        }
Exemple #59
0
 protected virtual Session CreateAtiveMQSession(AcknowledgementMode ackMode)
 {
     CheckConnected();
     return new Session(this, NextSessionId, ackMode);
 }
 public ISession CreateSession(AcknowledgementMode acknowledgementMode)
 {
     createSessionCount++;
     return new TestSession();
 }