コード例 #1
0
        /// <summary>
        ///     Queries the configuration.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <ConsumerConfigureQueryResponseModel> QueryConfiguration(ConsumerConfigureQueryRequestModel request)
        {
            IReliableDictionary <string, ConsumerConfiguresState> dictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, ConsumerConfiguresState> >(DictionaryKey);

            using (ITransaction tx = this.StateManager.CreateTransaction())
            {
                ConditionalValue <ConsumerConfiguresState> result = await dictionary.TryGetValueAsync(tx, ConfigureKey);

                if (!result.HasValue)
                {
                    return(null);
                }
                List <ConsumerConfigureInfo>        configureState = result.Value.Configures.Where(x => x.Action.Equals(request.Action) && x.ServiceName.Equals(request.AppName) && x.DictionaryKey.Equals(request.DictionaryKey)).ToList();
                ConsumerConfigureQueryResponseModel response       = new ConsumerConfigureQueryResponseModel
                {
                    ResultCode = 1,
                    ResultDesc = "查询成功",
                    Configure  = configureState.ConvertAll(x => (new ConsumerConfigureQueryResponseInfo
                    {
                        Action = x.Action,
                        Address = x.Address,
                        DictionaryKey = x.DictionaryKey,
                        ServiceName = x.ServiceName
                    }))
                };
                return(response);
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> QueryConfiguration(ConsumerConfigureQueryRequest request)
        {
            IConsumerConfigure client = ServiceProxy.Create <IConsumerConfigure>(new Uri("fabric:/Consumer/ConsumerConfigure"), new ServicePartitionKey(0));
            ConsumerConfigureQueryResponseModel result = await client.QueryConfiguration(new ConsumerConfigureQueryRequestModel
            {
                Action        = request.Action,
                AppName       = request.AppName,
                DictionaryKey = request.DictionaryKey
            });

            ConsumerConfigureQueryResponse response = new ConsumerConfigureQueryResponse
            {
                ResultCode = result.ResultCode,
                ResultDesc = result.ResultDesc,
                Configure  = result.Configure.ConvertAll(x => (new ConsumerConfigureResponse
                {
                    Action = x.Action,
                    Address = x.Address.Value,
                    DictionaryKey = x.DictionaryKey,
                    ServiceName = x.ServiceName
                }))
            };

            return(this.Ok(response));
        }
 /// <summary>
 ///     This method causes the communication listener to be opened. Once the Open
 ///     completes, the communication listener becomes usable - accepts and sends messages.
 /// </summary>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 ///     A <see cref="T:System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
 ///     the endpoint string.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">ServiceBusConnectionString Or ServiceBusQueueName Configuration Is Empty</exception>
 Task <string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken)
 {
     if (string.IsNullOrWhiteSpace(this.serviceBusConnectionString) || string.IsNullOrWhiteSpace(this.serviceBusQueueName))
     {
         throw new ArgumentNullException("ServiceBusConnectionString Or ServiceBusQueueName Configuration Is Empty", new Exception());
     }
     this.ServiceBusClient = QueueClient.CreateFromConnectionString(this.serviceBusConnectionString, this.serviceBusQueueName);
     this.ServiceBusClient.OnMessage(message =>
     {
         try
         {
             //分发 具体处理
             this.ProcessingMessage.Reset();
             dynamic eventSource = JsonConvert.DeserializeObject <dynamic>(message.GetBody <string>());
             ConsumerConfigureQueryResponseModel result = client.QueryConfiguration(new ConsumerConfigureQueryRequestModel
             {
                 Action        = eventSource.Action,
                 AppName       = eventSource.ServiceName,
                 DictionaryKey = eventSource.DictionaryKey
             }).GetAwaiter().GetResult();
             if (result.ResultCode == 1)
             {
                 HttpClient client = new HttpClient();
             }
             ServiceEventSource.Current.Message($"Consumer Message {message.GetBody<string>()}");
         }
         catch (Exception)
         {
             // ignored
         }
         finally
         {
             this.ProcessingMessage.Set();
         }
     });
     return(Task.FromResult(this.serviceBusConnectionString));
 }