当前位置: 首页>>代码示例>>C#>>正文


C# IChannel.DeclareQueue方法代码示例

本文整理汇总了C#中IChannel.DeclareQueue方法的典型用法代码示例。如果您正苦于以下问题:C# IChannel.DeclareQueue方法的具体用法?C# IChannel.DeclareQueue怎么用?C# IChannel.DeclareQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IChannel的用法示例。


在下文中一共展示了IChannel.DeclareQueue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

        public virtual void Init()
        {
            _logger.Info("public virtual void Init(): called");

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI);
            _connection = new AMQConnection(connectionInfo);
            _logger.Info("Starting...");

            // Register this to listen for exceptions on the test connection.
            _exceptionDelegate = new ExceptionListenerDelegate(OnException);
            _connection.ExceptionListener += _exceptionDelegate;

            // Establish a session on the broker.
            _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

            // Create a durable, non-temporary, non-exclusive queue.
            _queueName = _channel.GenerateUniqueName();
            _channel.DeclareQueue(_queueName, true, false, false);

            _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey);

            // Clear the most recent message and exception.
            _lastException = null;
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:25,代码来源:ChannelQueueTest.cs

示例2: TopicListener

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

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

            // Establish a session on the broker.
            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);
            
            // Set up a queue to listen for test messages on.
            string topicQueueName = channel.GenerateUniqueName();
            channel.DeclareQueue(topicQueueName, false, true, true);

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

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

            connection.Start();
            Console.WriteLine("Waiting for messages...");
            while (true)
            {
                if (shutdownReceivedEvt.WaitOne(TIMEOUT, true))
                {
                    Console.WriteLine("message was received");
                }
                else
                {
                    Console.WriteLine("timeout elapsed");
                }                
            }
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:44,代码来源:TopicListener.cs

示例3: TopicPublisher

        /// <summary>
        /// Creates a topic publisher that will send the specifed number of messages and expect the specifed number of report back from test
        /// subscribers.
        /// </summary>
        /// 
        /// <param name="connectionUri">The broker URL.</param>
        /// <param name="numMessages">The number of messages to send in each test.</param>
        /// <param name="numSubscribers">The number of subscribes that are expected to reply with a report.</param>
        TopicPublisher(string connectionUri, int numMessages, int numSubscribers)
        {
            log.Debug("TopicPublisher(string connectionUri = " + connectionUri + ", int numMessages = "+ numMessages + 
                      ", int numSubscribers = " + numSubscribers + "): called");

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

            // Establish a session on the broker.
            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

            // Set up a queue to listen for reports on.
            string responseQueueName = channel.GenerateUniqueName();
            channel.DeclareQueue(responseQueueName, false, true, true);
            
            // Set this listener up to listen for reports on the response queue.
            channel.Bind(responseQueueName, ExchangeNameDefaults.DIRECT, RESPONSE_ROUTING_KEY);
            //channel.Bind(responseQueueName, "<<default>>", RESPONSE_ROUTING_KEY);
            IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName)               
                .Create();
            consumer.OnMessage += new MessageReceivedDelegate(OnMessage);

            // Set up this listener with a producer to send the test messages and report requests on.
            publisher = channel.CreatePublisherBuilder()
                .WithExchangeName(ExchangeNameDefaults.TOPIC)
                .WithRoutingKey(CONTROL_ROUTING_KEY)
                .Create();

            // Keep the test parameters.
            this.numMessages = numMessages;
            this.numSubscribers = numSubscribers;

            connection.Start();
            Console.WriteLine("Sending messages and waiting for reports...");
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:44,代码来源:TopicPublisher.cs

示例4: Init

        public override void Init()
        {          
            // Ensure that the base init method is called. It establishes a connection with the broker.
            base.Init();   

            connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);         
            _connection = new AMQConnection(connectionInfo);
            _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300);

            _logger.Info("Starting...");
            _logger.Info("Exchange name is '" + _exchangeName + "'...");

            // Register this to listen for exceptions on the test connection.
            _exceptionDelegate = new ExceptionListenerDelegate(OnException);
            _connection.ExceptionListener += _exceptionDelegate;

            // Declare a new headers exchange with the name of the test service.
            _channel.DeclareExchange(_exchangeName, ExchangeClassConstants.HEADERS);

            // Create a non-durable, temporary (aka auto-delete), exclusive queue.
            string queueName = _channel.GenerateUniqueName();
            _channel.DeclareQueue(queueName, false, true, true);

            // Bind the queue to the new headers exchange, setting up some header patterns for the exchange to match.
            _channel.Bind(queueName, _exchangeName, null, CreatePatternAsFieldTable());

            // Create a test consumer to consume messages from the test exchange.
            _consumer = _channel.CreateConsumerBuilder(queueName)
                .WithPrefetchLow(100)
                .WithPrefetchHigh(500)
                .WithNoLocal(false) // make sure we get our own messages
                .Create();

            // Register this to listen for messages on the consumer.
            _msgRecDelegate = new MessageReceivedDelegate(OnMessage);
            _consumer.OnMessage += _msgRecDelegate;
            
            // Clear the most recent message and exception.
            _lastException = null;
            _lastMessage = null;

            _publisher = _channel.CreatePublisherBuilder()
                    .WithExchangeName(_exchangeName)
                    .WithMandatory(true)
                    .Create();

            _publisher.DeliveryMode = DeliveryMode.NonPersistent;

            // Start all channel
            _connection.Start();
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:51,代码来源:HeadersExchangeTest.cs

示例5: Start

        /// <summary>
        /// Starts the interop test client running. This causes it to start listening for incoming test invites.
        /// </summary>
        private void Start()
        {
            log.Info("private void Start(): called");

            // Use a class path scanner to find all the interop test case implementations.
            ArrayList testCaseClasses = new ArrayList();

            // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true);
            // Hard code the test classes till the classpath scanner is fixed.
            testCaseClasses.Add(typeof(TestCase1DummyRun));
            testCaseClasses.Add(typeof(TestCase2BasicP2P));
            testCaseClasses.Add(typeof(TestCase3BasicPubSub));
            testCaseClasses.Add(typeof(TestCase4P2PMessageSize));
            testCaseClasses.Add(typeof(TestCase5PubSubMessageSize));

            // Create all the test case implementations and index them by the test names.
            foreach (Type testClass in testCaseClasses)
            {
                InteropClientTestCase testCase = (InteropClientTestCase)Activator.CreateInstance(testClass);
                testCases.Add(testCase.GetName(), testCase);

                log.Info("Found test case: " + testClass);
            }

            // Open a connection to communicate with the coordinator on.
            log.Info("brokerUrl = " + brokerUrl);
            IConnection connection = CreateConnection(brokerUrl, virtualHost);

            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge);

            // Set this up to listen for control messages.
            string responseQueueName = channel.GenerateUniqueName();
            channel.DeclareQueue(responseQueueName, false, true, true);

            channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control." + clientName);
            channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control");

            IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName)
                .Create();
            consumer.OnMessage += new MessageReceivedDelegate(OnMessage);

            // Create a publisher to send replies with.
            publisherBuilder = channel.CreatePublisherBuilder()
                .WithExchangeName(ExchangeNameDefaults.DIRECT);
                

            // Start listening for incoming control messages.
            connection.Start();
            Console.WriteLine("Test client " + clientName + " ready to receive test control messages...");
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:53,代码来源:TestClient.cs

示例6: AssignRole

        /// <summary>
        /// Assigns the role to be played by this test case. The test parameters are fully specified in the
        /// assignment message. When this method return the test case will be ready to execute.
        /// </summary>
        ///
        /// <param name="role">              The role to be played; sender or receiver. </param>
        /// <param name="assignRoleMessage"> The role assingment message, contains the full test parameters. </param>
        public void AssignRole(Roles role, IMessage assignRoleMessage) 
        {
            log.Debug("public void AssignRole(Roles role = " + role + ", Message assignRoleMessage = " + assignRoleMessage
                + "): called");
    
            // Reset the message count for a new test.
            messageCount = 0;

            // Take note of the role to be played.
            this.role = role;

            // Create a new connection to pass the test messages on.
            connection =
                TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost);
            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge);

            // Extract and retain the test parameters.
            numMessages = assignRoleMessage.Headers.GetInt("P2P_NUM_MESSAGES");
            string queueAndKeyName = assignRoleMessage.Headers.GetString("P2P_QUEUE_AND_KEY_NAME");
            channel.DeclareQueue(queueAndKeyName, false, true, true);
            channel.Bind(queueAndKeyName, ExchangeNameDefaults.DIRECT, queueAndKeyName);
            sendDestination = queueAndKeyName;

            log.Debug("numMessages = " + numMessages);
            log.Debug("sendDestination = " + sendDestination);
            log.Debug("role = " + role);

            switch (role)
            {
            // Check if the sender role is being assigned, and set up a message producer if so.
            case Roles.SENDER:
                publisher = channel.CreatePublisherBuilder()
                .WithExchangeName(ExchangeNameDefaults.DIRECT)
                .WithRoutingKey(sendDestination)
                .Create();
                break;

            // Otherwise the receiver role is being assigned, so set this up to listen for messages.
            case Roles.RECEIVER:
                IMessageConsumer consumer = channel.CreateConsumerBuilder(sendDestination).Create();
                consumer.OnMessage += new MessageReceivedDelegate(OnMessage);

                break;
            }

            connection.Start();
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:54,代码来源:TestCase2BasicP2P.cs


注:本文中的IChannel.DeclareQueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。