本文整理汇总了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();
}
示例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();
}
示例3: SetUp
public void SetUp()
{
connectionFactory = new ConnectionFactory("tcp://localhost:61616", GetType().Name);
connection = connectionFactory.CreateConnection();
connection.Start();
session = connection.CreateSession();
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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.");
}