コード例 #1
0
        public IQueueBrowser CreateBrowser(IQueue queue, string selector)
        {
            if (queue == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest    = ActiveMQDestination.Transform(queue);
            QueueBrowser        browser = null;

            try
            {
                browser = new QueueBrowser(this, GetNextConsumerId(), dest, selector, this.DispatchAsync);
            }
            catch (Exception)
            {
                if (browser != null)
                {
                    browser.Close();
                }

                throw;
            }

            return(browser);
        }
コード例 #2
0
        public IMessageProducer CreateProducer(IDestination destination)
        {
            MessageProducer producer = null;

            try
            {
                ActiveMQDestination dest = null;
                if (destination != null)
                {
                    dest = ActiveMQDestination.Transform(destination);
                }

                producer = DoCreateMessageProducer(GetNextProducerId(), dest);

                producer.ProducerTransformer = this.ProducerTransformer;

                this.AddProducer(producer);
                this.Connection.Oneway(producer.ProducerInfo);
            }
            catch (Exception)
            {
                if (producer != null)
                {
                    this.RemoveProducer(producer.ProducerId);
                    producer.Close();
                }

                throw;
            }

            return(producer);
        }
コード例 #3
0
        public async Task <IMessageProducer> CreateProducerAsync(IDestination destination)
        {
            MessageProducer producer = null;

            try
            {
                ActiveMQDestination dest = null;
                if (destination != null)
                {
                    dest = ActiveMQDestination.Transform(destination);
                }

                producer = DoCreateMessageProducer(GetNextProducerId(), dest);

                producer.ProducerTransformer = this.ProducerTransformer;

                this.AddProducer(producer);
                await this.Connection.SyncRequestAsync(producer.ProducerInfo).Await();
            }
            catch (Exception)
            {
                if (producer != null)
                {
                    this.RemoveProducer(producer.ProducerId);
                }

                throw;
            }

            return(producer);
        }
コード例 #4
0
ファイル: Session.cs プロジェクト: samiudheen/mono-soc-2007
        protected virtual ProducerInfo CreateProducerInfo(IDestination destination)
        {
            ProducerInfo answer = new ProducerInfo();
            ProducerId   id     = new ProducerId();

            id.ConnectionId = info.SessionId.ConnectionId;
            id.SessionId    = info.SessionId.Value;
            lock (this)
            {
                id.Value = ++producerCounter;
            }
            answer.ProducerId  = id;
            answer.Destination = ActiveMQDestination.Transform(destination);

            answer.Destination = ActiveMQDestination.Transform(destination);

            // If the destination contained a URI query, then use it to set public
            // properties on the ProducerInfo
            ActiveMQDestination amqDestination = destination as ActiveMQDestination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                Util.URISupport.SetProperties(answer, amqDestination.Options, "producer.");
            }

            return(answer);
        }
コード例 #5
0
ファイル: Session.cs プロジェクト: samiudheen/mono-soc-2007
        protected virtual ConsumerInfo CreateConsumerInfo(IDestination destination, string selector)
        {
            ConsumerInfo answer = new ConsumerInfo();
            ConsumerId   id     = new ConsumerId();

            id.ConnectionId = info.SessionId.ConnectionId;
            id.SessionId    = info.SessionId.Value;
            lock (this)
            {
                id.Value = ++consumerCounter;
            }
            answer.ConsumerId    = id;
            answer.Destination   = ActiveMQDestination.Transform(destination);
            answer.Selector      = selector;
            answer.PrefetchSize  = prefetchSize;
            answer.Priority      = priority;
            answer.Exclusive     = exclusive;
            answer.DispatchAsync = dispatchAsync;
            answer.Retroactive   = retroactive;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            ActiveMQDestination amqDestination = destination as ActiveMQDestination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                Util.URISupport.SetProperties(answer, amqDestination.Options, "consumer.");
            }

            return(answer);
        }
コード例 #6
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest = ActiveMQDestination.Transform(destination);
            int prefetchSize         = this.Connection.PrefetchPolicy.DurableTopicPrefetch;

            if (dest.IsTopic)
            {
                prefetchSize = this.connection.PrefetchPolicy.TopicPrefetch;
            }
            else if (dest.IsQueue)
            {
                prefetchSize = this.connection.PrefetchPolicy.QueuePrefetch;
            }

            MessageConsumer consumer = null;

            try
            {
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), dest, null, selector, prefetchSize,
                                                   this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                                   noLocal);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
コード例 #7
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            if (IsIndividualAcknowledge)
            {
                throw new NMSException("Cannot create a durable consumer for a session that is using " +
                                       "Individual Acknowledgement mode.");
            }

            ActiveMQDestination dest     = ActiveMQDestination.Transform(destination);
            MessageConsumer     consumer = null;

            try
            {
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), dest, name, selector,
                                                   this.connection.PrefetchPolicy.DurableTopicPrefetch,
                                                   this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                                   noLocal);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
コード例 #8
0
        public void Send(IDestination destination, IMessage message, bool persistent, byte priority, TimeSpan timeToLive, bool specifiedTimeToLive)
        {
            ActiveMQMessage activeMessage = (ActiveMQMessage)message;

            if (!disableMessageID)
            {
                MessageId id = new MessageId();
                id.ProducerId = info.ProducerId;
                lock (this)
                {
                    id.ProducerSequenceId = ++messageCounter;
                }
                activeMessage.MessageId = id;
            }

            if (!disableMessageTimestamp && specifiedTimeToLive)
            {
                Console.WriteLine(">>> sending message with Timestamp: " + activeMessage.Timestamp + " and timeToLive:  " + timeToLive);
                activeMessage.Timestamp = ActiveMQ.Util.DateUtils.ToJavaTime(DateTime.UtcNow);
            }

            if (specifiedTimeToLive)
            {
                activeMessage.Expiration = ActiveMQ.Util.DateUtils.ToJavaTime(timeToLive);
            }

            activeMessage.ProducerId  = info.ProducerId;
            activeMessage.Destination = ActiveMQDestination.Transform(destination);

            if (session.Transacted)
            {
                session.DoStartTransaction();
                activeMessage.TransactionId = session.TransactionContext.TransactionId;
            }

            activeMessage.Persistent  = persistent;
            activeMessage.Priority    = priority;
            activeMessage.Destination = ActiveMQDestination.Transform(destination);

            session.DoSend(activeMessage);
        }
コード例 #9
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest     = ActiveMQDestination.Transform(destination);
            MessageConsumer     consumer = null;

            try
            {
                consumer = new MessageConsumer(this, GetNextConsumerId(), dest, name, selector,
                                               this.connection.PrefetchPolicy.DurableTopicPrefetch,
                                               this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                               noLocal, false, this.connection.DispatchAsync);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer.ConsumerId);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
コード例 #10
0
        protected virtual ConsumerInfo CreateConsumerInfo(IDestination destination, string selector)
        {
            ConsumerInfo answer = new ConsumerInfo();
            ConsumerId   id     = new ConsumerId();

            id.ConnectionId      = info.SessionId.ConnectionId;
            id.SessionId         = info.SessionId.Value;
            id.Value             = Interlocked.Increment(ref consumerCounter);
            answer.ConsumerId    = id;
            answer.Destination   = ActiveMQDestination.Transform(destination);
            answer.Selector      = selector;
            answer.Priority      = this.Priority;
            answer.Exclusive     = this.Exclusive;
            answer.DispatchAsync = this.DispatchAsync;
            answer.Retroactive   = this.Retroactive;
            answer.MaximumPendingMessageLimit = this.connection.PrefetchPolicy.MaximumPendingMessageLimit;

            if (destination is ITopic || destination is ITemporaryTopic)
            {
                answer.PrefetchSize = this.connection.PrefetchPolicy.TopicPrefetch;
            }
            else if (destination is IQueue || destination is ITemporaryQueue)
            {
                answer.PrefetchSize = this.connection.PrefetchPolicy.QueuePrefetch;
            }

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            ActiveMQDestination amqDestination = destination as ActiveMQDestination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                URISupport.SetProperties(answer, amqDestination.Options, "consumer.");
            }

            return(answer);
        }
コード例 #11
0
 public static bool IsMessageDiscardedAdvisoryTopic(IDestination destination)
 {
     return(IsMessageDiscardedAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #12
0
 public static ActiveMQTopic GetMessageConsumedAdvisoryTopic(IDestination destination)
 {
     return(GetMessageConsumedAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #13
0
 public static ActiveMQTopic GetNoQueueConsumersAdvisoryTopic(IDestination destination)
 {
     return(GetNoQueueConsumersAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #14
0
 public static ActiveMQTopic GetExpiredQueueMessageAdvisoryTopic(IDestination destination)
 {
     return(GetExpiredQueueMessageAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #15
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);
            }

            if (this.ProducerTransformer != null)
            {
                IMessage transformed = this.ProducerTransformer(this.session, this, message);
                if (transformed != null)
                {
                    message = transformed;
                }
            }

            ActiveMQMessage activeMessage = this.messageTransformation.TransformMessage <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;

            // Ensure that the source message contains the NMSMessageId of the transformed
            // message for correlation purposes.
            if (!ReferenceEquals(message, activeMessage))
            {
                message.NMSMessageId = activeMessage.NMSMessageId;
            }

            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(dest, activeMessage, this, this.usage, this.RequestTimeout);
            }
        }
コード例 #16
0
 public static bool IsFullAdvisoryTopic(IDestination destination)
 {
     return(IsFullAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #17
0
 public static ActiveMQTopic GetProducerAdvisoryTopic(IDestination destination)
 {
     return(GetProducerAdvisoryTopic(ActiveMQDestination.Transform(destination)));
 }
コード例 #18
0
 protected override IDestination DoTransformDestination(IDestination destination)
 {
     return(ActiveMQDestination.Transform(destination));
 }