本文整理匯總了C#中BrokeredMessage.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# BrokeredMessage.Dispose方法的具體用法?C# BrokeredMessage.Dispose怎麽用?C# BrokeredMessage.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BrokeredMessage
的用法示例。
在下文中一共展示了BrokeredMessage.Dispose方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendMessage
public JsonResult SendMessage(string topicName, string message, bool messageIsUrgent, bool messageIsImportant)
{
TopicClient topicClient = this.messagingFactory.CreateTopicClient(topicName);
var customMessage = new CustomMessage() { Body = message, Date = DateTime.Now };
bool success = false;
BrokeredMessage bm = null;
try
{
bm = new BrokeredMessage(customMessage);
bm.Properties["Urgent"] = messageIsUrgent ? "1" : "0";
bm.Properties["Important"] = messageIsImportant ? "1" : "0";
bm.Properties["Priority"] = "Low";
topicClient.Send(bm);
success = true;
}
catch (Exception)
{
// TODO: do something
}
finally
{
if (bm != null)
{
bm.Dispose();
}
}
return this.Json(success, JsonRequestBehavior.AllowGet);
}
示例2: SendMessage
public JsonResult SendMessage(string queueName, string message)
{
QueueClient queueClient = this.messagingFactory.CreateQueueClient(queueName);
var customMessage = new CustomMessage() { Date = DateTime.Now, Body = message };
long? messagesInQueue = null;
BrokeredMessage bm = null;
try
{
bm = new BrokeredMessage(customMessage);
bm.Properties["Urgent"] = "1";
bm.Properties["Priority"] = "High";
queueClient.Send(bm);
messagesInQueue = this.GetMessageCount(queueName);
}
catch
{
// TODO: do something
}
finally
{
if (bm != null)
{
bm.Dispose();
}
}
return this.Json(messagesInQueue, JsonRequestBehavior.AllowGet);
}
示例3: SendMessage
public void SendMessage(string queueName, string messageBody)
{
QueueClient queueClient = this.messagingFactory.CreateQueueClient(queueName);
var customMessage = new CustomMessage() { Date = DateTime.Now, Body = messageBody };
BrokeredMessage bm = null;
try
{
bm = new BrokeredMessage(customMessage);
bm.Properties["Urgent"] = "1";
bm.Properties["Priority"] = "High";
queueClient.Send(bm);
}
catch
{
// TODO: do something
}
finally
{
if (bm != null)
{
bm.Dispose();
}
}
}
示例4: SendMessage
public void SendMessage(string topicName, string messageBody, bool isUrgent, bool isImportant)
{
TopicClient topicClient = this.messagingFactory.CreateTopicClient(topicName);
var customMessage = new CustomMessage() { Body = messageBody, Date = DateTime.Now };
var bm = new BrokeredMessage(customMessage);
bm.Properties["Urgent"] = isUrgent ? "1" : "0";
bm.Properties["Important"] = isImportant ? "1" : "0";
// Force message priority to "Low". Subscription filters will change the value automatically if applies
bm.Properties["Priority"] = "Low";
topicClient.Send(bm);
if (bm != null)
{
bm.Dispose();
}
}
示例5: SendMessage
public void SendMessage(string queueName, string messageBody, bool isUrgent, bool isFollowUp)
{
MessageSender sender = this.messagingFactory.CreateMessageSender(queueName);
var customMessage = new CustomMessage() { Date = DateTime.Now, Body = messageBody };
BrokeredMessage bm = null;
try
{
bm = new BrokeredMessage(customMessage.ToDictinary());
bm.Properties["Urgent"] = "1";
bm.Properties["Priority"] = "High";
sender.Send(bm);
}
catch
{
}
finally
{
if (bm != null)
{
bm.Dispose();
}
}
}
示例6: SendMessage
/// <summary>
/// This method can be used to send a message to a queue or a topic.
/// </summary>
/// <param name="messageSender">A MessageSender object used to send messages.</param>
/// <param name="message">The message to send.</param>
/// <param name="taskId">The sender task id.</param>
/// <param name="isBinary">Indicates if the body is binary or not.</param>
/// <param name="useWcf">Indicates whether to send messages to a WCF receiver.</param>
/// <param name="logging">Indicates whether logging of message content and properties is enabled.</param>
/// <param name="verbose">Indicates whether verbose logging is enabled.</param>
/// <param name="elapsedMilliseconds">The time spent to send the message.</param>
public void SendMessage(MessageSender messageSender,
BrokeredMessage message,
int taskId,
bool isBinary,
bool useWcf,
bool logging,
bool verbose,
out long elapsedMilliseconds)
{
if (messageSender == null)
{
throw new ArgumentNullException(MessageSenderCannotBeNull);
}
if (message == null)
{
throw new ArgumentNullException(BrokeredMessageCannotBeNull);
}
var stopwatch = new Stopwatch();
try
{
Stream bodyStream = null;
if (logging && verbose)
{
bodyStream = message.Clone().GetBodyStream();
}
var builder = new StringBuilder();
try
{
stopwatch.Start();
messageSender.Send(message);
}
finally
{
stopwatch.Stop();
}
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
if (logging)
{
builder.AppendLine(string.Format(CultureInfo.CurrentCulture, MessageSuccessfullySent,
taskId,
string.IsNullOrWhiteSpace(message.MessageId) ? NullValue : message.MessageId,
string.IsNullOrWhiteSpace(message.SessionId) ? NullValue : message.SessionId,
string.IsNullOrWhiteSpace(message.Label) ? NullValue : message.Label,
message.Size));
if (verbose)
{
builder.AppendLine(SentMessagePayloadHeader);
var messageText = GetMessageText(bodyStream, isBinary);
if (useWcf)
{
messageText = XmlHelper.Indent(messageText);
}
builder.AppendLine(string.Format(MessageTextFormat, messageText.Contains('\n') ? messageText : messageText.Substring(0, Math.Min(messageText.Length, 128)) + (messageText.Length >= 128 ? "..." : "")));
if (message.Properties.Any())
{
builder.AppendLine(SentMessagePropertiesHeader);
foreach (var p in message.Properties)
{
builder.AppendLine(string.Format(MessagePropertyFormat,
p.Key,
p.Value));
}
}
}
var traceMessage = builder.ToString();
WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
}
}
finally
{
message.Dispose();
}
}
示例7: DoBeginSendMessage
protected virtual void DoBeginSendMessage(BrokeredMessage message, AsyncCallback ac)
{
try
{
this.topicClient.BeginSend(message, ac, message);
}
catch
{
message.Dispose();
throw;
}
}
示例8: ReleaseMessage
private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
{
switch (releaseAction.Kind)
{
case MessageReleaseActionKind.Complete:
msg.SafeCompleteAsync(
this.subscription,
success =>
{
msg.Dispose();
this.instrumentation.MessageCompleted(success);
if (success)
{
this.dynamicThrottling.NotifyWorkCompleted();
}
else
{
this.dynamicThrottling.NotifyWorkCompletedWithError();
}
},
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
case MessageReleaseActionKind.Abandon:
msg.SafeAbandonAsync(
this.subscription,
success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
case MessageReleaseActionKind.DeadLetter:
msg.SafeDeadLetterAsync(
this.subscription,
releaseAction.DeadLetterReason,
releaseAction.DeadLetterDescription,
success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
default:
break;
}
}
示例9: ProcessMessageAsync
internal async Task ProcessMessageAsync(BrokeredMessage message, CancellationToken cancellationToken)
{
if (message == null)
{
Trace.TraceWarning("ProcessMessageAsync was called with a null BrokeredMessage");
return;
}
if (cancellationToken.IsCancellationRequested == false)
{
Trace.TraceInformation("Receiving BrokeredMessage with Correlation Id {0}", message.CorrelationId);
try
{
// Do actual processing of the message
var topicMessage = message.GetBody<TopicMessageModel>();
var context = GlobalHost.ConnectionManager.GetHubContext<MessageHub>();
context.Clients.All.addMessage(topicMessage.Sender, topicMessage.Message, topicMessage.Disco);
Trace.TraceInformation("Processing message for {0}, sent by {1}, disco? {2}", topicMessage.Message, topicMessage.Sender, topicMessage.Disco);
// Complete the message
await message.CompleteAsync();
}
catch (MessageLockLostException e)
{
Trace.TraceError("Completing a BrokeredMessage in ProcessMessageAsync throw a MessageLockLostException");
}
catch (MessagingException e)
{
Trace.TraceError("Completing a BrokeredMessage in ProcessMessageAsync throw a MessagingException");
}
catch (Exception e)
{
Trace.TraceError("An exception occured while trying to process a deployment request message");
}
message.Dispose();
}
}
示例10: SendMessage
/// <summary>
/// This method can be used to send a message to a queue or a topic.
/// </summary>
/// <param name="messageSender">A MessageSender object used to send messages.</param>
/// <param name="outboundMessage">The message to send.</param>
/// <param name="messageText">The message text.</param>
/// <param name="taskId">The sender task id.</param>
/// <param name="useWcf">Indicates whether to send messages to a WCF receiver.</param>
/// <param name="logging">Indicates whether logging of message content and properties is enabled.</param>
/// <param name="verbose">Indicates whether verbose logging is enabled.</param>
/// <param name="elapsedMilliseconds">The time spent to send the message.</param>
public void SendMessage(MessageSender messageSender,
BrokeredMessage outboundMessage,
string messageText,
int taskId,
bool useWcf,
bool logging,
bool verbose,
out long elapsedMilliseconds)
{
if (messageSender == null)
{
throw new ArgumentNullException(MessageSenderCannotBeNull);
}
if (outboundMessage == null)
{
throw new ArgumentNullException(BrokeredMessageCannotBeNull);
}
var stopwatch = new Stopwatch();
try
{
var builder = new StringBuilder();
try
{
stopwatch.Start();
messageSender.Send(outboundMessage);
}
finally
{
stopwatch.Stop();
}
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
if (logging)
{
builder.AppendLine(string.Format(CultureInfo.CurrentCulture, MessageSuccessfullySent,
taskId,
string.IsNullOrEmpty(outboundMessage.MessageId) ? NullValue : outboundMessage.MessageId,
string.IsNullOrEmpty(outboundMessage.SessionId) ? NullValue : outboundMessage.SessionId,
string.IsNullOrEmpty(outboundMessage.Label) ? NullValue : outboundMessage.Label,
outboundMessage.Size));
if (verbose)
{
builder.AppendLine(SentMessagePayloadHeader);
if (useWcf)
{
var stringBuilder = new StringBuilder();
using (var reader = XmlReader.Create(new StringReader(messageText)))
{
// The XmlWriter is used just to indent the XML message
var settings = new XmlWriterSettings { Indent = true };
using (var writer = XmlWriter.Create(stringBuilder, settings))
{
writer.WriteNode(reader, true);
}
}
messageText = stringBuilder.ToString();
}
builder.AppendLine(string.Format(MessageTextFormat, messageText));
builder.AppendLine(SentMessagePropertiesHeader);
foreach (var p in outboundMessage.Properties)
{
builder.AppendLine(string.Format(MessagePropertyFormat,
p.Key,
p.Value));
}
}
var traceMessage = builder.ToString();
WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
}
}
finally
{
outboundMessage.Dispose();
}
}
示例11: ReleaseMessage
private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, Action completeReceive, Action onReleaseError, CountdownEvent countdown, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
{
switch (releaseAction.Kind)
{
case MessageReleaseActionKind.Complete:
msg.SafeCompleteAsync(
this.subscription,
operationSucceeded =>
{
msg.Dispose();
this.OnMessageCompleted(operationSucceeded, countdown);
if (operationSucceeded)
{
completeReceive();
}
else
{
onReleaseError();
}
},
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
case MessageReleaseActionKind.Abandon:
this.dynamicThrottling.Penalize();
msg.SafeAbandonAsync(
this.subscription,
operationSucceeded =>
{
msg.Dispose();
this.OnMessageCompleted(false, countdown);
onReleaseError();
},
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
case MessageReleaseActionKind.DeadLetter:
this.dynamicThrottling.Penalize();
msg.SafeDeadLetterAsync(
this.subscription,
releaseAction.DeadLetterReason,
releaseAction.DeadLetterDescription,
operationSucceeded =>
{
msg.Dispose();
this.OnMessageCompleted(false, countdown);
if (operationSucceeded)
{
completeReceive();
}
else
{
onReleaseError();
}
},
processingElapsedMilliseconds,
schedulingElapsedMilliseconds,
roundtripStopwatch);
break;
default:
break;
}
}