本文整理汇总了C#中RabbitMQ.Client.ConnectionFactory.CreateModel方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.CreateModel方法的具体用法?C# ConnectionFactory.CreateModel怎么用?C# ConnectionFactory.CreateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RabbitMQ.Client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.CreateModel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var serverAddress = "192.168.0.196";
var queueName = "message_data_cs";
using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
{
using (var ch = conn.CreateModel())
{
ch.QueueDeclare(queueName, true);
var properties = ch.CreateBasicProperties();
properties.SetPersistent(true);
for (int i = 0; i < 10; i++)
{
var message = new Message()
{
From = "C# Sample",
Body = String.Format("Message No. {0}", i)
};
Console.WriteLine("Sending: {0}", i);
ch.BasicPublish("", queueName, properties, Message.Serialize(message));
}
}
}
}
示例2: WillCreateInputAndErrorQueue
public void WillCreateInputAndErrorQueue()
{
var testRabbitQueues = "test.rabbit.queues";
CreateBus(testRabbitQueues, new HandlerActivatorForTesting()).Start(1);
using (var connection = new ConnectionFactory {Uri = ConnectionString}.CreateConnection())
using (var model = connection.CreateModel())
{
Assert.DoesNotThrow(() => model.BasicGet(testRabbitQueues, true));
Assert.DoesNotThrow(() => model.BasicGet(testRabbitQueues + ".error", true));
}
}
示例3: DeleteQueue
public static void DeleteQueue(string queueName)
{
using (var connection = new ConnectionFactory {Uri = ConnectionString}.CreateConnection())
using (var model = connection.CreateModel())
{
// just ignore if it fails...
try
{
model.QueueDelete(queueName);
}
catch
{
}
}
}
示例4: Main
static void Main(string[] args)
{
var serverAddress = "192.168.0.196";
var queueName = "string_data";
using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
{
using (var ch = conn.CreateModel())
{
var messages = Enumerable.Range(1, 10).Select(x => String.Format("Hello from .NET! Message No. {0}", x));
foreach (var message in messages)
{
Console.WriteLine("Sending: {0}", message);
ch.BasicPublish("", queueName, null, Encoding.ASCII.GetBytes(message));
}
}
}
}
示例5: Main
static void Main(string[] args)
{
var serverAddress = @"192.168.0.196";
var queueName = "string_data";
var conn = new ConnectionFactory().CreateConnection(serverAddress);
using (var ch = conn.CreateModel())
{
conn.AutoClose = true;
ch.QueueDeclare(queueName);
BasicGetResult result = null;
while ((result = ch.BasicGet(queueName, false)) != null)
{
ch.BasicAck(result.DeliveryTag, false);
Console.WriteLine("Message: {0}", Encoding.ASCII.GetString(result.Body));
}
}
}
示例6: Main
static void Main(string[] args)
{
var serverAddress = @"192.168.0.196";
var queueName = "message_data_cs";
var conn = new ConnectionFactory().CreateConnection(serverAddress);
using (var ch = conn.CreateModel())
{
conn.AutoClose = true;
ch.QueueDeclare(queueName, true);
BasicGetResult result = null;
while ((result = ch.BasicGet(queueName, false)) != null)
{
ch.BasicAck(result.DeliveryTag, false);
var message = Message.Deserialize(result.Body);
Console.WriteLine(message.Text);
}
}
Console.ReadKey();
}
示例7: Main
static void Main(string[] args)
{
var serverAddress = "192.168.0.196";
var queueName = "string_data";
using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
{
using (var ch = conn.CreateModel())
{
ch.QueueDeclare(queueName, true);
var properties = ch.CreateBasicProperties();
properties.SetPersistent(true);
for (int i = 0; i < 10; i++)
{
var message = String.Format("Hello from .NET! Message No. {0}", i);
Console.WriteLine("Sending: {0}", message);
ch.BasicPublish("", queueName, (i % 2 == 1) ? properties : null, Encoding.ASCII.GetBytes(message));
}
}
}
}
示例8: TestRabbitMq
static void TestRabbitMq(int messageCount)
{
IConnection connection = new ConnectionFactory().CreateConnection();
var serializer = new BinarySerializationStrategy();
for (int i = 0; i < messageCount; i++)
{
IModel model = connection.CreateModel();
model.ExchangeDeclare("rabbitMQ.test.exchange", ExchangeType.Direct, false, true, null);
byte[] serializedMessage = serializer.Serialize(new TestMessage("test"));
model.BasicPublish("rabbitMQ.test.exchange", string.Empty, null, serializedMessage);
model.Close();
}
connection.Close();
}
示例9: QueueExists
bool QueueExists(string queueName)
{
using (var connection = new ConnectionFactory { Uri = ConnectionString }.CreateConnection())
{
using (var model = connection.CreateModel())
{
try
{
model.QueueDeclarePassive(queueName);
// if the call succeeds, then the queue exists
return true;
}
catch (OperationInterruptedException exception)
{
if (exception.Message.Contains("NOT_FOUND"))
{
return false;
}
throw;
}
}
}
}
示例10: RabbitTransportDoesNotChokeOnMessagesContainingComplexHeaders
public void RabbitTransportDoesNotChokeOnMessagesContainingComplexHeaders()
{
// arrange
const string recipientInputQueue = "test.roundtripping.receiver";
const string someText = "whoohaa!";
DeleteQueue(recipientInputQueue);
// ensure recipient queue is created...
using (var recipient = new RabbitMqMessageQueue(ConnectionString, recipientInputQueue))
{
// force creation of the queue
recipient.ReceiveMessage(new NoTransaction());
// act
// send a message with a complex header
using (var connection = new ConnectionFactory { Uri = ConnectionString }.CreateConnection())
using (var model = connection.CreateModel())
{
var props = model.CreateBasicProperties();
props.Headers = new Dictionary<string, object>
{
{
"someKey", new Hashtable
{
{"someContainedKey", "someContainedValue"},
{"anotherContainedKey", "anotherContainedValue"},
}
}
};
model.BasicPublish(recipient.ExchangeName,
recipientInputQueue,
props,
Encoding.GetBytes(someText));
}
Thread.Sleep(2.Seconds());
// assert
var receivedTransportMessage = recipient.ReceiveMessage(new NoTransaction());
receivedTransportMessage.ShouldNotBe(null);
Encoding.GetString(receivedTransportMessage.Body).ShouldBe(someText);
}
// assert
}