本文整理汇总了C#中SubscriptionClient.OnMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionClient.OnMessageAsync方法的具体用法?C# SubscriptionClient.OnMessageAsync怎么用?C# SubscriptionClient.OnMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubscriptionClient
的用法示例。
在下文中一共展示了SubscriptionClient.OnMessageAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start(Func<BrokeredMessage, Task> callback)
{
lock (_mutex)
{
if (_subscriptionClient != null) throw new InvalidOperationException("Already started!");
_subscriptionClient = _queueManager.CreateSubscriptionReceiver(_topicPath, _subscriptionName);
_subscriptionClient.OnMessageAsync(callback,
new OnMessageOptions
{
AutoComplete = false,
MaxConcurrentCalls = _concurrentHandlerLimit,
});
}
}
示例2: ServiceBusMessageBus
public ServiceBusMessageBus(string connectionString, string topicName, ISerializer serializer = null) {
_topicName = topicName;
_serializer = serializer ?? new JsonNetSerializer();
_subscriptionName = "MessageBus";
_namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!_namespaceManager.TopicExists(_topicName))
_namespaceManager.CreateTopic(_topicName);
_topicClient = TopicClient.CreateFromConnectionString(connectionString, _topicName);
if (!_namespaceManager.SubscriptionExists(_topicName, _subscriptionName))
_namespaceManager.CreateSubscription(_topicName, _subscriptionName);
_subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, _topicName, _subscriptionName, ReceiveMode.ReceiveAndDelete);
_subscriptionClient.OnMessageAsync(OnMessageAsync, new OnMessageOptions { AutoComplete = true });
}
示例3: AzureServiceBusMessageBus
public AzureServiceBusMessageBus(string connectionString, string topicName, ISerializer serializer = null, ILoggerFactory loggerFactory = null) : base(loggerFactory) {
_serializer = serializer ?? new JsonNetSerializer();
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.TopicExists(topicName))
namespaceManager.CreateTopic(topicName);
_topicClient = TopicClient.CreateFromConnectionString(connectionString, topicName);
const string subscriptionName = "MessageBus";
if (!namespaceManager.SubscriptionExists(topicName, subscriptionName))
namespaceManager.CreateSubscription(topicName, subscriptionName);
_subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName, ReceiveMode.ReceiveAndDelete);
_subscriptionClient.OnMessageAsync(OnMessageAsync, new OnMessageOptions { AutoComplete = true });
}
示例4: btnStart_Click
private async void btnStart_Click(object sender, EventArgs e)
{
if (string.Compare(btnStart.Text, Start, StringComparison.OrdinalIgnoreCase) == 0)
{
receiverBrokeredMessageInspector = cboReceiverInspector.SelectedIndex > 0
? Activator.CreateInstance(serviceBusHelper.BrokeredMessageInspectors[cboReceiverInspector.Text]) as IBrokeredMessageInspector
: null;
cancellationTokenSource = new CancellationTokenSource();
btnStart.Text = Stop;
blockingCollection = new BlockingCollection<Tuple<long, long, long>>();
timer = new System.Timers.Timer
{
AutoReset = true,
Enabled = true,
Interval = 1000 * txtRefreshInformation.IntegerValue
};
if (startLog != null && checkBoxLogging.Checked)
{
startLog();
}
timer.Elapsed += timer_Elapsed;
autoComplete = checkBoxAutoComplete.Checked;
logging = checkBoxLogging.Checked;
verbose = checkBoxVerbose.Checked;
tracking = checkBoxTrackMessages.Checked;
try
{
receiveMode = cboReceivedMode.SelectedIndex == 1 ? ReceiveMode.PeekLock : ReceiveMode.ReceiveAndDelete;
if (entityDescription is QueueDescription)
{
var currentQueue = entityDescription as QueueDescription;
queueClient = serviceBusHelper.MessagingFactory.CreateQueueClient(currentQueue.Path, receiveMode);
queueClient.PrefetchCount = txtPrefetchCount.IntegerValue;
if (currentQueue.RequiresSession)
{
await queueClient.RegisterSessionHandlerFactoryAsync(
new CustomMessageSessionAsyncHandlerFactory(new CustomMessageSessionAsyncHandlerConfiguration
{
Logging = logging,
Tracking = tracking,
AutoComplete = autoComplete,
MessageEncoder = encoder,
ReceiveMode = receiveMode,
GetElapsedTime = GetElapsedTime,
UpdateStatistics = UpdateStatistics,
WriteToLog = writeToLog,
MessageInspector = receiverBrokeredMessageInspector,
ServiceBusHelper = serviceBusHelper,
TrackMessage = bm => Invoke(new Action<BrokeredMessage>(m => messageCollection.Add(m)), bm)
}), GetSessionHandlerOptions());
}
else
{
#pragma warning disable 4014
Task.Run(() => queueClient.OnMessageAsync(OnMessageAsync, GetOnMessageOptions()));
#pragma warning restore 4014
}
}
if (entityDescription is SubscriptionDescription)
{
var currentSubscription = entityDescription as SubscriptionDescription;
subscriptionClient = serviceBusHelper.MessagingFactory.CreateSubscriptionClient(currentSubscription.TopicPath,
currentSubscription.Name,
receiveMode);
subscriptionClient.PrefetchCount = txtPrefetchCount.IntegerValue;
if (currentSubscription.RequiresSession)
{
await subscriptionClient.RegisterSessionHandlerFactoryAsync(
new CustomMessageSessionAsyncHandlerFactory(new CustomMessageSessionAsyncHandlerConfiguration
{
Logging = logging,
Tracking = tracking,
AutoComplete = autoComplete,
MessageEncoder = encoder,
ReceiveMode = receiveMode,
GetElapsedTime = GetElapsedTime,
UpdateStatistics = UpdateStatistics,
WriteToLog = writeToLog,
ServiceBusHelper = serviceBusHelper,
TrackMessage = bm => Invoke(new Action<BrokeredMessage>(m => messageCollection.Add(m)), bm)
}), GetSessionHandlerOptions());
}
else
{
#pragma warning disable 4014
Task.Run(() => subscriptionClient.OnMessageAsync(OnMessageAsync, GetOnMessageOptions()));
#pragma warning restore 4014
}
}
#pragma warning disable 4014
Task.Run(new Action(RefreshGraph));
#pragma warning restore 4014
GetElapsedTime();
}
catch (Exception ex)
{
HandleException(ex);
//.........这里部分代码省略.........
示例5: InitializeReceiver
void InitializeReceiver(SubscriptionClient receiver, ConsoleColor color)
{
// register the OnMessageAsync callback
receiver.OnMessageAsync(
async message =>
{
if (message.Label != null &&
message.ContentType != null &&
message.Label.Equals("Scientist", StringComparison.InvariantCultureIgnoreCase) &&
message.ContentType.Equals("application/json", StringComparison.InvariantCultureIgnoreCase))
{
var body = message.GetBody<Stream>();
dynamic scientist = JsonConvert.DeserializeObject(new StreamReader(body, true).ReadToEnd());
lock (Console.Out)
{
Console.ForegroundColor = color;
Console.WriteLine(
"\t\t\t\tMessage received: \n\t\t\t\t\t\tMessageId = {0}, \n\t\t\t\t\t\tSequenceNumber = {1}, \n\t\t\t\t\t\tEnqueuedTimeUtc = {2}," +
"\n\t\t\t\t\t\tExpiresAtUtc = {5}, \n\t\t\t\t\t\tContentType = \"{3}\", \n\t\t\t\t\t\tSize = {4}, \n\t\t\t\t\t\tContent: [ firstName = {6}, name = {7} ]",
message.MessageId,
message.SequenceNumber,
message.EnqueuedTimeUtc,
message.ContentType,
message.Size,
message.ExpiresAtUtc,
scientist.firstName,
scientist.name);
Console.ResetColor();
}
}
await message.CompleteAsync();
},
new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1 });
}