本文整理汇总了C#中SubscriptionClient.OnMessage方法的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionClient.OnMessage方法的具体用法?C# SubscriptionClient.OnMessage怎么用?C# SubscriptionClient.OnMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubscriptionClient
的用法示例。
在下文中一共展示了SubscriptionClient.OnMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitialiseTopic
public void InitialiseTopic()
{
ServicePointManager.DefaultConnectionLimit = 12;
string connectionString = CloudConfigurationManager.GetSetting("ServiceBus.TopicConnectionString");
_topicClient = SubscriptionClient.CreateFromConnectionString(connectionString, "recreateindex", "WebRoles");
Task.Run(() =>
{
_topicClient.OnMessage(async receivedMessage =>
{
var sequenceNumber = receivedMessage.SequenceNumber;
try
{
await _throttling.Execute(async () => ReCreateSearcher());
}
catch (Exception ex)
{
//no idea why it does not work but well, log it
Trace.TraceWarning("Exception occurred during the read of message '" + sequenceNumber + "': " + ex.Message);
}
}, new OnMessageOptions {
AutoComplete = true
});
_completedEvent.WaitOne();
});
}
示例2: Start
public bool Start(string dmsTallerId)
{
try
{
//connectionString = ConfigurationManager.AppSettings["CitaTallerAzureBusSubscribe"];
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.SubscriptionExists(topicName, SubscripName))
{
// Defino un filtro para un taller. Y creo la suscripción con ese filtro.
dmsTallerId = dmsTallerId.Replace("-", "").Trim().ToUpper();
if (string.IsNullOrEmpty(dmsTallerId))
{
namespaceManager.CreateSubscription(topicName, SubscripName);
}
else
{
SqlFilter DmsTallerIdFilter = new SqlFilter("DmsTallerId = '" + dmsTallerId + "'");
namespaceManager.CreateSubscription(topicName, SubscripName, DmsTallerIdFilter);
}
}
// Creo un cliente para este NameSpace + Topic + Subscription
Client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, SubscripName);
Connected = true;
// Defino las opciones para el callback (evento)
ClientOptions = new OnMessageOptions();
ClientOptions.AutoComplete = false;
ClientOptions.MaxConcurrentCalls = 1;
ClientOptions.AutoRenewTimeout = TimeSpan.FromMinutes(1);
}
catch (Exception ex)
{
Connected = false;
ErrorMsg(ex.Message);
}
// Definimos el callback (event)
Client.OnMessage((busMessage) =>
{
try
{
if (Closing)
{
busMessage.Abandon();
return;
}
Message message = new Message();
message.SolicitudID = busMessage.Properties["SolicitudID"].ToString();
message.DmsTallerId = busMessage.Properties["DmsTallerId"].ToString();
OcxOnMessage(message);
// Eliminamos el mensaje de la suscripción
busMessage.Complete();
}
catch (Exception ex)
{
// Hemos tenido un crash. Liberamos el mensaje y quedará pendiente.
busMessage.Abandon();
ErrorMsg(ex.Message);
}
}, ClientOptions);
return true;
}
示例3: StartEvents
public void StartEvents(Action<CheckEvent> action)
{
using (new TraceLogicalScope(source, "StartEvents"))
{
try
{
eventPath = String.Format("{0}/Events", dc);
eventSubscription = String.Format("{0}-{1}-Subscription", node, dc);
this.source.TraceData(TraceEventType.Verbose, 0, new object[] { "Path", eventPath });
string connectionString = configuration.ServiceBus.ConnectionString;
this.source.TraceData(TraceEventType.Verbose, 0, new object[] { "ConnectionString", connectionString });
this.CreateTopic(dc, eventPath);
this.CreateCheckEventSubscription(dc, eventPath, eventSubscription);
OnMessageOptions options = new OnMessageOptions()
{
AutoComplete = true, // Indicates if the message-pump should call complete on messages after the callback has completed processing.
MaxConcurrentCalls = 1 // Indicates the maximum number of concurrent calls to the callback the pump should initiate
};
if(this.eventClient != null)
this.StopEvents();
this.eventClient = SubscriptionClient.CreateFromConnectionString(connectionString, eventPath, eventSubscription, ReceiveMode.PeekLock);
eventClient.OnMessage((BrokeredMessage message) =>
{
using(new TraceLogicalScope(source, "Receiving a message"))
{
try
{
if (message != null)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(CheckEvent));
CheckEvent ev = serializer.ReadObject(message.GetBody<Stream>()) as CheckEvent;
action.Invoke(ev);
}
}
catch(Exception ex)
{
source.TraceData(TraceEventType.Error, 0, ex);
throw;
}
}
}, options);
source.TraceEvent(TraceEventType.Verbose, 0, "Listening for Events...");
}
catch (Exception ex)
{
source.TraceData(TraceEventType.Error, 0, ex);
throw;
}
}
}