コード例 #1
0
        private void HandleTibcoMsg(object sender, TIBCO.EMS.EMSMessageEventArgs arg)
        {
            Apache.NMS.IMessage message = EMSConvert.ToNMSMessage(arg.Message);

            if (null != message)
            {
                if (this.ConsumerTransformer != null)
                {
                    IMessage newMessage = ConsumerTransformer(this.nmsSession, this, message);

                    if (newMessage != null)
                    {
                        message = newMessage;
                    }
                }

                if (Listener != null)
                {
                    try
                    {
                        Listener(message);
                    }
                    catch (Exception ex)
                    {
                        Apache.NMS.Tracer.Debug("Error handling message: " + ex.Message);
                    }
                }
                else
                {
                    this.dispatcher.Enqueue(message);
                }
            }
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: Ishitori/Palantir
        public static IMessage CreateFrom(Apache.NMS.IMessage queueMessage, ISession session)
        {
            if (queueMessage == null)
            {
                return(null);
            }

            Apache.NMS.ITextMessage textMessage = queueMessage as Apache.NMS.ITextMessage;

            if (textMessage == null)
            {
                throw new ArgumentException(string.Format("Unsupported message type provided: \"{0}\"", queueMessage.GetType().FullName));
            }

            Message message = new Message();

            message.queueMessage    = queueMessage;
            message.Text            = textMessage.Text;
            message.Id              = textMessage.GetId();
            message.Type            = textMessage.GetMessageType();
            message.SentDate        = textMessage.GetSentDate();
            message.TryIndex        = textMessage.GetTryIndex();
            message.DeliveryTimeout = textMessage.GetDeliveryDelay();
            message.session         = session;

            return(message);
        }
コード例 #3
0
 /// <summary>
 /// Redeliver the given message, putting it at the head of the queue
 /// </summary>
 public void Redeliver(Apache.NMS.IMessage message)
 {
     lock (semaphore)
     {
         messagesToRedeliver.Add(message);
     }
 }
コード例 #4
0
        /// <summary>
        /// Sends the message to the given destination
        /// </summary>
        public void Send(Apache.NMS.IDestination destination, Apache.NMS.IMessage message)
        {
            Apache.NMS.EMS.Destination dest = (Apache.NMS.EMS.Destination)destination;
            Apache.NMS.EMS.Message     msg  = GetEMSMessage(message);
            long timeToLive = (long)message.NMSTimeToLive.TotalMilliseconds;

            if (0 == timeToLive)
            {
                timeToLive = this.tibcoMessageProducer.TimeToLive;
            }

            try
            {
                this.tibcoMessageProducer.Send(
                    dest.tibcoDestination,
                    msg.tibcoMessage,
                    this.tibcoMessageProducer.MsgDeliveryMode,
                    this.tibcoMessageProducer.Priority,
                    timeToLive);
            }
            catch (Exception ex)
            {
                ExceptionUtil.WrapAndThrowNMSException(ex);
            }
        }
コード例 #5
0
 /// <summary>
 /// Method Enqueue
 /// </summary>
 public void Enqueue(Apache.NMS.IMessage message)
 {
     lock (semaphore)
     {
         queue.Enqueue(message);
         messageReceivedEventHandle.Set();
     }
 }
コード例 #6
0
        public IDictionary <string, object> ToHeaders(IMessage nmsMessage)
        {
            IDictionary <string, object> headerMap = new Dictionary <string, object>();

            headerMap.Add("testProperty", "foo");
            headerMap.Add("testAttribute", 123);
            return(headerMap);
        }
コード例 #7
0
        protected void LogMessageReceived(Apache.NMS.IMessage message)
        {
            Apache.NMS.ITextMessage textMessage = message as Apache.NMS.ITextMessage;

            if (textMessage != null)
            {
                this.logger.LogMessageWasReceived(textMessage.GetId(), textMessage.GetMessageType(), textMessage.GetTryIndex(), textMessage.GetSentDate(), textMessage.GetDeliveryDelay(), textMessage.Text);
            }
        }
コード例 #8
0
        public static string GetMessageType(this Apache.NMS.IMessage message)
        {
            if (message.Properties.Contains(CONST_MessageTypeKey))
            {
                object messageType = message.Properties[CONST_MessageTypeKey];
                return(messageType != null?messageType.ToString() : string.Empty);
            }

            return(string.Empty);
        }
コード例 #9
0
        /// <summary>
        /// Sends the message to the default destination with the explicit QoS configuration
        /// </summary>
        public void Send(Apache.NMS.IMessage message, bool persistent, byte priority, TimeSpan timeToLive)
        {
            Apache.NMS.EMS.Message msg = (Apache.NMS.EMS.Message)message;

            this.tibcoMessageProducer.Send(
                msg.tibcoMessage,
                EMSConvert.ToMessageDeliveryMode(persistent),
                priority,
                (long)timeToLive.TotalMilliseconds);
        }
コード例 #10
0
        /// <summary>
        /// Sends the message to the default destination with the explicit QoS configuration
        /// </summary>
        public void Send(Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            Apache.NMS.EMS.Message msg = (Apache.NMS.EMS.Message)message;

            this.tibcoMessageProducer.Send(
                msg.tibcoMessage,
                EMSConvert.ToMessageDeliveryMode(deliveryMode),
                (int)priority,
                (long)timeToLive.TotalMilliseconds);
        }
コード例 #11
0
        public static string GetId(this Apache.NMS.IMessage message)
        {
            var activeMQMessage = message as Apache.NMS.ActiveMQ.Commands.ActiveMQMessage;

            if (activeMQMessage == null)
            {
                return(string.Empty);
            }

            return(activeMQMessage.NMSMessageId);
        }
コード例 #12
0
 /// <summary>
 /// Method DequeueNoWait
 /// </summary>
 public Apache.NMS.IMessage DequeueNoWait()
 {
     Apache.NMS.IMessage rc = null;
     lock (semaphore)
     {
         if (!m_bClosed && queue.Count > 0)
         {
             rc = (Apache.NMS.IMessage)queue.Dequeue();
         }
     }
     return(rc);
 }
コード例 #13
0
        public static DateTime GetSentDate(this Apache.NMS.IMessage message)
        {
            if (message.Properties.Contains(CONST_SentDateKey))
            {
                DateTime sentDate;
                object   sentDateObject = message.Properties[CONST_SentDateKey];

                if (sentDateObject != null && DateTime.TryParse(sentDateObject.ToString(), out sentDate))
                {
                    return(sentDate);
                }
            }

            return(DateTime.MinValue);
        }
コード例 #14
0
        public IMessage ReceiveMessage(int timeoutInMs = 1000)
        {
            this.InitializeIfReq();

            try
            {
                Apache.NMS.IMessage queueMessage = this.messageConsumer.Receive(TimeSpan.FromMilliseconds(timeoutInMs));
                this.LogMessageReceived(queueMessage);
                return(Message.CreateFrom(queueMessage, this.session));
            }
            catch (Apache.NMS.NMSException exc)
            {
                throw new QueueingException("Cannot receive a message", exc);
            }
        }
コード例 #15
0
        public static int GetTryIndex(this Apache.NMS.IMessage message)
        {
            var activeMQMessage = message as Apache.NMS.ActiveMQ.Commands.ActiveMQMessage;

            if (activeMQMessage == null)
            {
                return(-1);
            }

            int redeliveryCounter = activeMQMessage.Properties.Contains(CONST_RedeliveryIndexKey)
                ? Convert.ToInt32(activeMQMessage.Properties[CONST_RedeliveryIndexKey])
                : activeMQMessage.RedeliveryCounter;

            return(redeliveryCounter + 1);
        }
コード例 #16
0
        private Apache.NMS.EMS.Message GetEMSMessage(Apache.NMS.IMessage message)
        {
            Apache.NMS.EMS.Message msg = (Apache.NMS.EMS.Message)message;

            if (this.ProducerTransformer != null)
            {
                IMessage transformed = this.ProducerTransformer(this.nmsSession, this, message);
                if (transformed != null)
                {
                    msg = (Apache.NMS.EMS.Message)transformed;
                }
            }

            return(msg);
        }
コード例 #17
0
        public static void SetTryIndex(this Apache.NMS.IMessage message, int tryIndex)
        {
            var activeMQMessage = message as Apache.NMS.ActiveMQ.Commands.ActiveMQMessage;

            if (activeMQMessage == null)
            {
                return;
            }

            if (tryIndex <= 0)
            {
                return;
            }

            activeMQMessage.Properties[CONST_RedeliveryIndexKey] = tryIndex - 1;
        }
コード例 #18
0
        public static void SetDeliveryDelay(this Apache.NMS.IMessage message, int delayInMs)
        {
            var activeMQMessage = message as Apache.NMS.ActiveMQ.Commands.ActiveMQMessage;

            if (activeMQMessage == null)
            {
                return;
            }

            if (delayInMs <= 0)
            {
                return;
            }

            message.Properties[CONST_DeliveryDelayKey] = delayInMs;
        }
コード例 #19
0
        /// <summary>
        /// Sends the message to the default destination for this producer
        /// </summary>
        public void Send(Apache.NMS.IMessage message)
        {
            Apache.NMS.EMS.Message msg = (Apache.NMS.EMS.Message)message;
            long timeToLive            = (long)message.NMSTimeToLive.TotalMilliseconds;

            if (0 == timeToLive)
            {
                timeToLive = this.tibcoMessageProducer.TimeToLive;
            }

            this.tibcoMessageProducer.Send(
                msg.tibcoMessage,
                this.tibcoMessageProducer.MsgDeliveryMode,
                this.tibcoMessageProducer.Priority,
                timeToLive);
        }
コード例 #20
0
        /// <summary>
        /// Sends the message to the default destination with the explicit QoS configuration
        /// </summary>
        public void Send(Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            Apache.NMS.EMS.Message msg = GetEMSMessage(message);

            try
            {
                this.tibcoMessageProducer.Send(
                    msg.tibcoMessage,
                    EMSConvert.ToMessageDeliveryMode(deliveryMode),
                    (int)priority,
                    (long)timeToLive.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                ExceptionUtil.WrapAndThrowNMSException(ex);
            }
        }
コード例 #21
0
        public static int GetDeliveryDelay(this Apache.NMS.IMessage message)
        {
            var activeMQMessage = message as Apache.NMS.ActiveMQ.Commands.ActiveMQMessage;

            if (activeMQMessage == null)
            {
                return(0);
            }

            object deliveryTimeout = message.Properties[CONST_DeliveryDelayKey];

            if (deliveryTimeout == null)
            {
                return(0);
            }

            return(Convert.ToInt32(deliveryTimeout));
        }
コード例 #22
0
        /// <summary>
        /// Whem we start a transaction we must redeliver any rolled back messages
        /// </summary>
        public void RedeliverRolledBackMessages()
        {
            lock (semaphore)
            {
                System.Collections.Queue replacement = new System.Collections.Queue(queue.Count + messagesToRedeliver.Count);
                foreach (Apache.NMS.IMessage element in messagesToRedeliver)
                {
                    replacement.Enqueue(element);
                }
                messagesToRedeliver.Clear();

                while (queue.Count > 0)
                {
                    Apache.NMS.IMessage element = (Apache.NMS.IMessage)queue.Dequeue();
                    replacement.Enqueue(element);
                }

                queue = replacement;
                if (queue.Count > 0)
                {
                    messageReceivedEventHandle.Set();
                }
            }
        }
コード例 #23
0
 public static void SetSentDate(this Apache.NMS.IMessage message, DateTime sendDate)
 {
     message.Properties[CONST_SentDateKey] = sendDate.ToString();
 }
コード例 #24
0
ファイル: vhmsg.cs プロジェクト: USC-ICT/elsender
        /// <summary>
        /// This function is a callback function received whenever an ActiveMQ message is received from the server.  It processes the message and passes it on to the client via
        /// the MessageEvent handler.
        /// </summary>
        /// <param name="msg">ActiveMQ message received from the server</param>
        protected void OnMessage(Apache.NMS.IMessage msg)
        {
            string message = "";
            //string elements  = null ;
            string temp = null;
            //string holder = null ;
            //StringTokenizer st = null;
            //int index = 0 ;

            //System.out.println("onMessage(): " + ((TextMessage)msg).getText() );

            //if ( msg instanceof TextMessage )
            {
                Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage txtMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)msg;
                temp = txtMsg.Text;

                temp = HttpUtility.UrlDecode(temp);

                temp = temp.Trim();

                /*
                 * // Strip off first char of args if it is a "
                 * if( temp.substring(0,1).compareToIgnoreCase("\"") == 0 )
                 * {
                 * temp = (temp.substring( 1, temp.length())).trim() ;
                 * if( temp.substring(0,1).compareToIgnoreCase("\"") == 0 )
                 * {
                 *    // if 2 double quotes at end, take one double quote off
                 *    message += temp.substring( 0, temp.length()-1 );
                 * }
                 * else
                 * {
                 *    message += "\"" + temp ;
                 * }
                 * }
                 * else
                 * {
                 * message += temp ;
                 * }
                 */
                message = temp;

                Dictionary <string, string> properties = new Dictionary <string, string>();
                foreach (string key in txtMsg.Properties.Keys)
                {
                    object data  = txtMsg.Properties[key];
                    string sData = data as string;
                    if (sData != null)
                    {
                        properties[key] = HttpUtility.UrlDecode(sData).Trim();
                    }
                }

                Message args = new Message(message, properties);

                if (m_immediateMethod)
                {
                    MessageEvent(this, args);
                }
                else
                {
                    lock (m_messageLock)
                    {
                        m_messages.Add(args);
                    }

                    // signal the other thread that we've received a message (only used in WaitAndPoll() )
                    lock (m_waitLock)
                    {
                        m_waitCondition.Set();
                    }
                }
            }
        }
コード例 #25
0
 public void FromHeaders(MessageHeaders headers, IMessage nmsMessage)
 {
 }
コード例 #26
0
ファイル: vhmsg.cs プロジェクト: USC-ICT/elsender
 /// <summary>
 /// This function is a callback function received whenever an ActiveMQ message is received from the server.  It ignores the message and returns immediately.
 /// </summary>
 /// <param name="msg">ActiveMQ message received from the server</param>
 protected void OnMessageIgnore(Apache.NMS.IMessage msg)
 {
     return;
 }
コード例 #27
0
 public static void SetMessageType(this Apache.NMS.IMessage message, string type)
 {
     message.Properties[CONST_MessageTypeKey] = type;
 }