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


C# IConnection.CreateSession方法代码示例

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


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

示例1: 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

示例2: CreateMocks

        private void CreateMocks()
        {
            mockConnectionFactory = mocks.StrictMock<IConnectionFactory>();
            mockConnection = mocks.StrictMock<IConnection>();
            mockSession = mocks.StrictMock<ISession>();

            IQueue queue = mocks.StrictMock<IQueue>();

            Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once();
            if (UseTransactedTemplate)
            {
                Expect.Call(mockConnection.CreateSession(AcknowledgementMode.Transactional)).Return(mockSession).Repeat.
                    Once();
            }
            else
            {
                Expect.Call(mockConnection.CreateSession(AcknowledgementMode.AutoAcknowledge)).Return(mockSession).
                    Repeat.
                    Once();
            }
            Expect.Call(mockSession.Transacted).Return(true);

            mockDestinationResolver =
                mocks.StrictMock<IDestinationResolver>();
            mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false);
            LastCall.Return(queue).Repeat.Any();
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:27,代码来源:MessageTemplateTests.cs

示例3: Init

        public override void Init()
        {
            base.Init();
            _producers = new LinkedList<IMessageProducer>();
            _consumers = new Hashtable();

            XmlNode nmsNode = this.DestinationDefinition.PropertiesXml.SelectSingleNode("nms");
            _nmsSettings = new NMSSettings(nmsNode);
            if (_nmsSettings != null)
            {
                ConnectionFactory connectionFactory = new ConnectionFactory(_nmsSettings.URI);

                log.Debug(string.Format("NMSAdapter Connected to URI {0}", _nmsSettings.URI));

                _connection = connectionFactory.CreateConnection();
                _connection.Start();
                _session = _connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge);

                if (_nmsSettings.DESTINATION_TYPE.StartsWith(NMSSettings.QueueDestination))
                {
                    _destination = new ActiveMQQueue(_nmsSettings.Destination);
                    log.Debug(string.Format("NMSAdapter Connected to Queue {0}", _nmsSettings.Destination));
                }
                else if (_nmsSettings.DESTINATION_TYPE.StartsWith(NMSSettings.TopicDestination))
                {
                    _destination = new ActiveMQTopic(_nmsSettings.Destination);
                    log.Debug(string.Format("NMSAdapter Connected to Topic {0}", _nmsSettings.Destination));
                }
                else
                {
                    log.Debug(string.Format("Unknown Destination Type {0}", _nmsSettings.DESTINATION_TYPE));
                }
            }
        }
开发者ID:DarkActive,项目名称:daFluorineFx,代码行数:34,代码来源:NMSAdapter.cs

示例4: 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

示例5: Connecting

        protected bool Connecting()
        {
            if (mqConn != null)
            {
                return true;
            }

            // 尝试连接是否成功(不断开自动重连)
            if (!TryConnect())
            {
                return false;
            }

            // 实际连接,断开会自动重连
            string address = GetAddress();
            try
            {
                IConnectionFactory factory = new ConnectionFactory(address);
                mqConn = factory.CreateConnection();
                mqConn.Start();
                mqSession = mqConn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                return true;
            }
            catch (Exception ex)
            {
                ex.ToString();
                return false;
            }
        }
开发者ID:xumingxsh,项目名称:HiCSMQ,代码行数:29,代码来源:HiMQBase.cs

示例6: 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

示例7: UpdateConnection

        // Verbindung zum  Messaging-Server aktualisieren
        public void UpdateConnection()
        {
            try
            {
                // eventuell früher belegte Ressourcen freigeben
                CleanupResources();

                // Verbindung / Session / MessageProducer und -Consumer instanziieren
                if (connectionFactory == null)
                {
                    Console.WriteLine(brokerURL);
                    connectionFactory = new ConnectionFactory(brokerURL);
                }
                connection = connectionFactory.CreateConnection();
                session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                messageProducer = session.CreateProducer(new ActiveMQTopic(topicName));

                // Thread zum Empfang eingehender Nachrichten starten
                connection.Start();

                Console.WriteLine("Connection geändert, Broker-URL ist " + brokerURL);
            }
            catch (Exception e)
            {
                Console.WriteLine("*** EXCEPTION in updateConnection(): " + e.Message);
            }
        }
开发者ID:TLandmann,项目名称:Bachelor-HSRM-Medieninformatik,代码行数:28,代码来源:Producer.cs

示例8: SetUp

 public void SetUp()
 {
     connectionFactory = new ConnectionFactory("tcp://localhost:61616", GetType().Name);
     connection = connectionFactory.CreateConnection();
     connection.Start();
     session = connection.CreateSession();
 }
开发者ID:cityindex-attic,项目名称:RTD-Subscription-Engine,代码行数:7,代码来源:ActiveMQIntegrationTests.cs

示例9: 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

示例10: 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, XMSC.DELIVERY_PERSISTENT);
     producer = session.CreateProducer(queue);
 }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.2,代码行数:10,代码来源:XmsProducer.cs

示例11: Connect

        public void Connect(string clientId, string topicName, string host, int ip = 61616)
        {
            string broker = "tcp://" + host + ":" + ip;

            m_connection = new ConnectionFactory(broker, clientId).CreateConnection();
            m_session = m_connection.CreateSession();
            m_topic = new ActiveMQTopic(topicName);
            //m_clinet = m_session.CreateProducer(m_topic);
            m_client = CreateClient(m_session, m_topic);
        }
开发者ID:sohong,项目名称:greenfleet-viewer,代码行数:10,代码来源:TopicClient.cs

示例12: TopicPublisher

 public TopicPublisher(string topicName, string brokerUri)
 {
     this.topicName = topicName;
     this.connectionFactory = new ConnectionFactory(brokerUri);
     this.connection = this.connectionFactory.CreateConnection();
     this.connection.Start();
     this.session = connection.CreateSession();
     ActiveMQTopic topic = new ActiveMQTopic(topicName);
     this.producer = this.session.CreateProducer(topic);
 }
开发者ID:shadowlink,项目名称:SOR-Project,代码行数:10,代码来源:TopicPublisher.cs

示例13: Connect

        public void Connect()
        {
            while (!ableToSendEvents) {
                Uri connecturi = null;
                //if (textBoxSIPIPAddress.Text.StartsWith("ssl://"))
                //{
                Console.WriteLine ("Trying to connect to ActiveMQ broker ");
                //	connecturi = new Uri("activemq:" + textBoxSIPIPAddress.Text + ":" + textBoxSIPPort.Text + "?transport.ClientCertSubject=E%[email protected], CN%3DCommunication Tool"); // Connect to the ActiveMQ broker
                //}
                //else
                //{
                //log4.Debug(name + ": Trying to connect to ActiveMQ broker via non-secure connection");
                connecturi = new Uri ("activemq:tcp://localhost:61616"); // Connect to the ActiveMQ broker
                //}
                //Console.WriteLine("activeMQ::About to connect to " + connecturi);

                try {

                    // NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder.
                    IConnectionFactory factory = new ConnectionFactory (connecturi);

                    // Create a new connection and session for publishing events
                    activeMQConnection = factory.CreateConnection ();
                    activeMQSession = activeMQConnection.CreateSession ();

                    IDestination destination = SessionUtil.GetDestination (activeMQSession, "topic://SIFTEO");
                    //Console.WriteLine("activeMQ::Using destination: " + destination);

                    // Create the producer
                    activeMQProducer = activeMQSession.CreateProducer (destination);
                    activeMQProducer.DeliveryMode = MsgDeliveryMode.Persistent;
                    destination = SessionUtil.GetDestination (activeMQSession, "topic://XVR.CCC");
                    activeMQConsumer = activeMQSession.CreateConsumer (destination);
                    //activeMQConsumer.Listener += new MessageListener(OnCCCMessage);

                    // Start the connection so that messages will be processed
                    activeMQConnection.Start ();
                    //activeMQProducer.Persistent = true;

                    // Enable the sending of events
                    //log4.Debug(name + ": ActiveMQ connected on topics XVR.CCC and XVR.SDK");
                    ableToSendEvents = true;

                } catch (Exception exp) {
                    // Report the problem in the output.log (Program Files (x86)\E-Semble\XVR 2012\XVR 2012\XVR_Data\output_log.txt)
                    //Console.WriteLine("*** AN ACTIVE MQ ERROR OCCURED: " + exp.ToString() + " ***");
                    //log4.Error(name + ": Error connecting to ActiveMQ broker: " + exp.Message);
                    //log4.Error((exp.InnerException != null) ? exp.InnerException.StackTrace : "");

                    Console.WriteLine (exp.Message);
                }
                System.Threading.Thread.Sleep (1000);
            }
        }
开发者ID:rooch84,项目名称:TangibleInvestigator,代码行数:54,代码来源:AMQConnector.cs

示例14: SetUp

        public override void SetUp()
        {
            base.SetUp();

            connection = CreateConnection();
            connection.Start();

            Session session = connection.CreateSession() as Session;
            IQueue queue = session.GetQueue(destinationName);
            session.DeleteDestination(queue);
        }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:11,代码来源:RollbackRedeliveryTest.cs

示例15: PurgeQueue

        private void PurgeQueue(IConnection conn, IDestination queue)
        {
            ISession session = conn.CreateSession();
            IMessageConsumer consumer = session.CreateConsumer(queue);
            while(consumer.Receive(TimeSpan.FromMilliseconds(500)) != null)
            {
            }

            consumer.Close();
            session.Close();
        }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:11,代码来源:QueueConsumerPriorityTest.cs


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