Exemplo n.º 1
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));
 }