本文整理汇总了C#中BrokeredMessage类的典型用法代码示例。如果您正苦于以下问题:C# BrokeredMessage类的具体用法?C# BrokeredMessage怎么用?C# BrokeredMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BrokeredMessage类属于命名空间,在下文中一共展示了BrokeredMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AddToAzureQueue
public static void AddToAzureQueue(this object o, string queueName, string nameSpace, string issuerName, string issuerKey)
{
if (_queueClient == null || queueName.ToLower() != _queueName || nameSpace.ToLower() != _nameSpace || issuerName.ToLower() != _issuerName || issuerKey.ToLower() != _issuerKey)
{
_queueName = queueName.ToLower();
_nameSpace = nameSpace.ToLower();
_issuerName = issuerName.ToLower();
_issuerKey = issuerKey.ToLower();
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue;
System.Net.ServicePointManager.Expect100Continue = false;
System.Net.ServicePointManager.UseNagleAlgorithm = false;
var credentials = GetToken(issuerName, issuerKey);
// Get a client to the queue
var messagingFactory = MessagingFactory.Create(GetAddress(nameSpace), credentials);
_queueClient = messagingFactory.CreateQueueClient(queueName);
}
BrokeredMessage message = new BrokeredMessage(o);
_queueClient.Send(message);
}
示例3: Send
/// <summary>
/// Save Message to Queue
/// </summary>
/// <param name="message">Message</param>
/// <returns>Task</returns>
public async Task Send(BrokeredMessage message)
{
if (null == message)
{
throw new ArgumentNullException("message");
}
while (true)
{
try
{
await this.client.Send(message);
break;
}
catch (MessagingException ex)
{
if (ex.IsTransient)
{
this.HandleTransientError(ex);
}
else
{
Trace.TraceError("Error: '{0}'", ex.ToString());
throw;
}
}
}
}
示例4: OnBrokerMessage
private void OnBrokerMessage(BrokeredMessage brokeredMessage)
{
try
{
//Ignore messages from self
if (brokeredMessage.Properties[SidAttributeName].ToString() == _sid)
{
brokeredMessage.Complete();
return;
}
var json = brokeredMessage.Properties[DataAttributeName].ToString();
var message = _jsonSerializer.DeserializeFromString<Message>(json);
var pipeline = Composable.GetExport<IXSocketPipeline>();
var controller = Composable.GetExports<IXSocketController>().First(p => p.Alias == message.Controller);
controller.ProtocolInstance = new XSocketInternalProtocol();
pipeline.OnIncomingMessage(controller, message);
brokeredMessage.Complete();
}
catch (Exception ex)
{
Composable.GetExport<IXLogger>().Error(ex.ToString());
// Indicates a problem
if (brokeredMessage.DeliveryCount > 3)
{
brokeredMessage.DeadLetter();
}
else
{
brokeredMessage.Abandon();
}
}
}
示例5: BuildMessage
/// <summary>
/// Convert the brokered message to an envelope.
/// </summary>
/// <param name="brokeredMessage"></param>
/// <returns></returns>
public async Task<IEnvelope<IMessage>> BuildMessage(BrokeredMessage brokeredMessage)
{
using (var stream = brokeredMessage.GetBody<Stream>())
using (var ms = new MemoryStream())
{
var messageType = brokeredMessage.ContentType;
// Log.
MessagingEventSource.Log.DeserializingMessage(messageType, brokeredMessage.MessageId, brokeredMessage.CorrelationId, brokeredMessage.SessionId);
// Helps us get access to the byte array.
await stream.CopyToAsync(ms);
// Build the envelope.
var envelope = Envelope.Create<IMessage>(null)
.CorrelationId(brokeredMessage.CorrelationId)
.SessionId(brokeredMessage.SessionId)
.TimeToLive(brokeredMessage.TimeToLive)
.Properties(brokeredMessage.Properties);
// Handle interceptors, then deserialize.
var serializedMessage = await Configuration.MessageFilterInvoker.BeforeDeserialization(envelope, ms.ToArray());
var message = await Configuration.Serializer.Deserialize<IMessage>(serializedMessage);
// Log.
MessagingEventSource.Log.DeserializationComplete(messageType, brokeredMessage.MessageId, brokeredMessage.CorrelationId, brokeredMessage.SessionId);
// Done.
return envelope.Body(message);
}
}
示例6: BuildMessage
private BrokeredMessage BuildMessage(Envelope<ICommand> command)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
this.serializer.Serialize(writer, command.Body);
stream.Position = 0;
var message = new BrokeredMessage(stream, true);
if (!default(Guid).Equals(command.Body.Id))
{
message.MessageId = command.Body.Id.ToString();
}
var metadata = this.metadataProvider.GetMetadata(command.Body);
if (metadata != null)
{
foreach (var pair in metadata)
{
message.Properties[pair.Key] = pair.Value;
}
}
if (command.Delay != TimeSpan.Zero)
message.ScheduledEnqueueTimeUtc = DateTime.UtcNow.Add(command.Delay);
return message;
}
示例7: PumpMessage
protected override void PumpMessage(BrokeredMessage message)
{
var correlationId = Guid.Parse(message.CorrelationId);
var responseCorrelationWrapper = _requestResponseCorrelator.TryGetWrapper(correlationId);
if (responseCorrelationWrapper == null)
{
Logger.Debug("Could not find correlation wrapper for reply {0} ({1}", correlationId, message.Properties[MessagePropertyKeys.MessageType]);
return;
}
var success = (bool) message.Properties[MessagePropertyKeys.RequestSuccessfulKey];
if (success)
{
Logger.Debug("Request {0} was successful. Dispatching reply to correlation wrapper.", correlationId);
var responseType = responseCorrelationWrapper.ResponseType;
var response = message.GetBody(responseType);
responseCorrelationWrapper.Reply(response);
Logger.Debug("Response {0} dispatched.", correlationId);
}
else
{
var exceptionMessage = (string) message.Properties[MessagePropertyKeys.ExceptionMessageKey];
var exceptionStackTrace = (string) message.Properties[MessagePropertyKeys.ExceptionStackTraceKey];
Logger.Debug("Request {0} failed. Dispatching exception to correlation wrapper: {1} {2}", correlationId, exceptionMessage, exceptionStackTrace);
responseCorrelationWrapper.Throw(exceptionMessage, exceptionStackTrace);
}
}
示例8: SendMessage
private static void SendMessage(string name, string message)
{
Greeting g = new Greeting() { Name = name, Message = message };
while(true){
try
{
BrokeredMessage bmsg = new BrokeredMessage(g);
queueClient.Send(bmsg);
Console.Out.WriteLine("Sent message with id {0}", bmsg.MessageId);
break;
}
catch (MessagingException mex)
{
if (!mex.IsTransient)
{
throw;
}
else
{
Console.Out.WriteLine("We experienced a temporary setback due to {0}", mex.Message);
Console.Out.WriteLine("Retrying in 2 seconds.");
Thread.Sleep(2000);
}
}
}
}
示例9: Enqueue
public async Task Enqueue(object message)
{
var brokeredMessage = new BrokeredMessage(message);
var topicClient = QueueClient.CreateFromConnectionString(_serviceBusNamespaceConnectionString, QueueName);
await topicClient.SendAsync(brokeredMessage);
}
开发者ID:kkrzaczkowski-fp,项目名称:AzureConstructionsProgressTracker-AzureWorkshopFP,代码行数:7,代码来源:ServiceBusManager.cs
示例10: SendSBM
public void SendSBM(string msg, string channel)
{
message = new BrokeredMessage(msg);
message.Properties["channel"] = channel;
message.TimeToLive = timetolive;
client.Send(message);
}
示例11: When
protected override async Task When()
{
_request = new BrokeredMessage();
_sessionId = Guid.NewGuid().ToString();
_request.ReplyToSessionId = _sessionId;
_response = await Subject.CreateSuccessfulResponse(new TestResponse(), _request);
}
开发者ID:AtmosphereMessaging,项目名称:Cumulus,代码行数:7,代码来源:WhenCreatingASuccesfulResponseToARequestWithReplyToSessionIdSet.cs
示例12: CreateInstance
/// <summary>
/// Create a new session handler.
/// </summary>
/// <param name="session"></param>
/// <param name="message"></param>
/// <returns></returns>
public IMessageSessionAsyncHandler CreateInstance(MessageSession session, BrokeredMessage message)
{
ServiceBusEventSource.Log.SessonAccepted(_receiverNamespace, _receiverPath, session.SessionId, message.MessageId, message.CorrelationId);
// Use the current handler.
return new SessionMessageAsyncHandler(_receiverNamespace, _receiverPath, session, _messageHandler, _options);
}
示例13: Main
static void Main(string[] args)
{
try
{
//ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
string topicName = "sb-salesorder-topic";
string sbconnection = "Endpoint=sb://sb-twocents-ns.servicebus.windows.net/;SharedAccessKeyName=Sender;SharedAccessKey=TzYnAEaXHAP3dVJ0J/knLc+2+99C/E2ytbo8qDJQ+TI=";
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(sbconnection);
TopicClient client = factory.CreateTopicClient(topicName);
string postBody = "{'ServiceNumber': 'TST100', 'AddressCode': 'HAG', 'ServiceContractNumber': 'SOC920001', Description': 'Testmelding'}";
BrokeredMessage msg = new BrokeredMessage(postBody);
msg.Properties["Priority"] = 1;
client.Send(msg);
msg = null;
Console.WriteLine("Press Enter");
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine(String.Format("Error: {0}", ex.ToString()));
Console.Read();
}
}
示例14: Main
static void Main(string[] args)
{
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
NamespaceManager ConnectorNamespaceMgr = NamespaceManager.CreateFromConnectionString(connectionString);
if (!ConnectorNamespaceMgr.QueueExists("TestQueue"))
{
ConnectorNamespaceMgr.CreateQueue("TestQueue");
}
QueueClient Client = QueueClient.CreateFromConnectionString(connectionString, "TestQueue", ReceiveMode.PeekLock);
for (int i = 0; i < 5; i++)
{
// Create message, passing a string message for the body.
BrokeredMessage message = new BrokeredMessage("Test message " + i);
// Set some addtional custom app-specific properties.
message.Properties["TestProperty"] = "TestValue";
message.Properties["Message number"] = i;
// Send message to the queue.
Client.Send(message);
}
ReceiveQueueMessages(Client);
}
示例15: FromBrokeredMessage
public static SBMessage FromBrokeredMessage(BrokeredMessage message)
{
SBMessage ret = new SBMessage(message.GetBody());
foreach (var key in message.Properties.Keys)
ret.Headers.Add(key, message.Properties[key]);
return ret;
}