本文整理汇总了C#中QueueClient.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# QueueClient.Receive方法的具体用法?C# QueueClient.Receive怎么用?C# QueueClient.Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueueClient
的用法示例。
在下文中一共展示了QueueClient.Receive方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
lstMensagens.Items.Add("status: Recebendo mensagens...");
this.Refresh();
queueClient = QueueClient.Create(QueueName);
BrokeredMessage message = null;
while (true)
{
try
{
message = queueClient.Receive(TimeSpan.FromSeconds(2));
if (message != null)
{
lstResultado.Items.Add(string.Format("Id: {0}, Body: {1}", message.MessageId, message.GetBody<string>()));
message.Complete();
}
else break;
}
catch (MessagingException error)
{
if (!error.IsTransient)
{
lstMensagens.Items.Add("status: " + error.Message);
}
else ManipularExcecoes(error);
}
}
queueClient.Close();
}
示例2: ReceivedMessage
public string ReceivedMessage()
{
var factory = MessagingFactory.CreateFromConnectionString(ConnectionString);
_client = factory.CreateQueueClient(ServiceProperties.QueueName);
var message = _client.Receive();
return message.GetBody<string>();
}
示例3: ReceiveNMessagesFromQueue
//Recebe messageCount mensagens da queue, com timeout de 5 segundos por mensagem.
//Imprimir na consola o id e o body de cada mensagem
static void ReceiveNMessagesFromQueue(QueueClient myQueueClient, long messageCount)
{
for (int i = 0; i < messageCount; i++)
{
var message = myQueueClient.Receive(new TimeSpan(0, 0, 5));
if (message != null)
{
Console.WriteLine("Message received. Id: {0} Body: {1}", message.MessageId, message.GetBody<string>());
}
}
}
示例4: ReturnMessageToSourceQueue
/// <summary>
/// May throw a timeout exception if a message with the given id cannot be found.
/// </summary>
/// <param name="seqNumber"></param>
public void ReturnMessageToSourceQueue(QueueClient queue, QueueClient deadLetterQueue, ServiceBusMQ.Model.QueueItem itm) {
//var rec = MessagingFactory.Create()
//rec.
BrokeredMessage message;
try {
message = deadLetterQueue.Receive((long)itm.MessageQueueItemId);
} catch(Exception e) {
message = queue.Receive((long)itm.MessageQueueItemId);
}
//message.Abandon();
queue.Send(message.Clone());
//} catch( Exception ex ) {
// TryFindMessage(itm);
//}
}
示例5: Main
static void Main(string[] args)
{
CreateQueue();
queueClient = QueueClient.Create(queueName, ReceiveMode.PeekLock);
Console.Out.WriteLine("Queue client receive mode is " + queueClient.Mode.ToString());
try
{
while (true)
{
long msgCount = nsMgr.GetQueue(queueName).MessageCountDetails.ActiveMessageCount;
Console.Out.WriteLine("Ready for messages... ");
if (msgCount > 0) { Console.Out.WriteLine("The queue has " + msgCount + " messages waiting"); }
var msg = queueClient.Receive(new TimeSpan(1, 0, 0));
Console.Out.WriteLine("Received message with id {0}", msg.MessageId);
Messages.Greeting greeting = msg.GetBody<Messages.Greeting>();
Console.Out.WriteLine("Message for: {0}", greeting.Name );
Console.Out.WriteLine("{0}\n", greeting.Message);
if (queueClient.Mode == ReceiveMode.PeekLock)
{
try
{
Console.Out.WriteLine("Completing message with lock token {0}", msg.LockToken);
queueClient.Complete(msg.LockToken);
}
catch (MessageLockLostException)
{
Console.Out.WriteLine("Oh noes! We lost the lock on the message. ");
}
}
Console.Out.WriteLine();
}
}
finally
{
queueClient.Close();
}
}
示例6: ReturnMessageToSourceQueue
/// <summary>
/// May throw a timeout exception if a message with the given id cannot be found.
/// </summary>
/// <param name="seqNumber"></param>
public void ReturnMessageToSourceQueue(QueueClient queue, QueueClient deadLetterQueue, ServiceBusMQ.Model.QueueItem itm)
{
try {
var message = deadLetterQueue.Receive((long)itm.MessageQueueItemId);
message.Abandon();
//queue.Send(message.Clone());
} catch( Exception ex ) {
TryFindMessage(itm);
}
}
示例7: Receive
//TODO: move to ServivceBus class
public static void Receive(QueueClient client)
{
try
{
Trace.TraceInformation("1. Pull messages off of queue");
client.Receive();
}
catch (Exception ex)
{
Trace.TraceError("On retrieving message from queue. Client.Receive() before while loop starts. " + ex.Message);
}
bool messageFound = true;
BrokeredMessage message = null;
// Continuously process messages on the queue
while (messageFound)
{
try
{
Trace.TraceInformation("2. Pull messages off of queue");
message = client.Receive();
}
catch (Exception ex)
{
Trace.TraceError("On retrieving message from queue. Client.Receive() inside while loop. " + ex.Message);
}
DateTime? dateCreated = null;
var region = string.Empty;
var messageId = string.Empty;
if (message != null)
{
try
{
//Trace.TraceInformation("Body: " + message.GetBody<string>());
//Trace.TraceInformation("MessageID: " + message.MessageId);
//Trace.TraceInformation("Region Code: " +
// message.Properties["RegionCode"]);
//Trace.TraceInformation("Date Created: " +
// message.Properties["DateCreated"]);
dateCreated = Convert.ToDateTime(message.Properties["DateCreated"]);
region = message.Properties["RegionCode"].ToString();
messageId = message.MessageId;
}
catch (Exception ex)
{
// Indicate a problem, unlock message in queue
message.Abandon();
Trace.TraceError("On CreateAndSendMessage: " + ex.Message);
}
// Remove message from queue
if (dateCreated == null || region == string.Empty)
{
message.Abandon();
Trace.TraceWarning("Message abandoned: where date created is " + dateCreated + " and where region is " + region);
continue;
}
Trace.TraceInformation("3. Message Found");
message.Complete();
Trace.TraceInformation("4. Message marked as complete. Reading from Azure table storage is next...");
var dataSourceAzureTable = new DataSource.AzureTable();
dataSourceAzureTable.GetRows(messageId,region, dateCreated);
}
else
{
Trace.TraceInformation("2.5 No message found on queue and no error reported.");
messageFound = false;
}
}
}
示例8: Main
static void Main(string[] args)
{
Console.CancelKeyPress += Console_CancelKeyPress;
if(args.Length > 0)
{
PrintUsage();
}
if(!Directory.Exists(s_DownloadRootFolder))
{
Directory.CreateDirectory(s_DownloadRootFolder);
}
//Get Service Bus
var queueConnectionString =
CloudConfigurationManager.GetSetting("Uploader.ServiceBus.ConnectionString");
var queueName = CloudConfigurationManager.GetSetting("Uploader.UploadQueueName");
s_QueueClient = QueueClient.CreateFromConnectionString(queueConnectionString, queueName, ReceiveMode.ReceiveAndDelete);
CloudBlobClient blobClient = s_Account.CreateCloudBlobClient();
while (true)
{
try
{
var message = s_QueueClient.Receive();
//no new messages go back and wait again for more
if(message == null)
{
continue;
}
FileUploadedMessage etlUploadedMessage = JsonConvert.DeserializeObject<FileUploadedMessage>(message.GetBody<string>());
Console.WriteLine("Got uploaded file notification for " + etlUploadedMessage.FileName);
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(etlUploadedMessage.ContainerName.ToLower());
var blockBlob = container.GetBlockBlobReference(etlUploadedMessage.FileName);
var localFilePath = Path.Combine(s_DownloadRootFolder, etlUploadedMessage.ContainerName.ToLower());
var filePath = etlUploadedMessage.FileName.Replace("/", "\\");
localFilePath = Path.Combine(localFilePath, filePath);
if (!Directory.Exists(Path.GetDirectoryName(localFilePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(localFilePath));
}
if (File.Exists(localFilePath))
{
File.Delete(localFilePath);
}
//Get the file
using (Stream cloudStoredBits = blockBlob.OpenRead())
using (FileStream fs = new FileStream(localFilePath, FileMode.CreateNew, FileAccess.ReadWrite))
{
Console.WriteLine("Downloading Cloud file [" + etlUploadedMessage.ContainerName + "]" + etlUploadedMessage.FileName
+ " to " + localFilePath);
cloudStoredBits.CopyTo(fs);
}
//Delete it from blob storage. Cloud storage isn't cheap :-)
Console.WriteLine("Deleting Cloud file [" + etlUploadedMessage.ContainerName + "]" + etlUploadedMessage.FileName);
blockBlob.Delete(DeleteSnapshotsOption.IncludeSnapshots);
}
catch(Exception e)
{
Console.WriteLine("Unexpected Exception occured. See this exception - " + e);
}
}
}