protected void DoClientAcknowledge(ActiveMQMessage message)
 {
     this.CheckClosed();
     Tracer.Debug("Sending Client Ack:");
     this.session.Acknowledge();
 }
        public void Dispatch(MessageDispatch dispatch)
        {
            MessageListener listener = this.listener;

            try
            {
                lock (this.unconsumedMessages.SyncRoot)
                {
                    if (this.clearDispatchList)
                    {
                        // we are reconnecting so lets flush the in progress messages
                        this.clearDispatchList = false;
                        this.unconsumedMessages.Clear();

                        if (this.pendingAck != null && this.pendingAck.AckType == (byte)AckType.DeliveredAck)
                        {
                            // on resumption a pending delivered ack will be out of sync with
                            // re-deliveries.
                            if (Tracer.IsDebugEnabled)
                            {
                                Tracer.Debug("removing pending delivered ack on transport interupt: " + pendingAck);
                            }
                            this.pendingAck = null;
                        }
                    }

                    if (!this.unconsumedMessages.Closed)
                    {
                        if (listener != null && this.unconsumedMessages.Running)
                        {
                            ActiveMQMessage message = CreateActiveMQMessage(dispatch);

                            this.BeforeMessageIsConsumed(dispatch);

                            try
                            {
                                bool expired = message.IsExpired();

                                if (!expired)
                                {
                                    listener(message);
                                }

                                this.AfterMessageIsConsumed(dispatch, expired);
                            }
                            catch (Exception e)
                            {
                                if (IsAutoAcknowledgeBatch || IsAutoAcknowledgeEach || this.session.IsIndividualAcknowledge)
                                {
                                    // Redeliver the message
                                }
                                else
                                {
                                    // Transacted or Client ack: Deliver the next message.
                                    this.AfterMessageIsConsumed(dispatch, false);
                                }

                                Tracer.Error(this.info.ConsumerId + " Exception while processing message: " + e);

                                // If aborted we stop the abort here and let normal processing resume.
                                // This allows the session to shutdown normally and ack all messages
                                // that have outstanding acks in this consumer.
                                if ((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) == ThreadState.AbortRequested)
                                {
                                    Thread.ResetAbort();
                                }
                            }
                        }
                        else
                        {
                            this.unconsumedMessages.Enqueue(dispatch);
                        }
                    }
                }

                if (++dispatchedCount % 1000 == 0)
                {
                    dispatchedCount = 0;
                    Thread.Sleep(1);
                }
            }
            catch (Exception e)
            {
                this.session.Connection.OnSessionException(this.session, e);
            }
        }
        public void TestMessageTransformation()
        {
            ActiveMQMessage message = new ActiveMQMessage();

            Assert.AreSame(message, transformer.TransformMessage <ActiveMQMessage>(message));
        }
 protected void DoNothingAcknowledge(ActiveMQMessage message)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Prevents message from throwing an exception if a client calls Acknoweldge on
 /// a message that is part of a transaction either being produced or consumed.  The
 /// JMS Spec indicates that users should be able to call Acknowledge with no effect
 /// if the message is in a transaction.
 /// </summary>
 /// <param name="message">
 /// A <see cref="ActiveMQMessage"/>
 /// </param>
 private static void DoNothingAcknowledge(ActiveMQMessage message)
 {
 }
Esempio n. 6
0
        public IMessage CreateMessage()
        {
            ActiveMQMessage answer = new ActiveMQMessage();

            return(ConfigureMessage(answer) as IMessage);
        }
Esempio n. 7
0
 /// <summary>
 /// Configures the message command
 /// </summary>
 protected void Configure(ActiveMQMessage message)
 {
 }
Esempio n. 8
0
        protected void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive, bool specifiedTimeToLive)
        {
            if (null == destination)
            {
                // See if this producer was created without a destination.
                if (null == info.Destination)
                {
                    throw new NotSupportedException();
                }

                // The producer was created with a destination, but an invalid destination
                // was specified.
                throw new Apache.NMS.InvalidDestinationException();
            }

            ActiveMQDestination dest = null;

            if (destination == this.info.Destination)
            {
                dest = destination as ActiveMQDestination;
            }
            else if (info.Destination == null)
            {
                dest = ActiveMQDestination.Transform(destination);
            }
            else
            {
                throw new NotSupportedException("This producer can only send messages to: " + this.info.Destination.PhysicalName);
            }

            ActiveMQMessage activeMessage = (ActiveMQMessage)message;

            activeMessage.ProducerId      = info.ProducerId;
            activeMessage.Destination     = dest;
            activeMessage.NMSDeliveryMode = deliveryMode;
            activeMessage.NMSPriority     = priority;

            // Always set the message Id regardless of the disable flag.
            MessageId id = new MessageId();

            id.ProducerId           = info.ProducerId;
            id.ProducerSequenceId   = Interlocked.Increment(ref this.producerSequenceId);
            activeMessage.MessageId = id;

            if (!disableMessageTimestamp)
            {
                activeMessage.NMSTimestamp = DateTime.UtcNow;
            }

            if (specifiedTimeToLive)
            {
                activeMessage.NMSTimeToLive = timeToLive;
            }

            // Ensure there's room left to send this message
            if (this.usage != null)
            {
                usage.WaitForSpace();
            }

            lock (closedLock)
            {
                if (closed)
                {
                    throw new ConnectionClosedException();
                }

                session.DoSend(activeMessage, this, this.usage, this.RequestTimeout);
            }
        }
Esempio n. 9
0
        public void TestReadOnlyProperties()
        {
            ActiveMQMessage msg          = new ActiveMQMessage();
            String          propertyName = "property";

            msg.ReadOnlyProperties = true;

            try
            {
                msg.Properties[propertyName] = new Object();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetString(propertyName, "test");
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetBool(propertyName, true);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetByte(propertyName, (byte)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException) {
            }

            try
            {
                msg.Properties.SetShort(propertyName, (short)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetInt(propertyName, 1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetLong(propertyName, 1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetFloat(propertyName, (float)1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }

            try
            {
                msg.Properties.SetDouble(propertyName, 1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
        }
Esempio n. 10
0
        public void TestStringPropertyConversion()
        {
            ActiveMQMessage msg          = new ActiveMQMessage();
            String          propertyName = "property";
            String          stringValue  = "True";

            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetString(propertyName), stringValue);
            Assert.AreEqual((string)msg.Properties[propertyName], stringValue);
            Assert.AreEqual(msg.Properties.GetBool(propertyName), true);

            stringValue = "1";
            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetByte(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetShort(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);

            Double doubleValue = 1.5;

            stringValue = doubleValue.ToString();
            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetFloat(propertyName), 1.5, 0);
            Assert.AreEqual(msg.Properties.GetDouble(propertyName), 1.5, 0);

            stringValue = "bad";
            msg.Properties.SetString(propertyName, stringValue);

            try
            {
                msg.Properties.GetByte(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetShort(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetInt(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetLong(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetFloat(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetDouble(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            Assert.IsFalse(msg.Properties.GetBool(propertyName));
        }
Esempio n. 11
0
        public void TestSetToForeignNMSID()
        {
            ActiveMQMessage msg = new ActiveMQMessage();

            msg.NMSMessageId = "ID:EMS-SERVER.8B443C380083:429";
        }
Esempio n. 12
0
        public void TestDoublePropertyConversion()
        {
            ActiveMQMessage msg          = new ActiveMQMessage();
            String          propertyName = "property";
            Double          doubleValue  = 1.5;

            msg.Properties.SetDouble(propertyName, doubleValue);
            Assert.AreEqual((double)msg.Properties[propertyName], doubleValue, 0);
            Assert.AreEqual(msg.Properties.GetDouble(propertyName), doubleValue, 0);
            Assert.AreEqual(msg.Properties.GetString(propertyName), doubleValue.ToString());

            try
            {
                msg.Properties.GetBool(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetByte(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetShort(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetInt(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetLong(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetFloat(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
        }
Esempio n. 13
0
        public void TestLongPropertyConversion()
        {
            ActiveMQMessage msg          = new ActiveMQMessage();
            String          propertyName = "property";

            msg.Properties.SetLong(propertyName, 1);

            Assert.AreEqual((long)msg.Properties[propertyName], 1);
            Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetString(propertyName), "1");

            try
            {
                msg.Properties.GetBool(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetByte(propertyName);
                Assert.Fail("Should have thrown exception");
            } catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetShort(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetInt(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetFloat(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetDouble(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
        }