Example #1
0
 public void CloseSession(AmqChannel channel)
 {
     // FIXME: Don't we need FailoverSupport here (as we have SyncWrite).
     _protocolSession.CloseSession(channel);
     
     AMQFrame frame = ChannelCloseBody.CreateAMQFrame(
         channel.ChannelId, 200, "JMS client closing channel", 0, 0);
     
     _log.Debug("Blocking for channel close frame for channel " + channel.ChannelId);
     _protocolWriter.SyncWrite(frame, typeof(ChannelCloseOkBody));
     _log.Debug("Received channel close frame");
     // When control resumes at this point, a reply will have been received that
     // indicates the broker has closed the channel successfully
 }
Example #2
0
 internal void RegisterSession(int channelId, AmqChannel channel)
 {
     _sessions[channelId] = channel;
 }
Example #3
0
 private AmqChannel()
 {
     _messageFactoryRegistry = MessageFactoryRegistry.NewDefaultRegistry();
     DefaultInstance = this;
 }
Example #4
0
            protected override object operation()
            {
                ushort channelId = _connection.NextChannelId();

                if (_log.IsDebugEnabled)
                {
                    _log.Debug("Write channel open frame for channel id " + channelId);
                }

                // We must create the channel and register it before actually sending the frame to the server to
                // open it, so that there is no window where we could receive data on the channel and not be set
                // up to handle it appropriately.
                AmqChannel channel = new AmqChannel(_connection, 
                        channelId, _transacted, _acknowledgeMode, _prefetchHigh, _prefetchLow);
                _connection.ProtocolSession.AddSessionByChannel(channelId, channel);
                _connection.RegisterSession(channelId, channel);

                bool success = false;
                try
                {
                    _connection.CreateChannelOverWire(channelId, _prefetchHigh, _prefetchLow, _transacted);
                    success = true;
                }
                catch (AMQException e)
                {
                    throw new QpidException("Error creating channel: " + e, e);
                }
                finally
                {
                    if (!success) {
                        _connection.ProtocolSession.RemoveSessionByChannel(channelId);
                        _connection.DeregisterSession(channelId);
                    }
                }

                if (_connection._started)
                {
                    channel.Start();
                }
                return channel;
            }
Example #5
0
 /// <summary> Creates a dispatcher on the specified channel. </summary>
 ///
 /// <param name="containingChannel"> The channel on which this is a dispatcher. </param>
 public Dispatcher(AmqChannel containingChannel)
 {
     _containingChannel = containingChannel;
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AmqChannel"/> class.
        /// </summary>
        /// <param name="con">The connection.</param>
        /// <param name="channelId">The channel id.</param>
        /// <param name="transacted">if set to <c>true</c> [transacted].</param>
        /// <param name="acknowledgeMode">The acknowledge mode.</param>
        /// <param name="defaultPrefetchHigh">Default prefetch high value</param>
        /// <param name="defaultPrefetchLow">Default prefetch low value</param>
        internal AmqChannel(AMQConnection con, ushort channelId, bool transacted, AcknowledgeMode acknowledgeMode, 
                            int defaultPrefetchHigh, int defaultPrefetchLow)
            : this()
        {
            _sessionNumber = Interlocked.Increment(ref _nextSessionNumber);
            _connection = con;
            _transacted = transacted;
            
            if ( transacted )
            {
                _acknowledgeMode = AcknowledgeMode.SessionTransacted;
            } 
            else
            {
                _acknowledgeMode = acknowledgeMode;
            }

            _channelId = channelId;
            _defaultPrefetchHighMark = defaultPrefetchHigh;
            _defaultPrefetchLowMark = defaultPrefetchLow;

            if ( _acknowledgeMode == AcknowledgeMode.NoAcknowledge )
            {
                _queue = new FlowControlQueue(_defaultPrefetchLowMark, _defaultPrefetchHighMark,
                                              new ThresholdMethod(OnPrefetchLowMark),
                                              new ThresholdMethod(OnPrefetchHighMark));
            } 
            else
            {
                // low and upper are the same
                _queue = new FlowControlQueue(_defaultPrefetchHighMark, _defaultPrefetchHighMark,
                                              null, null);
            }
            DefaultInstance = this;
        }
        public void initRKListener(string connectionUri)
        {
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);
            if (connection == null) 
                connection = new AMQConnection(connectionInfo);
            //IConnection connection;
            //AMQConnection  connection; 
            if (channel == null) 
                channel = (AmqChannel)EnsureConnected(connectionUri, true, true, out connection);

        }
        public event MessageReceivedDelegate OnAvroMessage; // { get; set; }

        /// <summary> Creates a topic listener using the specified broker URL. </summary>
        /// 
        /// <param name="connectionUri">The broker URL to listen on.</param>
        public void RoboKindListener(string connectionUri, string botcontrol)
        {
            LogDebug("TopicListener(string connectionUri = " + connectionUri + "): called " + botcontrol);

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);
            if (connection == null) connection = new AMQConnection(connectionInfo);

            // Establish a session on the broker.
            if (channel == null) channel = (AmqChannel)connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);
            
            // Set up a queue to listen for test messages on.
            string topicQueueName = channel.GenerateUniqueName();
          //  AMQDestination dest = null;
            // doug just hanged to !isEclusive
            channel.DeclareQueue(topicQueueName, false, false, true);

            // Set this listener up to listen for incoming messages on the test topic queue.
            channel.Bind(topicQueueName, ExchangeNameDefaults.TOPIC, botcontrol);
            IMessageConsumer consumer = channel.CreateConsumerBuilder(topicQueueName)
                .Create();
            consumer.OnMessage += OnMessage;

            // Set up this listener with a producer to send the reports on.
            //publisher = channel.CreatePublisherBuilder()
            //    .WithExchangeName(ExchangeNameDefaults.DIRECT)
            //    .WithRoutingKey(RoboKindAvroQPIDModuleMain.ROBOKIND_RESPONSE_ROUTING_KEY)
            //    .Create();
            //publisher.Close();
            //publisher = null;

            connection.Start();

        }
        public IChannel EnsureConnected(String connectionUri, bool createNewChannel, bool createNewConnection, out AMQConnection madeCon)
        {
            madeCon = (AMQConnection)(createNewConnection ? null : this.connection);
            bool startConnection = createNewConnection;
            AmqChannel channel = (AmqChannel)(createNewConnection ? null : this.channel);
            // Create a connection to the broker.
            IConnectionInfo connectionInfo0 = QpidConnectionInfo.FromUrl(connectionUri);
            if (madeCon == null)
            {
                madeCon = new AMQConnection(connectionInfo0);
                startConnection = true;

                // Set up a queue to listen for reports on.
                //CreateDirectListener(channel, RoboKindAvroQPIDModuleMain.ROBOKIND_RESPONSE_ROUTING_KEY, OnMessage);
                //TopicDefault = botcontrol;

            }

            // Establish a session on the broker.
            if (channel == null || createNewChannel)
            {
                channel = (AmqChannel) madeCon.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);
            }

            if (startConnection)
            {
             //   madeCon.Start();
            }
            return channel;
        }
        internal BasicMessageConsumer(ushort channelId, string queueName, bool noLocal,
                                      MessageFactoryRegistry messageFactory, AmqChannel channel,
                                      int prefetchHigh, int prefetchLow, bool exclusive, bool browse)
        {
            _channelId = channelId;
            _queueName = queueName;
            _noLocal = noLocal;
            _messageFactory = messageFactory;
            _channel = channel;
            _acknowledgeMode = _channel.AcknowledgeMode;
            _prefetchHigh = prefetchHigh;
            _prefetchLow = prefetchLow;
            _exclusive = exclusive;
            _browse = browse;

            if (_acknowledgeMode == AcknowledgeMode.SessionTransacted)
            {
                _receivedDeliveryTags = new LinkedList<long>();
            }
        }
      public BasicMessageProducer(string exchangeName, string routingKey,
          bool transacted,
          ushort channelId,
          AmqChannel channel,
          long producerId,
          DeliveryMode deliveryMode,
          long timeToLive,
          bool immediate,
          bool mandatory,
          int priority)
      {
         _exchangeName = exchangeName;
         _routingKey = routingKey;
         _transacted = transacted;
         _channelId = channelId;
         _channel = channel;
         _producerId = producerId;
         _deliveryMode = deliveryMode;
         _timeToLive = timeToLive;
         _immediate = immediate;
         _mandatory = mandatory;
         _messagePriority = priority;

         _channel.RegisterProducer(producerId, this);
      }