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


C# IConnectionFactory.CreateConnection方法代码示例

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


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

示例1: NmsConnection

 public NmsConnection(IConnectionFactory connectionFactory, Apache.NMS.AcknowledgementMode acknowledgementMode, NmsCredentials credentials)
 {
     this.connection = (credentials == null)
         ? connectionFactory.CreateConnection()
         : connectionFactory.CreateConnection(credentials.Username, credentials.Password);
     this.acknowledgementMode = acknowledgementMode;
     this.id = idCounter++;
     this.WireUpEvents();
 }
开发者ID:cylwit,项目名称:EasyNMS,代码行数:9,代码来源:NmsConnection.cs

示例2: CreateMocks

        private void CreateMocks()
        {
            mockConnectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
            mockConnection = (IConnection) mocks.CreateMock(typeof (IConnection));
            mockSession = (ISession) mocks.CreateMock(typeof (ISession));

            TIBCO.EMS.Queue queue = new TIBCO.EMS.Queue("test"); //(Queue) mocks.CreateMock(typeof (Queue));

            Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once();
            if (UseTransactedTemplate)
            {
                Expect.Call(mockConnection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(mockSession).Repeat.
                    Once();
            }
            else
            {
                Expect.Call(mockConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE)).Return(mockSession).
                    Repeat.
                    Once();
            }
            Expect.Call(mockSession.Transacted).Return(true);

            mockDestinationResolver =
                (IDestinationResolver) mocks.CreateMock(typeof (IDestinationResolver));
            mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false);
            LastCall.Return(queue).Repeat.Any();
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:27,代码来源:MessageTemplateTests.cs

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

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

示例5: CreateMocks

        private void CreateMocks()
        {
            mockConnectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
            mockConnection = (IConnection) mocks.CreateMock(typeof (IConnection));
            mockSession = (ISession) mocks.CreateMock(typeof (ISession));

            IQueue queue = (IQueue) mocks.CreateMock(typeof (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 =
                (IDestinationResolver) mocks.CreateMock(typeof (IDestinationResolver));
            mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false);
            LastCall.Return(queue).Repeat.Any();
        }
开发者ID:fuadm,项目名称:spring-net,代码行数:27,代码来源:MessageTemplateTests.cs

示例6: ChannelFactory

        public ChannelFactory(RawRabbitConfiguration config, IConnectionFactory connectionFactory)
        {
            _connectionFactory = connectionFactory;
            _accessDictionary = new ConcurrentDictionary<IModel, DateTime>();
            _config = config;
            _threadChannels = new ThreadLocal<IModel>(true);

            try
            {
                _logger.LogDebug("Connecting to primary host.");
                _connection = _connectionFactory.CreateConnection(_config.Hostnames);
                _logger.LogInformation("Successfully established connection.");
            }
            catch (BrokerUnreachableException e)
            {
                _logger.LogError("Unable to connect to broker", e);
                throw e.InnerException;
            }
            _closeTimer = new System.Threading.Timer(state =>
            {
                var enumerator = _accessDictionary.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (DateTime.Now - enumerator.Current.Value > _config.RequestTimeout)
                    {
                        DateTime lastUsed;
                        if (_accessDictionary.TryRemove(enumerator.Current.Key, out lastUsed))
                        {
                            _logger.LogInformation($"Channel {enumerator.Current.Key.ChannelNumber} was last used {lastUsed}. Closing...");
                            enumerator.Current.Key.Close();
                        }
                    }
                }
            }, null, _config.RequestTimeout, _config.RequestTimeout);
        }
开发者ID:Originalutter,项目名称:RawRabbit,代码行数:35,代码来源:ChannelFactory.cs

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

示例8: TryCreateConnectionFactory

        protected void TryCreateConnectionFactory(object stateInfo)
        {
            if (Connection != null) Connection.Dispose();
            Connection = null;

            if (stateInfo != null)
            {
                Log.Information("Retrying connection");
                var autoEvent = (AutoResetEvent)stateInfo;
                autoEvent.Set();
            }
            var tempHostNames = hostNames;
            //hostNames.Shuffle();
            foreach (var hostName in tempHostNames)
            {
                try
                {
                    factory = new ConnectionFactory
                    {
                        HostName = hostName,
                        UserName = userName,
                        Password = password,
                        NetworkRecoveryInterval = TimeSpan.FromMilliseconds(timeout),
                        AutomaticRecoveryEnabled = automaticRecoveryEnabled,
                        RequestedHeartbeat = (ushort) heartbeat,
                        RequestedConnectionTimeout = 60000
                    };
                    Connection = factory.CreateConnection();
                    Log.Information(
                        "Connection heartbeat is configured to {0} seconds,  and the connection has returned a value of {1} seconds",
                        heartbeat, Connection.Heartbeat);
                    Connection.ConnectionShutdown += connection_ConnectionShutdown;
                    WaitingToConnect = false;
                    break;
                }
                catch (SocketException se)
                {
                    Log.Error(se, "RabbitMq: TryCreateConnectionFactory has an Error creating connection to host {0}",
                        hostName);
                }
                catch (BrokerUnreachableException be)
                {
                    Log.Error(be, "RabbitMq: TryCreateConnectionFactory Cannot reach broker for host {0}", hostName);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "RabbitMq: TryCreateConnectionFactory has an Error with {0} - {1}", hostName,
                        ex.Message);
                }
                finally
                {
                    if (Connection != null) Connection.Close();
                }
            }
            if (Connection == null) StartTryToConnect();
        }
开发者ID:jhonner72,项目名称:plat,代码行数:56,代码来源:RabbitMqBase.cs

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

示例10: Configure

        /// <summary>
        /// Configurate the Connection
        /// </summary>
        /// <param name="destination">Destionation</param>
        private void Configure(string destination)
        {
            Destination dest = new Destination(destination);

            Uri connectionUri = new Uri(dest.Host);
            factory = new Apache.NMS.ActiveMQ.ConnectionFactory(connectionUri);
            connection = factory.CreateConnection();
            session = connection.CreateSession();
            connection.Start();
            this.destination = session.GetDestination(dest.Queue);
        }
开发者ID:Mercynary,项目名称:loom-csharp,代码行数:15,代码来源:JMSPort.cs

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

示例12: Configure

        private void Configure(string destination)
        {
            Destination dest = new Destination(destination);

            Uri connectionUri = new Uri(dest.Host);
            _factory = new NMSConnectionFactory(connectionUri);
            _connection = _factory.CreateConnection();
            _session = _connection.CreateSession();
            _connection.Start();
            _destination = _session.GetDestination(dest.Queue);
        }
开发者ID:frenzqse,项目名称:loom-csharp-visualstudio,代码行数:11,代码来源:JMSPort.cs

示例13: SetUp

        public void SetUp()
        {
            connectionFactory = new ConnectionFactory(BROKER, CLIENT_ID);
            connection = connectionFactory.CreateConnection();
            connection.Start();
            session = connection.CreateSession();

            subscriber = new TopicSubscriber(session, TOPIC_NAME);
            subscriber.Start(CONSUMER_ID);
            subscriber.OnMessageReceived +=
                message => Console.WriteLine("Recieving message=>{0}", message);
        }
开发者ID:samwa,项目名称:mremoted,代码行数:12,代码来源:NMSTopicTests.cs

示例14: SingleNodeBroker

 public SingleNodeBroker(BrokerConfiguration config = null)
 {
     config = config ?? BrokerConfiguration.Local;
     _factory = new ConnectionFactory
     {
         HostName = config.Hostname,
         VirtualHost = config.VirtualHost,
         Password = config.Password,
         UserName = config.Username
     };
     _connection = _factory.CreateConnection();
 }
开发者ID:enrique-avalon,项目名称:RawRabbit,代码行数:12,代码来源:SingleNodeBroker.cs

示例15: Connect

 public void Connect()
 {
     log.Debug("New physical producer created. About to connect.");
     factory = XmsUtilities.CreateConnectionFactory(address);
     connection = factory.CreateConnection();
     connection.ExceptionListener += OnError;
     session = connection.CreateSession(transactional, AcknowledgeMode.AutoAcknowledge);
     queue = session.CreateQueue(address.Queue);
     queue.SetIntProperty(XMSC.DELIVERY_MODE, XMSC.DELIVERY_PERSISTENT);
     producer = session.CreateProducer(queue);
     connected = true;
     log.Debug("New physical producer successfully connected.");
 }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.3,代码行数:13,代码来源:XmsProducer.cs


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