Ejemplo n.º 1
0
        protected void InitializeIfReq()
        {
            try
            {
                if (this.session == null || this.session.IsClosed)
                {
                    if (this.session != null)
                    {
                        this.session.Dispose();
                    }

                    if (this.messageConsumer != null)
                    {
                        this.messageConsumer.Dispose();
                    }

                    this.session         = (Session)this.sessionProvider.GetSession(transactionalMode: false);
                    this.messageConsumer = this.session.CreateConsumer(this.queue, this.Selector);
                }
            }
            catch (Apache.NMS.NMSConnectionException exc)
            {
                throw new QueueingException("Cannot receive a message due to connection problems", exc);
            }
            catch (Apache.NMS.ActiveMQ.ConnectionClosedException exc)
            {
                throw new QueueingException("Cannot receive a message because connection is closed", exc);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Subscribes to a message.  This notifies the server that we are interested in messages that contain the given argument as the first word in the message.
        /// See <see cref="SendMessage(string,string)"/>
        /// <para />
        /// For each message that is received, the MessageEvent handler will be called for all listeners.  See <see cref="OnMessage"/>
        /// <para />
        /// More than one subscription can be made.  Alternatively, an asterisk (*) may be sent as a special-case argument that indicates we're interested in *all* messages.
        /// This should be used very sparingly because it can cause quite a bit of network traffic.
        /// </summary>
        /// <param name="req">Indicates what types of messages we are interested in receiving.  This tells the server to send messages where the first word matches req</param>
        public void SubscribeMessage(string req)
        {
            // check if we've already subscribed to this message
            foreach (KeyValuePairConsumer c in m_consumers)
            {
                if (c.Key == req)
                {
                    return;
                }
            }

            // special case for asterisk.  If we pass in an asterisk, we are subscribing to all messages
            string messageSelector;

            if (req == "*")
            {
                messageSelector = "ELVISH_SCOPE = '" + m_scope + "' AND MESSAGE_PREFIX LIKE '%'";
                m_subscribedAll = true;
            }
            else
            {
                messageSelector = "ELVISH_SCOPE = '" + m_scope + "' AND MESSAGE_PREFIX = '" + req + "'";
            }


            //string messageSelector = "ELVISH_SCOPE = '" + m_scope + "' AND MESSAGE_PREFIX = '" + req + "'";
            //m_consumers.add( m_session.createDurableConsumer( m_destination, req, reqString, false ) );
            //try
            {
                //MessageConsumer c = m_session.createDurableSubscriber( (Topic)m_destination, req, messageSelector, false );
                Apache.NMS.IMessageConsumer c = m_session.CreateConsumer(m_destination, messageSelector);
                //MessageConsumer c = m_session.createConsumer( m_destination, null );
                //MessageConsumer c = m_session.createConsumer( m_destination );
                c.Listener += this.OnMessage;

                m_consumers.Add(new KeyValuePairConsumer(req, c));

                //System.out.println("subscribeMessage(): " + messageSelector);
            }

            // if we subscribed to "*", remove all the other listeners to prevent duplicate messages
            if (m_subscribedAll)
            {
                foreach (KeyValuePairConsumer c in m_consumers)
                {
                    if (c.Key.CompareTo("*") != 0)
                    {
                        c.Value.Listener -= this.OnMessage;
                        c.Value.Listener -= this.OnMessageIgnore;
                        c.Value.Listener += this.OnMessageIgnore;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Apache.NMS.IMessageConsumer CreateConsumer(Apache.NMS.IDestination destination, string selector, bool noLocal)
        {
            Apache.NMS.EMS.Destination destinationObj = (Apache.NMS.EMS.Destination)destination;

            try
            {
                Apache.NMS.IMessageConsumer consumer = EMSConvert.ToNMSMessageConsumer(this, this.tibcoSession.CreateConsumer(destinationObj.tibcoDestination, selector, noLocal));
                ConfigureConsumer(consumer);
                return(consumer);
            }
            catch (Exception ex)
            {
                ExceptionUtil.WrapAndThrowNMSException(ex);
                return(null);
            }
        }
Ejemplo n.º 4
0
        public Apache.NMS.IMessageConsumer CreateDurableConsumer(Apache.NMS.ITopic destination, string name, string selector, bool noLocal)
        {
            Apache.NMS.EMS.Topic topicObj = (Apache.NMS.EMS.Topic)destination;

            try
            {
                Apache.NMS.IMessageConsumer consumer = EMSConvert.ToNMSMessageConsumer(this, this.tibcoSession.CreateDurableSubscriber(topicObj.tibcoTopic, name, selector, noLocal));
                ConfigureConsumer(consumer);
                return(consumer);
            }
            catch (Exception ex)
            {
                ExceptionUtil.WrapAndThrowNMSException(ex);
                return(null);
            }
        }
Ejemplo n.º 5
0
        protected virtual void Dispose(bool disposing)
        {
            if (this.isDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (this.messageConsumer != null)
                {
                    this.messageConsumer.Dispose();
                }

                if (this.session != null)
                {
                    this.session.Dispose();
                }
            }

            this.messageConsumer = null;
            this.session         = null;
            this.isDisposed      = true;
        }
Ejemplo n.º 6
0
 private void ConfigureConsumer(Apache.NMS.IMessageConsumer consumer)
 {
     consumer.ConsumerTransformer = this.ConsumerTransformer;
 }