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


C# ConnectionFactory.CreateConnection方法代码示例

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


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

示例1: TestProducerSendWithTimeout

		public void TestProducerSendWithTimeout()
		{
			int timeout = 1500;
			Uri uri = new Uri(string.Format("mock://localhost:61616?connection.RequestTimeout={0}&transport.respondToMessages=false", timeout));

			ConnectionFactory factory = new ConnectionFactory(uri);
			using(IConnection connection = factory.CreateConnection())
			using(ISession session = connection.CreateSession())
			{
				IDestination destination = session.GetTopic("Test");
				using(IMessageProducer producer = session.CreateProducer(destination))
				{
					ITextMessage message = session.CreateTextMessage("Hello World");

					for(int i = 0; i < 10; ++i)
					{
						DateTime start = DateTime.Now;

						try
						{
							producer.Send(message);
							Assert.Fail("Expected a RequestTimedOutException");
						}
						catch(RequestTimedOutException)
						{
						}
						
						TimeSpan elapsed = DateTime.Now - start;
						// Make sure we timed out.
						Assert.GreaterOrEqual((int) elapsed.TotalMilliseconds, timeout - 10, "Did not reach timeout limit.");
					}
				}
			}
		}
开发者ID:Redi0,项目名称:meijing-ui,代码行数:34,代码来源:MessageProducerTest.cs

示例2: CreateConnection

 private IConnection CreateConnection()
 {
     IConnectionFactory factory = new ConnectionFactory(jmsServer);
     IConnection connection = factory.CreateConnection(userId, password);
     connection.Start();
     return connection;
 }
开发者ID:Amphora2015,项目名称:DemoTest,代码行数:7,代码来源:JMSSubscriber.cs

示例3: TestHundredsOfConnectionsWithRandomHeartbeatInterval

        public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
        {
            if (!LongRunningTestsEnabled())
            {
                Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
                return;
            }

            var rnd = new Random();
            List<IConnection> xs = new List<IConnection>();
            for (var i = 0; i < 200; i++)
            {
                var n = Convert.ToUInt16(rnd.Next(2, 6));
                var cf = new ConnectionFactory() { RequestedHeartbeat = n, AutomaticRecoveryEnabled = false };
                var conn = cf.CreateConnection();
                xs.Add(conn);
                var ch = conn.CreateModel();
                bool wasShutdown = false;

                conn.ConnectionShutdown += (sender, evt) =>
                    {
                        CheckInitiator(evt);
                    };
            }

            SleepFor(60);

            foreach (var x in xs)
            {
                x.Close();
            }
        }
开发者ID:SilversphereInc,项目名称:rabbitmq-dotnet-client,代码行数:32,代码来源:TestHeartbeats.cs

示例4: TestHundredsOfConnectionsWithRandomHeartbeatInterval

        public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
        {
            var rnd = new Random();
            List<IConnection> xs = new List<IConnection>();
            for (var i = 0; i < 200; i++)
            {
                var n = Convert.ToUInt16(rnd.Next(2, 6));
                var cf = new ConnectionFactory() { RequestedHeartbeat = n, AutomaticRecoveryEnabled = false };
                var conn = cf.CreateConnection();
                xs.Add(conn);
                var ch = conn.CreateModel();
                bool wasShutdown = false;

                conn.ConnectionShutdown += (sender, evt) =>
                    {
                        CheckInitiator(evt);
                    };
            }

            SleepFor(60);

            foreach (var x in xs)
            {
                x.Close();
            }
        }
开发者ID:nbsynch,项目名称:rabbitmq-dotnet-client,代码行数:26,代码来源:TestHeartbeats.cs

示例5: TestNoCopyOnSend

        public void TestNoCopyOnSend()
        {
            Uri uri = new Uri("mock://localhost:61616?connection.CopyMessageOnSend=false");

            ConnectionFactory factory = new ConnectionFactory(uri);
            using(IConnection connection = factory.CreateConnection())
            using(ISession session = connection.CreateSession())
            {
                IDestination destination = session.GetTopic("Test");
                using(IMessageProducer producer = session.CreateProducer(destination))
                {
                    ITextMessage message = session.CreateTextMessage();

                    for(int i = 0; i < 10; ++i)
                    {
                        try
                        {
                            message.Properties["TribbleName"] = "Tribble" + i.ToString();
                            message.Text = "The Trouble with Tribbles - " + i.ToString();
                            producer.Send(message);
                        }
                        catch(MessageNotWriteableException)
                        {
                            Assert.Greater(i, 0);
                            Assert.Less(i, 10);
                        }
                    }
                }
            }
        }
开发者ID:ThorTech,项目名称:apache-nms,代码行数:30,代码来源:MessageProducerTest.cs

示例6: TestRedelivered

        public void TestRedelivered()
        {
            // enqueue several messages
            PurgeDatabase();
            PurgeAndFillQueue();

            // receive just one
            INetTxConnectionFactory factory = new NetTxConnectionFactory(ReplaceEnvVar(connectionURI));
            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                connection.Start();

                using (INetTxSession session = connection.CreateNetTxSession())
                {
                    IQueue queue = session.GetQueue(testQueueName);

                    // read message from queue and insert into db table
                    using (IMessageConsumer consumer = session.CreateConsumer(queue))
                    {
                        using (TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
                        using (SqlConnection sqlConnection = new SqlConnection(sqlConnectionString))
                        using (SqlCommand sqlInsertCommand = new SqlCommand())
                        {
                            sqlConnection.Open();
                            sqlInsertCommand.Connection = sqlConnection;

                            ITextMessage message = consumer.Receive(TimeSpan.FromMilliseconds(10000)) as ITextMessage;
                            sqlInsertCommand.CommandText =
                                string.Format("INSERT INTO {0} VALUES ({1})", testTable, Convert.ToInt32(message.Text));
                            sqlInsertCommand.ExecuteNonQuery();

                            scoped.Complete();
                        }
                    }

                    session.Close();
                }
            }

            // check that others message have status redelivered = false
            IConnectionFactory checkFactory = new ConnectionFactory(ReplaceEnvVar(connectionURI));

            using (IConnection connection = checkFactory.CreateConnection())
            {
                connection.Start();

                using (ISession session = connection.CreateSession())
                using (IQueueBrowser browser = session.CreateBrowser(session.GetQueue(testQueueName)))
                {
                    IEnumerator enumerator = browser.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        IMessage msg = enumerator.Current as IMessage;
                        Assert.IsNotNull(msg, "message is not in the queue!");
                        Assert.IsFalse(msg.NMSRedelivered, "message is redelivered!");
                    }
                }
            }
        }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:60,代码来源:DtcConsumerTransactionsTest.cs

示例7: Init

 public override void Init()
 {
     var connFactory = new ConnectionFactory()
     {
         AutomaticRecoveryEnabled = false
     };
     Conn = connFactory.CreateConnection();
     Model = Conn.CreateModel();
 }
开发者ID:nbsynch,项目名称:rabbitmq-dotnet-client,代码行数:9,代码来源:TestSubscription.cs

示例8: RabbitMqService

        public RabbitMqService(string host)
        {
            _host = host;

            var factory = new ConnectionFactory
            {
                Protocol = Protocols.FromEnvironment(),
                HostName = _host
            };

            _connection = factory.CreateConnection();
        }
开发者ID:mickdelaney,项目名称:backbone-mvc-sample,代码行数:12,代码来源:RabbitMqService.cs

示例9: OpenConnection

 static IModel OpenConnection(string machine, string userName, string password)
 {
     ConnectionFactory factory = new ConnectionFactory
     {
         HostName = machine,
         Port = AmqpTcpEndpoint.UseDefaultPort,
         UserName = userName,
         Password = password,
     };
     IConnection conn = factory.CreateConnection();
     return conn.CreateModel();
 }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:12,代码来源:NativeSend.cs

示例10: DeleteQueue

 public static void DeleteQueue(string uri, string queueName)
 {
     ConnectionFactory factory = new ConnectionFactory
     {
         Uri = uri,
     };
     using (IConnection conn = factory.CreateConnection())
     using (IModel channel = conn.CreateModel())
     {
         channel.QueueUnbind(queueName, queueName, string.Empty, null);
         channel.ExchangeDelete(queueName);
         channel.QueueDelete(queueName);
     }
 }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:14,代码来源:QueueDeletion.cs

示例11: TestHandleLeak

 public void TestHandleLeak()
 {
     var cf = new ConnectionFactory();
     var me = Process.GetCurrentProcess();
     var n = me.HandleCount;
     Console.WriteLine("{0} handles before the test...", me.HandleCount);
     for (var i = 0; i < 1000; i++)
     {
         using (var conn = cf.CreateConnection())
         {
         }
     }
     Thread.Sleep(TimeSpan.FromSeconds(10));
     Console.WriteLine("{0} handles after the test...", me.HandleCount);
     Assert.That(me.HandleCount, Is.LessThanOrEqualTo(n));
 }
开发者ID:SilversphereInc,项目名称:rabbitmq-dotnet-client,代码行数:16,代码来源:TestConnectionChurnHandleLeak.cs

示例12: PerformLeakTest

 protected void PerformLeakTest(ConnectionFactory cf)
 {
     var me = Process.GetCurrentProcess();
     var n = me.HandleCount;
     Console.WriteLine("{0} handles before the test...", me.HandleCount);
     for (var i = 0; i < 1000; i++)
     {
         var conn = cf.CreateConnection();
         conn.Close();
     }
     GC.Collect();
     GC.WaitForPendingFinalizers();
     Thread.Sleep(TimeSpan.FromSeconds(10));
     me = Process.GetCurrentProcess();
     Console.WriteLine("{0} handles after the test...", me.HandleCount);
     // allow for a 20% margin of error, as GC behaviour and native handle
     // release is difficult to predict
     Assert.That(me.HandleCount, Is.LessThanOrEqualTo(n + 200));
 }
开发者ID:hanxinimm,项目名称:rabbitmq-dotnet-client,代码行数:19,代码来源:TestConnectionChurnHandleLeak.cs

示例13: TestCloseWithFaultyConsumer

        public void TestCloseWithFaultyConsumer()
        {
            ConnectionFactory connFactory = new ConnectionFactory();
            IConnection c = connFactory.CreateConnection();
            IModel m = Conn.CreateModel();
            object o = new object();
            string q = GenerateQueueName();
            m.QueueDeclare(q, false, false, false, null);

            CallbackExceptionEventArgs ea = null;
            m.CallbackException += (_, evt) => {
                ea = evt;
                c.Close();
                Monitor.PulseAll(o);
            };
            m.BasicConsume(q, true, new FaultyConsumer(Model));
            m.BasicPublish("", q, null, encoding.GetBytes("message"));
            WaitOn(o);

            Assert.IsNotNull(ea);
            Assert.AreEqual(c.IsOpen, false);
            Assert.AreEqual(c.CloseReason.ReplyCode, 200);
        }
开发者ID:hanxinimm,项目名称:rabbitmq-dotnet-client,代码行数:23,代码来源:TestMainLoop.cs

示例14: CreateQueue

        public static void CreateQueue(string uri, string queueName, bool durableMessages, bool createExchange)
        {
            ConnectionFactory factory = new ConnectionFactory
            {
                Uri = uri,
            };

            using (IConnection conn = factory.CreateConnection())
            {
                IModel channel = conn.CreateModel();

                channel.QueueDeclare(
                    queue: queueName,
                    durable: durableMessages,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);
                if (createExchange)
                {
                    CreateExchange(channel, queueName, durableMessages);
                }
            }
        }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:23,代码来源:QueueCreation.cs

示例15: Init

 public virtual void Init()
 {
     var connFactory = new ConnectionFactory();
     Conn = connFactory.CreateConnection();
     Model = Conn.CreateModel();
 }
开发者ID:rabbitmq,项目名称:rabbitmq-dotnet-client,代码行数:6,代码来源:Fixtures.cs


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