本文整理汇总了C#中IModel.BasicGet方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.BasicGet方法的具体用法?C# IModel.BasicGet怎么用?C# IModel.BasicGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.BasicGet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Exec
// ReSharper disable ConditionIsAlwaysTrueOrFalse
public static void Exec(bool durable, bool ack, IModel model, IConnection connection)
{
var queueName = "CSharpPublish" + (durable ? "Durable" : "NotDurable");
if (!string.IsNullOrWhiteSpace(_overrideQueueName))
queueName = _overrideQueueName;
Console.WriteLine("Durability {0} enabled", durable ? "IS" : "is NOT");
Console.WriteLine("ACK {0} enabled", ack ? "IS" : "is NOT");
Console.WriteLine("Creating queue {0}...", queueName);
model.QueueDeclare(queueName, durable, false, false, null);
var msg = Encoding.UTF8.GetBytes("Hello from my PC !");
var properties = new BasicProperties { DeliveryMode = (byte)(durable ? 2 : 1) };
if (_publish)
{
for (int i = 0; i < _numMsgs; i++)
model.BasicPublish(string.Empty, queueName, properties, msg);
Console.WriteLine("Published!");
}
uint msgs = 0;
if (_receive)
{
Console.WriteLine("Reading...");
var fromMac = false;
while (connection.IsOpen)
{
var result = model.BasicGet(queueName, ack == false);
if (result == null)
break;
if (msgs % 3144 == 0)
Console.WriteLine(msgs);
if (ack)
model.BasicAck(result.DeliveryTag, false);
var msgText = Encoding.UTF8.GetString(result.Body);
if (msgText.Contains("Mac"))
fromMac = true;
msgs++;
}
if (fromMac)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Received messages from the mac");
Console.ResetColor();
}
}
}
示例2: GetResult
private static void GetResult(string queueName, IModel model)
{
var result = model.BasicGet(queueName, false);
if (result == null)
{
Console.WriteLine("Nothing left!");
return;
}
var msg = result.Body.Deserialize<SomeMessage>().ToJson();
Console.WriteLine("Received {0}", msg);
Console.WriteLine("ACK'ing reciept of msg {0}", result.DeliveryTag);
model.BasicAck(result.DeliveryTag, false);
// Recursively get the other results
GetResult(queueName, model);
}
示例3: GetResult
private static void GetResult(string queueName, IModel model)
{
var result = model.BasicGet(queueName, false);
if (result == null)
{
Console.WriteLine("Nothing left!");
return;
}
var msg = Encoding.UTF8.GetString(result.Body);
Console.WriteLine("Received {0}", msg);
Console.WriteLine("ACK'ing reciept of msg {0}", result.DeliveryTag);
model.BasicAck(result.DeliveryTag, false);
// Recursively get the other results
GetResult(queueName, model);
}
示例4: _t_Elapsed
void _t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
var connectionFactory = new ConnectionFactory();
connection = connectionFactory.CreateConnection();
channel = connection.CreateModel();
channel.ExchangeDeclare("GIS", ExchangeType.Direct);
channel.QueueDeclare("GIS", false, false, false, null);
channel.QueueBind("GIS", "GIS", "PAUL");
BasicGetResult result = channel.BasicGet("GIS", true);
if (result != null)
{
msg = Encoding.UTF8.GetString(result.Body);
MessageBox.Show(msg, "You've Got a Message!");
//If set Message to send coords in form "35,-106" Next lines will draw points.
string[] coords = msg.Split(',');
float x = float.Parse(coords[0]);
float y = float.Parse(coords[1]);
Note fromRabbit = new Note("From RabbitMQ", new ESRI.ArcGISExplorer.Geometry.Point(y, x));
ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(fromRabbit);
}
}