本文整理汇总了C#中ConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory类的具体用法?C# ConnectionFactory怎么用?C# ConnectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionFactory类属于命名空间,在下文中一共展示了ConnectionFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UnitOfWork
public UnitOfWork(string nameOrConnectionString)
{
var connectionFactory = new ConnectionFactory(nameOrConnectionString);
_connection = connectionFactory.Create();
_connection.Open();
_transaction = _connection.BeginTransaction();
}
开发者ID:Manikandhar,项目名称:AspNetIdentityRepPatt,代码行数:7,代码来源:UnitOfWork.cs
示例3: Main
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using( var connection = factory.CreateConnection() )
using( var channel = connection.CreateModel() )
{
channel.QueueDeclare( queue: "task_queue", durable: true, exclusive: false, autoDelete: false, arguments: null );
channel.BasicQos( prefetchSize: 0, prefetchCount: 1, global: false );
var consumer = new QueueingBasicConsumer( channel );
channel.BasicConsume( queue: "task_queue", noAck: false, consumer: consumer );
Console.WriteLine( " [*] Waiting for messages. To exit press CTRL+C" );
while( true )
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString( body );
Console.WriteLine( " [x] Received {0}", message );
int dots = message.Split( '.' ).Length - 1;
Thread.Sleep( dots * 1000 );
Console.WriteLine( " [x] Done" );
channel.BasicAck( deliveryTag: ea.DeliveryTag, multiple: false );
}
}
}
开发者ID:zhaoshiling1017,项目名称:rabbitmq-tutorials,代码行数:30,代码来源:Worker.cs
示例4: Main
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
channel.ExchangeDeclare(exchange: "logs", type: "fanout");
var queueName = channel.QueueDeclare().QueueName;
channel.QueueBind(queue: queueName, exchange: "logs", routingKey: "");
Console.WriteLine(" [*] Waiting for logs.");
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] {0}", message);
};
channel.BasicConsume(queue: queueName, noAck: true, consumer: consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
开发者ID:Fortiz2305,项目名称:rabbitmq-tutorials,代码行数:26,代码来源:ReceiveLogs.cs
示例5: GetProviderFromConfigName
public static IGroupDataProvider GetProviderFromConfigName(ILog log, IConfig groupsConfig, string configName)
{
switch (configName)
{
case "XmlRpc":
string ServiceURL = groupsConfig.GetString("XmlRpcServiceURL");
bool DisableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", false);
string ServiceReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", String.Empty);
string ServiceWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", String.Empty);
log.InfoFormat("[GROUPS]: XmlRpc Service URL set to: {0}", ServiceURL);
return new XmlRpcGroupDataProvider(ServiceURL, DisableKeepAlive, ServiceReadKey, ServiceWriteKey);
case "Native":
string dbType = groupsConfig.GetString("NativeProviderDBType");
string connStr = groupsConfig.GetString("NativeProviderConnString");
ConnectionFactory connFactory = new ConnectionFactory(dbType, connStr);
return new NativeGroupDataProvider(connFactory);
}
return null;
}
开发者ID:kf6kjg,项目名称:halcyon,代码行数:27,代码来源:ProviderFactory.cs
示例6: 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
示例7: Main
public static void Main()
{
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "localhost";
using (IConnection connection = factory.CreateConnection())
using (IModel channel = connection.CreateModel()) {
channel.ExchangeDeclare("logs", "fanout");
string queue_name = channel.QueueDeclare();
channel.QueueBind(queue_name, "logs", "");
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queue_name, true, consumer);
Console.WriteLine(" [*] Waiting for logs." +
"To exit press CTRL+C");
while(true) {
BasicDeliverEventArgs ea =
(BasicDeliverEventArgs)consumer.Queue.Dequeue();
byte[] body = ea.Body;
string message = System.Text.Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] {0}", message);
}
}
}
开发者ID:ne0c0de,项目名称:rabbitmq-tutorials,代码行数:26,代码来源:ReceiveLogs.cs
示例8: TestThatHeartbeatWriterWithTLSEnabled
public void TestThatHeartbeatWriterWithTLSEnabled()
{
if (!LongRunningTestsEnabled())
{
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
return;
}
var cf = new ConnectionFactory()
{
RequestedHeartbeat = heartbeatTimeout,
AutomaticRecoveryEnabled = false
};
string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");
return;
}
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
Assert.IsNotNull(sslDir);
cf.Ssl.CertPath = sslDir + "/client/keycert.p12";
string p12Password = Environment.GetEnvironmentVariable("PASSWORD");
Assert.IsNotNull(p12Password, "missing PASSWORD env var");
cf.Ssl.CertPassphrase = p12Password;
cf.Ssl.Enabled = true;
RunSingleConnectionTest(cf);
}
开发者ID:hanxinimm,项目名称:rabbitmq-dotnet-client,代码行数:30,代码来源:TestHeartbeats.cs
示例9: 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
示例10: 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
示例11: Main
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.ExchangeDeclare("logs", "fanout");
var queueName = channel.QueueDeclare();
channel.QueueBind(queueName, "logs", "");
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queueName, true, consumer);
Console.WriteLine(" [*] Waiting for logs." +
"To exit press CTRL+C");
while (true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] {0}", message);
}
}
}
}
开发者ID:harlan1,项目名称:rabbitmq-tutorials,代码行数:28,代码来源:ReceiveLogs.cs
示例12: Main
public static void Main()
{
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "127.0.0.1";
using (IConnection connection = factory.CreateConnection())
using (IModel channel = connection.CreateModel())
{
channel.QueueDeclare(QueueName, false, false, false, null);
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
bool autoAck = true;
channel.BasicConsume(QueueName, autoAck, consumer);
System.Console.WriteLine(" [*] Message List\n" +
"To exit press CTRL+C");
while (true)
{
BasicDeliverEventArgs ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
byte[] body = ea.Body;
string message = System.Text.Encoding.UTF8.GetString(body);
System.Console.WriteLine(" [x] Received {0}", message);
}
}
}
开发者ID:mplacona,项目名称:RabbitMQ-Integration,代码行数:26,代码来源:Monitor.cs
示例13: NewTask
public void NewTask()
{
string filepath = Utils.GetFullPathFileName("Chegou.png");
byte[] body = Utils.GetFileAsBytesOrNull (filepath);
var factory = new ConnectionFactory() { HostName = "diablo" };
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
//channel.QueueDeclare("Work_Queue"); // version shup
channel.QueueDeclare("Work_Queue",true,false,false,null);
var properties = channel.CreateBasicProperties();
properties.SetPersistent(true);
channel.BasicPublish(exchange: "",
routingKey: "Work_Queue",
basicProperties: properties,
body: body);
Text text ,log;
text = GameObject.Find("TextPE").GetComponent<Text>();
int count = int.Parse(text.text) + 1;
text.text= count.ToString();
log = GameObject.Find("console").GetComponent<Text>();
var fileInfo = new System.IO.FileInfo("Chegou.png");
var fileSize = (fileInfo.Length/1024f)/1024f;
log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] Mensagem Enviada Work Queue : " + fileSize.ToString("0.00") + " MB" + "\n";
connection.Close();
//Console.WriteLine(" [x] Sent {0}", message);
}
}
开发者ID:wgaalves,项目名称:unityRabbit,代码行数:31,代码来源:Workqueue.cs
示例14: Worker
public void Worker()
{
Text log = GameObject.Find("console").GetComponent<Text>();
var factory = new ConnectionFactory() { HostName = "diablo", UserName = "guest" ,Password = "guest"};
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
//var body = ea.Body;
//var message = Encoding.UTF8.GetString(body);
//Console.WriteLine(" [x] Received {0}", message);
/// int dots = message.Split('.').Length - 1;
//
Thread.Sleep(1000);
log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] recebendo mensagens. \n";
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
};
channel.BasicConsume(queue: "Work_Queue",
noAck: false,
consumer: consumer);
}
}
开发者ID:wgaalves,项目名称:unityRabbit,代码行数:29,代码来源:Workqueue.cs
示例15: 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
示例16: RabbitMqConnectionFactory
public RabbitMqConnectionFactory(ConnectionConfiguration connectionConfiguration)
{
if (connectionConfiguration == null)
{
throw new ArgumentNullException("connectionConfiguration");
}
if (connectionConfiguration.HostConfiguration == null)
{
throw new ArgumentException(
"The connectionConfiguration has a null HostConfiguration.", "connectionConfiguration");
}
Configuration = connectionConfiguration;
connectionFactory = new ConnectionFactory
{
HostName = connectionConfiguration.HostConfiguration.Host,
Port = connectionConfiguration.HostConfiguration.Port,
VirtualHost = Configuration.VirtualHost,
UserName = Configuration.UserName,
Password = Configuration.Password,
RequestedHeartbeat = Configuration.RequestedHeartbeat,
ClientProperties = Configuration.ClientProperties
};
}
开发者ID:MyDealerLot,项目名称:NServiceBus.RabbitMQ,代码行数:26,代码来源:RabbitMqConnectionFactory.cs
示例17: SendSimpleQueue
public void SendSimpleQueue()
{
string filepath = Utils.GetFullPathFileName("rabbit.ogg");
byte[] body = Utils.GetFileAsBytesOrNull (filepath);
var factory = new ConnectionFactory() { HostName = "diablo" ,UserName = "guest" ,Password = "guest" };
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
//channel.QueueDeclare("SimpleQueue"); //version shup
channel.QueueDeclare("SimpleQueue",true,false,false,null);
// string message = "Hello World!";
//var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: "SimpleQueue",
basicProperties: null,
body: body);
Text text ,log;
text = GameObject.Find("TextPE").GetComponent<Text>();
int count = int.Parse(text.text) + 1;
text.text= count.ToString();
log = GameObject.Find("console").GetComponent<Text>();
var fileInfo = new System.IO.FileInfo("rabbit.ogg");
var fileSize = (fileInfo.Length/1024f)/1024f;
log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] Mensagem Enviada SingleQueue : " + fileSize.ToString("0.00") + " MB" + "\n";
connection.Close();
}
}
开发者ID:wgaalves,项目名称:RabbitMQ-Unity,代码行数:32,代码来源:SingleQueue.cs
示例18: receivePSMessage
public void receivePSMessage()
{
Debug.Log("Start");
Text log = GameObject.Find("console").GetComponent<Text>();
log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] Aguardando mensagens.\n";
var factory = new ConnectionFactory() { HostName = "diablo", UserName = "guest", Password = "guest" };
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
if(uuid == ""){
setUuid("amq-" + Guid.NewGuid().ToString());
}
channel.ExchangeDeclare(exchange: "publishSubEX", type: "fanout");
var queueName = channel.QueueDeclare(uuid, false,false,false,null);
channel.QueueBind(queueName,"publishSubEX","");
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
Utils.SaveFileToDisk("rabbit.png",body);
var fileInfo = new System.IO.FileInfo("rabbit.png");
var fileSize = (fileInfo.Length/1024f)/1024f;
log.text = log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] Mensagem Enviada Publish / Subscribe : " + fileSize.ToString("0.00") + " MB" + "\n";
};
channel.BasicConsume(queue: queueName,
noAck: true,
consumer: consumer);
}
}
开发者ID:wgaalves,项目名称:unityRabbit,代码行数:30,代码来源:PSQueue.cs
示例19: SendPSMessage
public void SendPSMessage()
{
string filepath = Utils.GetFullPathFileName("Chegou.png");
byte[] messageBytes = Utils.GetFileAsBytesOrNull (filepath);
var factory = new ConnectionFactory() { HostName = "diablo" , UserName = "guest" , Password = "guest"};
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
channel.ExchangeDeclare(exchange: "publishSubEX", type: "fanout");
var body = messageBytes;
//var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "publishSubEX",
routingKey: "",
basicProperties: null,
body: body);
Text text ,log;
text = GameObject.Find("TextPE").GetComponent<Text>();
int count = int.Parse(text.text) + 1;
text.text= count.ToString();
log = GameObject.Find("console").GetComponent<Text>();
var fileInfo = new System.IO.FileInfo("Chegou.png");
var fileSize = (fileInfo.Length/1024f)/1024f;
log.text = log.text + "[ "+ DateTime.Now.ToString("HH:mm:ss") +" ] Mensagem Enviada Publish / Subscribe : " + fileSize.ToString("0.00") + " MB" + "\n";
}
}
开发者ID:wgaalves,项目名称:unityRabbit,代码行数:29,代码来源:PSQueue.cs
示例20: 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
注:本文中的ConnectionFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论