/// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="tid"></param>
        /// <returns></returns>
        public async Task <string> DelServiceNodeAsync(long tid)
        {
            var node = await this.Entitys.Nodes.FindByBkAsync(tid);

            var result = this.DB.Delete(node) > 0;

            if (result)
            {
                if (node.Type.Equals((int)NodeTypeEnum.Consul))
                {
                    //N:innovationwork.cloudbag.v1.cloudbagrestfulapi|A:[http://192.168.1.2:8088/]
                    //注销服务
                    var service = ConsulClient.GetService(node.ServiceFullName,
                                                          "N:{0}|A:[{1}]".Args(node.ServiceFullName, node.Url));
                    if (service != null)
                    {
                        ConsulClient.UnregisterService(service.ServiceID);
                    }
                }
                else
                {
                    SignalRUtil.PushServerToGroup(node.ServiceFullName, GetServerNodeList(node.ServiceFullName));
                }
                return(string.Empty);
            }
            return(Tip.DeleteError);
        }
Exemple #2
0
        public void GetService_WithNoMatchingTag_ThrowException()
        {
            using (new HttpResultsFilter("[]"))
            {
                Action action = () => ConsulClient.GetService("ServiceStack", "three");

                action.ShouldThrow <GatewayServiceDiscoveryException>().WithMessage("No healthy services are currently registered to process the request of type 'three'");
            }
        }
Exemple #3
0
        public void GetService_ThrowsException_WhenResponseIsEmpty(string response)
        {
            using (new HttpResultsFilter(response))
            {
                Action action = () => ConsulClient.GetService("service", "three");

                action.ShouldThrow <GatewayServiceDiscoveryException>()
                .WithMessage("No healthy services are currently registered to process the request of type 'three'")
                .WithInnerException <WebServiceException>()
                .WithInnerMessage("Expected json but received empty or null reponse from http://127.0.0.1:8500/v1/health/service/service?near=_agent&passing&tag=three");
            }
        }
        public ConsulLoadBalancerRequestContext(string serviceKey, string version = null)
        {
            if (string.IsNullOrEmpty(ConsulUris.LocalAgent))
            {
                throw new ConfigurationErrorsException("can not find SOA.consul.url in Appseting file");
            }

            if (string.IsNullOrEmpty(version))
            {
                //_server = ConsulClient.GetServices(serviceKey);
                _servers = ConsulClient.GetServices(serviceKey).GroupBy(r => r.ServiceAddress, y => y).Select(r => r.First()).ToArray();
            }
            else
            {
                _servers = new [] { ConsulClient.GetService(serviceKey, version) };
            }
        }
Exemple #5
0
 /// <summary>
 /// 配置EventBus,RabbitMQ
 /// 配合集成测试,该方法可重写
 /// </summary>
 /// <param name="services"></param>
 /// <returns></returns>
 public virtual IServiceCollection ConfigureEventBus(IServiceCollection services)
 {
     services.AddRabbitMQEventBus(connectionAction: () =>
     {
         string endpoint = "192.168.0.251:5672";
         if (!HostingEnvironment.IsDevelopment())
         {
             using (IConsulClient consul = new ConsulClient(option => option.Address = new Uri(Configuration["App:ConsulUrl"])))
             {
                 endpoint = consul.GetService(Configuration["App:EventBus:ServiceName"]).Result;
             }
         }
         var connectionString = $"amqp://{Configuration["App:EventBus:UserName"]}:{Configuration["App:EventBus:Password"]}@{endpoint}/";
         return(connectionString);
     }, eBusOption =>
     {
         eBusOption.ClientProvidedAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
         eBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
     });
     return(services);
 }
Exemple #6
0
        public void GetService_ReturnsCorrectly_WhenHealthyService()
        {
            using (new HttpResultsFilter
            {
                StringResultFn = (request, s) =>
                {
                    if (request.RequestUri.AbsoluteUri == "http://127.0.0.1:8500/v1/health/service/api?near=_agent&passing&tag=EchoA")
                    {
                        return("[{\"Node\": {\"Node\": \"X1-Win10\",\"Address\": \"127.0.0.1\",\"CreateIndex\": 3,\"ModifyIndex\": 29},\"Service\": {\"ID\": \"ss-ServiceA-7f96fc1c-ab72-4471-bc90-a39cd5591545\",\"Service\": \"api\",\"Tags\": [\"ss-version-2.0\",\"EchoA\",\"one\",\"two\",\"three\"],\"Address\": \"http://127.0.0.1:8091/\",\"Port\": 8091,\"EnableTagOverride\": false,\"CreateIndex\": 7,\"ModifyIndex\": 7},\"Checks\": [{\"Node\": \"X1-Win10\",\"CheckID\": \"serfHealth\",\"Name\": \"Serf Health Status\",\"Status\": \"passing\",\"Notes\": \"\",\"Output\": \"Agent alive and reachable\",\"ServiceID\": \"\",\"ServiceName\": \"\",\"CreateIndex\": 3,\"ModifyIndex\": 3}]},{\"Node\": {\"Node\": \"X1-Win10\",\"Address\": \"127.0.0.1\",\"CreateIndex\": 3,\"ModifyIndex\": 29},\"Service\": {\"ID\": \"ss-ServiceB-73dff66c-bc91-43f3-92f5-6ee7677b2756\",\"Service\": \"api\",\"Tags\": [\"ss-version-1.0\",\"EchoB\"],\"Address\": \"http://127.0.0.1:8092/api/\",\"Port\": 8092,\"EnableTagOverride\": false,\"CreateIndex\": 6,\"ModifyIndex\": 6},\"Checks\": [{\"Node\": \"X1-Win10\",\"CheckID\": \"serfHealth\",\"Name\": \"Serf Health Status\",\"Status\": \"passing\",\"Notes\": \"\",\"Output\": \"Agent alive and reachable\",\"ServiceID\": \"\",\"ServiceName\": \"\",\"CreateIndex\": 3,\"ModifyIndex\": 3}]}]");
                    }
                    return(null);
                }
            })
            {
                var response = ConsulClient.GetService("api", "EchoA");

                response.ServiceName.Should().Be("api");
                response.ServiceID.Should().Be("ss-ServiceA-7f96fc1c-ab72-4471-bc90-a39cd5591545");
                response.ServiceAddress.Should().Be("http://127.0.0.1:8091/");
                response.ServicePort.Should().Be(8091);
                response.ServiceTags.Should().BeEquivalentTo("ss-version-2.0", "EchoA", "one", "two", "three");
            }
        }
        public ConsulService GetService(string serviceName, string dtoName)
        {
            var response = ConsulClient.GetService(serviceName, dtoName);

            return(new ConsulService(response));
        }