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


C# ISession.CreateConsumer方法代码示例

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


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

示例1: Queue

        public Queue(MsgDeliveryMode mode = MsgDeliveryMode.NonPersistent)
        {
            Uri msgQueue = new Uri("activemq:tcp://localhost:61616");

            _factory = new ConnectionFactory(msgQueue);
            try
            {
                _connection = _factory.CreateConnection();
            }
            catch (NMSConnectionException ex)
            {
                Log.FatalException("Error connecting to MQ server", ex);
                throw;
            }
            // TODO check _connection for null
            _connection.RequestTimeout = TimeSpan.FromSeconds(60);
            Session = _connection.CreateSession();

            // TODO need to find out if queue exists.
            // It creates a new queue if it doesn't exist.
            _destination = Session.GetDestination("queue://TwitterSearchStream");
            _consumer = Session.CreateConsumer(_destination);

            _producer = Session.CreateProducer(_destination);
            _producer.RequestTimeout = TimeSpan.FromSeconds(60);
            _producer.DeliveryMode = mode;

            _connection.Start();

            _connection.ExceptionListener += _connection_ExceptionListener;
            _connection.ConnectionInterruptedListener += _connection_ConnectionInterruptedListener;
        }
开发者ID:cfmayer,项目名称:Toketee,代码行数:32,代码来源:Queue.cs

示例2: OpenWireConsumer

        /// <summary>
        /// 消息消费构造器
        /// </summary>
        /// <param name="brokerUri">地址</param>
        /// <param name="username">用户名</param>
        /// <param name="psw">密码</param>
        /// <param name="clientId">客户端标识 兼做队列接收目的地</param>
        /// <param name="isClient">true 客户端;false 服务端</param>
        public OpenWireConsumer(string brokerUri, string username, string psw, string clientId,bool isClient)
        {
            NMSConnectionFactory _factory = new NMSConnectionFactory(brokerUri, clientId);
            _connection = _factory.CreateConnection(username, psw);
            _connection.Start();
            _session = _connection.CreateSession(AcknowledgementMode.AutoAcknowledge);

            if (isClient)
            {
                _qReceiveDest = _session.GetDestination(clientId, DestinationType.TemporaryQueue);
            }
            else
            {
                _qReceiveDest = _session.GetQueue(clientId);
            }

            _messageConsumer = _session.CreateConsumer(_qReceiveDest);
            _messageConsumer.Listener += (message) =>
            {
                if (Listener != null)
                {
                    Listener(message);
                }
            };
        }
开发者ID:OldApple,项目名称:MQProxy,代码行数:33,代码来源:OpenWireMiddleware.cs

示例3: btnSetup_Click

                //IDestination destination;
                //        string destinationTarget;
                //switch (cboxDestinationType.SelectedIndex)
                //{
                //    case 0:
                //        destinationTarget = QUEUE_PREFIX + cboxQueueList.Items[cboxQueueList.SelectedIndex] + MAX_INACTIVITY_DURATION;
                //        break;
                //    case 1:
                //        destinationTarget = TOPIC_PREFIX + cboxTopicList.Items[cboxTopicList.SelectedIndex] + MAX_INACTIVITY_DURATION;
                //        break;
                //    default:
                //        throw new Exception("Please select a destination.");
                //}
                //destination = SessionUtil.GetDestination(_session, destinationTarget);

        private void btnSetup_Click(object sender, EventArgs e)
        {
            try
            {
                //TearDown();
                //_connectionFactory = new ConnectionFactory(_connectUri, CLIENT_ID);               
                //_connection = _connectionFactory.CreateConnection(Properties.Settings.Default.MessageServerUserId, Properties.Settings.Default.MessageServerPassword);

                Environment.SetEnvironmentVariable("is.hornetQ.client", "true");
                _connection = CreateConnection();
                _connection.ExceptionListener += new ExceptionListener(OnException);
                _session = _connection.CreateSession(AcknowledgementMode.AutoAcknowledge);

                string destName = cboxTopicList.Text;
                IDestination dest = SessionUtil.GetDestination(_session, TOPIC_PREFIX + destName);
                var consumer = _session.CreateConsumer(dest);
                consumer.Listener += new MessageListener(OnMessage);

                ITextMessage request = _session.CreateTextMessage("Connection verification has been received.");
                
                //request.NMSCorrelationID = "abc";
                //request.Properties["NMSXGroupID"] = "cheese";
                //request.Properties["myHeader"] = "Cheddar";
                using (IMessageProducer producer = _session.CreateProducer(dest))
                {
                    producer.Send(request);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception doing setup: " + "\n" + ex.Message.ToString());
            }
        }
开发者ID:Amphora2015,项目名称:DemoTest,代码行数:48,代码来源:frmTestHornetQ.cs

示例4: MessageTransporter

 public MessageTransporter()
 {
     _connectionFactory = new Apache.NMS.Stomp.ConnectionFactory("tcp://0.0.0.0:61613");
     _connection = _connectionFactory.CreateConnection();
     _session = _connection.CreateSession();
     _destination = SessionUtil.GetDestination(_session, "queue://testingQueue");
     _messageProducer = _session.CreateProducer(_destination);
     _messageConsumer = _session.CreateConsumer(_destination);
 }
开发者ID:ivankarpey,项目名称:qa,代码行数:9,代码来源:MessageTransporter.cs

示例5: Master

        public Master(IUserService service)
        {
            DownloadUsers = new DownloadUsers(service);

            Factory = new NMSConnectionFactory("tcp://localhost:61616");
            Connection = Factory.CreateConnection();
            Connection.Start();
            Session = Connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            Destination = SessionUtil.GetDestination(Session, "Users");
            Receiver = Session.CreateConsumer(Destination);
        }
开发者ID:KiraTanaka,项目名称:VK,代码行数:11,代码来源:Master.cs

示例6: Connect

 private void Connect()
 {
     factory = XmsUtilities.CreateConnectionFactory(destination);
     connection = factory.CreateConnection();
     connection.ExceptionListener += OnError;
     session = connection.CreateSession(transactional, AcknowledgeMode.AutoAcknowledge);
     queue = session.CreateQueue(destination.Queue);
     queue.SetIntProperty(XMSC.DELIVERY_MODE,
                          transactional ? XMSC.DELIVERY_PERSISTENT : XMSC.DELIVERY_NOT_PERSISTENT);
     consumer = session.CreateConsumer(queue);
     connection.Start();
 }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.2,代码行数:12,代码来源:XmsConsumer.cs

示例7: ClientResultStream

        public ClientResultStream(OpenGammaFudgeContext fudgeContext, MQTemplate mqTemplate, bool checkSeqNumber)
        {
            _mqTemplate = mqTemplate;

            _fudgeMessageDecoder = new FudgeMessageDecoder(fudgeContext, checkSeqNumber);
            _connection = _mqTemplate.CreateConnection();
            _session = _connection.CreateSession();

            _destination = _session.CreateTemporaryQueue();

            _consumer = _session.CreateConsumer(_destination);
            _consumer.Listener += RawMessageReceived;
            _connection.Start();
        }
开发者ID:BietteMaxime,项目名称:OG-DotNet,代码行数:14,代码来源:ClientResultStream.cs

示例8: Stomp

        public Stomp(bool durable)
        {
            _connectionFactory = new ConnectionFactory("tcp://localhost:61613");
            _connection = _connectionFactory.CreateConnection();
            _connection.ClientId = "13AC0CF8-65FE-4638-8B85-62210DD89BEE";
            _connection.Start();
            _session = _connection.CreateSession();

            var topic = _session.GetQueue("exampleQueue");

            _producer = _session.CreateProducer(topic);
            _producer.DeliveryMode = durable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent;

            _consumer = _session.CreateConsumer(topic);
        }
开发者ID:bling,项目名称:MessageQueuePerfTest,代码行数:15,代码来源:Stomp.cs

示例9: TestQueueRollbackConsumerListener

        public void TestQueueRollbackConsumerListener()
        {
            connection.Start();

            this.session = connection.CreateSession(AcknowledgementMode.Transactional);
            ITemporaryQueue queue = session.CreateTemporaryQueue();
            IMessageProducer producer = session.CreateProducer(queue);
            IMessage message = session.CreateTextMessage("Test Message");
            producer.Send(message);
            session.Commit();

            IMessageConsumer consumer = session.CreateConsumer(queue);

            consumer.Listener += new MessageListener(OnMessageListener);

            Thread.Sleep(500);

            // first try.. should get 2 since there is no delay on the
            // first redeliver..
            Assert.AreEqual(2, counter);

            Thread.Sleep(1000);

            // 2nd redeliver (redelivery after 1 sec)
            Assert.AreEqual(3, counter);

            Thread.Sleep(2000);

            // 3rd redeliver (redelivery after 2 seconds) - it should give up after
            // that
            Assert.AreEqual(4, counter);

            // create new message
            producer.Send(session.CreateTextMessage("Test Message Again"));
            session.Commit();

            Thread.Sleep(500);

            // it should be committed, so no redelivery
            Assert.AreEqual(5, counter);

            Thread.Sleep(1500);

            // no redelivery, counter should still be 5
            Assert.AreEqual(5, counter);

            session.Close();
        }
开发者ID:ThorTech,项目名称:apache-nms,代码行数:48,代码来源:MessageListenerRedeliveryTest.cs

示例10: Server

        public Server()
        {
            InitializeComponent();
            listBox1.DataSource = listener;

            //服务端
            String brokerUri = "stomp:tcp://" + host + ":" + port + "?transport.useLogging=true";
            factory = new NMSConnectionFactory(brokerUri);
            connection = factory.CreateConnection(user, password);
            connection.Start();
            session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            consumer = session.CreateConsumer(session.GetQueue(re_destination));
            producer = session.CreateProducer();
            listener.Add("Starting up Listener.");
            listener.Add("Waiting for messages...");
            t1 = new Thread(new ThreadStart(StartListener));
        }
开发者ID:OldApple,项目名称:MQProxy,代码行数:17,代码来源:Server.cs

示例11: Client

        public Client()
        {
            InitializeComponent();
            listBox2.DataSource = publisher;

            //客户端
            String brokerUri2 = "stomp:tcp://" + host + ":" + port;
            factory2 = new NMSConnectionFactory(brokerUri2);
            connection2 = factory2.CreateConnection(user, password);
            connection2.Start();
            session2 = connection2.CreateSession(AcknowledgementMode.AutoAcknowledge);
            dest2 = session2.GetQueue(se_destination);
            producer = session2.CreateProducer(dest2);
            consumer = session2.CreateConsumer(session2.GetQueue(re_destination));
            consumer.Listener += (lllll) =>
                {
                    publisher.Add(String.Format("Receive {0} CorrelationId {1}", listenercount++, lllll.NMSCorrelationID));
                };
            publisher.Add("Starting up Publisher.");
            publisher.Add("Sending  messages...");
            t2 = new Thread(new ThreadStart(StartPublisher));
        }
开发者ID:OldApple,项目名称:MQProxy,代码行数:22,代码来源:Client.cs

示例12: SetUp

        public void SetUp()
        {
            A.Fake<IConnectionFactory>();
            _connection = A.Fake<IConnection>();
            _lazyConnection = new Lazy<IConnection>(() =>
            {
                _connection.Start();
                return _connection;
            });
            _session = A.Fake<ISession>();
            _consumer = A.Fake<IMessageConsumer>();
            _deserializer = A.Fake<IMessageDeserializer<ITestMessage>>();
            _observer = A.Fake<IObserver<ITestMessage>>();
            _destination = A.Fake<IDestination>();
            _acknowledgementMode = AcknowledgementMode.AutoAcknowledge;

            A.CallTo(() => _connection.CreateSession(A<Apache.NMS.AcknowledgementMode>.Ignored)).Returns(_session);
            A.CallTo(() => _session.CreateConsumer(_destination)).Returns(_consumer);

            _source = new MessageSource<ITestMessage>(_lazyConnection, new[] {_deserializer}, _destination,
                _acknowledgementMode);
        }
开发者ID:megakid,项目名称:Obvs.ActiveMQ,代码行数:22,代码来源:TestMessageSource.cs

示例13: ActiveConsumer

        public ActiveConsumer(IConnection amqConnection, ISession amqSession, String amqQueueName, EasyNetQ.IBus rabbitBus)
        {
            try
            {
                _rabbitBus = rabbitBus;
                ActiveMQQueue topic = new ActiveMQQueue(amqQueueName);

                _amqConsumer = amqSession.CreateConsumer(topic);
                _amqConsumer.Listener +=_amqConsumer_Listener;

               _rabbitBus.Subscribe<CorpMessage>(amqQueueName, _rabbitMQConsumer_Listener);

               log.Info("Consumer Connected to Queue '" + amqQueueName + "'");
            }
            catch(Exception e)
            {
                log.Info(e.ToString());
                log.Debug(e.ToString());
            }
            finally
            {

            }
        }
开发者ID:parampavar,项目名称:angtut,代码行数:24,代码来源:ActiveConsumer.cs

示例14: CreateConsumer

 /// <summary>
 /// Creates a MessageConsumer for the given Session and Destination.
 /// </summary>
 /// <param name="session">The session to create a MessageConsumer for.</param>
 /// <param name="destination">The destination to create a MessageConsumer for.</param>
 /// <returns>The new MessageConsumer</returns>
 protected IMessageConsumer CreateConsumer(ISession session, Destination destination)
 {
     // Only pass in the NoLocal flag in case of a Topic:
     // Some EMS providers, such as WebSphere MQ 6.0, throw IllegalStateException
     // in case of the NoLocal flag being specified for a Queue.
     if (PubSubDomain)
     {
         if (SubscriptionDurable && destination is Topic)
         {
             return session.CreateDurableSubscriber(
                 (Topic) destination, DurableSubscriptionName, MessageSelector, PubSubNoLocal);
         }
         else
         {
             return session.CreateConsumer(destination, MessageSelector, PubSubNoLocal);
         }
     }
     else
     {
         return session.CreateConsumer(destination, MessageSelector);
     }
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:28,代码来源:SimpleMessageListenerContainer.cs

示例15: TryConnect

        private void TryConnect()
        {
            Task.Factory.StartNew(() =>
            {

                while (!_cts.IsCancellationRequested)
                {
                    if (!_isConnect)
                    {
                        _logger.Info("开始尝试连接队列服务器![{0}-{1}]".GetFormat(_name, _uri));
                        try
                        {
                            _factory = new ConnectionFactory(_uri);
                            _connection = _factory.CreateConnection();
                            _connection.ConnectionInterruptedListener += () =>
                            {
                                _logger.Error("与队列服务器断开连接![{0}-{1}]".GetFormat(_name, _uri));
                                _isConnect = false;
                            };
                            _connection.ClientId = Guid.NewGuid().ToString();
                            _connection.Start();
                            _session = _connection.CreateSession();
                            _consumer = _session.CreateConsumer(new ActiveMQQueue(_name));
                            _isConnect = true;
                            _logger.Info("连接队列服务器成功![{0}-{1}]".GetFormat(_name, _uri));
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("连接队列服务器失败![{0}-{1}]".GetFormat(_name, _uri), ex);
                            _isConnect = false;
                        }
                    }
                    Thread.Sleep(10 * 1000);
                }

            },_cts.Token);
        }
开发者ID:hhahh2011,项目名称:CH.Spartan,代码行数:37,代码来源:Queue.cs


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