当前位置: 首页>>代码示例>>C#>>正文


C# SubscriptionClient.OnMessage方法代码示例

本文整理汇总了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();
            });
        }
开发者ID:robstoll,项目名称:farmfinder,代码行数:28,代码来源:Global.asax.cs

示例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;
        }
开发者ID:icarsystems-ramon,项目名称:CitaTaller1,代码行数:63,代码来源:Listener.cs

示例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;
                }
            }
        }
开发者ID:britehouse,项目名称:toyota-tsusho-new,代码行数:65,代码来源:Subscriber.cs


注:本文中的SubscriptionClient.OnMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。