{"action":"created","issue":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/206","repository_url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul","labels_url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/206/labels{/name}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/206/comments","events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/206/events","html_url":"https://github.com/spring-cloud/spring-cloud-consul/issues/206","id":170417661,"number":206,"title":"Customize SpringAggregatorFactory implementation of getClusterName() using consul discovery client","user":{"login":"JagmohanSharma","id":19706178,"avatar_url":"https://avatars.githubusercontent.com/u/19706178?v=3","gravatar_id":"","url":"https://api.github.com/users/JagmohanSharma","html_url":"https://github.com/JagmohanSharma","followers_url":"https://api.github.com/users/JagmohanSharma/followers","following_url":"https://api.github.com/users/JagmohanSharma/following{/other_user}","gists_url":"https://api.github.com/users/JagmohanSharma/gists{/gist_id}","starred_url":"https://api.github.com/users/JagmohanSharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JagmohanSharma/subscriptions","organizations_url":"https://api.github.com/users/JagmohanSharma/orgs","repos_url":"https://api.github.com/users/JagmohanSharma/repos","events_url":"https://api.github.com/users/JagmohanSharma/events{/privacy}","received_events_url":"https://api.github.com/users/JagmohanSharma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-10T13:31:40Z","updated_at":"2016-08-17T07:11:13Z","closed_at":null,"body":"@spencergibb \r\n\r\nI want to customize the implementation of SpringAggregatorFactory as I want to set cluster information from consul agent. Right now this is being provided by spring cloud where it is reading this from clusterConfig given in properties file.as \r\n\r\n            private List<String> getClusterNames()  {\r\n\t\t   List<String> clusters = new ArrayList<String>();\r\n\t\t   String clusterNames = aggClusters.get();\r\n\t\t  if (clusterNames == null || clusterNames.trim().length() == 0) {\r\n\t\t\tclusters.add(\"default\");\r\n\t\t  }\r\n\t\t  else {\r\n\t\t\tString[] parts = aggClusters.get().split(\",\");\r\n\t\t\tfor (String s : parts) {\r\n\t\t\t\tclusters.add(s);\r\n\t\t\t}\r\n\t\t  }\r\n\t\t  return clusters;\r\n\t      }\r\n\r\n\r\nI have provided option to also read this from consul as per my project requirement as \r\n\r\n          private List<String> getClusterNames() {\r\n\r\n        List<String> clusters = new ArrayList<String>();\r\n        List<String> appNames = discoveryClient.getServices();\r\n        if (appNames == null || appNames.size() == 0) {\r\n            logger.info(\"No apps configured, returning an empty instance list\");\r\n            String clusterNames = aggClusters.get();\r\n            if (clusterNames == null || clusterNames.trim().length() == 0) {\r\n                clusters.add(\"default\");\r\n            } else {\r\n                String[] parts = aggClusters.get().split(\",\");\r\n                for (String s : parts) {\r\n                    clusters.add(s);\r\n                }\r\n            }\r\n        } else {\r\n            for (String appName : appNames) {\r\n                try {\r\n                    clusters.add(appName);\r\n                } catch (Exception ex) {\r\n\r\n                }\r\n            }\r\n        }\r\n\r\n        return clusters;\r\n    }\r\n\r\n\r\nI have created a local AggregatoryFactory class and configured this in local TurbineLifeCycle class as \r\n\r\n              public class HystrixTurbineLifecycle extends TurbineLifecycle {\r\n\r\n                       @Resource\r\n                         InstanceDiscovery instanceDiscovery;\r\n\r\n                        public HystrixTurbineLifecycle(InstanceDiscovery instanceDiscovery) {\r\n                        super(instanceDiscovery);\r\n                          }\r\n\r\n                          private boolean running;\r\n\r\n    @Override\r\n    public void start() {\r\n        PluginsFactory.setClusterMonitorFactory(new TurbineAggregatorFactory());\r\n        PluginsFactory.setInstanceDiscovery(instanceDiscovery);\r\n        TurbineInit.init();\r\n        running = true;\r\n    }\r\n\r\n    @Override\r\n    public void stop() {\r\n        this.running = false;\r\n    }\r\n\r\n    @Override\r\n    public boolean isRunning() {\r\n        return this.running;\r\n    }\r\n}\r\n\r\n\r\n\r\nNow this lifecycle class in also configured as \r\n\r\n                    @EnableConfigurationProperties\r\n                  @Configuration\r\n                        public class TurbineInstanceDiscoveryConfig {\r\n\r\n    @Resource\r\n    private DiscoveryClient discoveryClient;\r\n\r\n    @Bean\r\n    public HasFeatures Feature() {\r\n        return HasFeatures.namedFeature(\"Turbine (HTTP)\", TurbineInstanceDiscoveryConfig.class);\r\n    }\r\n\r\n    @Bean\r\n    public ServletRegistrationBean turbineStreamServlet() {\r\n        return new ServletRegistrationBean(new TurbineStreamServlet(), \"/turbine.stream\");\r\n    }\r\n\r\n    @Bean\r\n    public TurbineProperties turbineProperties() {\r\n        return new TurbineProperties();\r\n    }\r\n\r\n    @Bean(name = \"turbineLifecycle\")\r\n    public TurbineLifecycle turbineLifecycle(InstanceDiscovery instanceDiscovery) {\r\n        return new HystrixTurbineLifecycle(instanceDiscovery);\r\n    }\r\n\r\n    @Bean\r\n    public InstanceDiscovery instanceDiscovery(TurbineProperties turbineProperties) {\r\n        return new TurbineInstanceDiscoverImpl(turbineProperties, discoveryClient);\r\n    }\r\n}\r\n\r\n\r\nNow It is able to use my own implementation for Turbine instance discovery as configured above but it is not reading HystixTurbineLifeCycle which I have created to inject AggregatoryFactory . \r\nAnd it is reading this from spring cloud TurbineLifecycle.\r\n\r\nPlease help how can I configure this to use own AggregatorFactory instead of using spring cloud SpringAggregatorFactory.\r\n"},"comment":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/comments/240331549","html_url":"https://github.com/spring-cloud/spring-cloud-consul/issues/206#issuecomment-240331549","issue_url":"https://api.github.com/repos/spring-cloud/spring-cloud-consul/issues/206","id":240331549,"user":{"login":"JagmohanSharma","id":19706178,"avatar_url":"https://avatars.githubusercontent.com/u/19706178?v=3","gravatar_id":"","url":"https://api.github.com/users/JagmohanSharma","html_url":"https://github.com/JagmohanSharma","followers_url":"https://api.github.com/users/JagmohanSharma/followers","following_url":"https://api.github.com/users/JagmohanSharma/following{/other_user}","gists_url":"https://api.github.com/users/JagmohanSharma/gists{/gist_id}","starred_url":"https://api.github.com/users/JagmohanSharma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JagmohanSharma/subscriptions","organizations_url":"https://api.github.com/users/JagmohanSharma/orgs","repos_url":"https://api.github.com/users/JagmohanSharma/repos","events_url":"https://api.github.com/users/JagmohanSharma/events{/privacy}","received_events_url":"https://api.github.com/users/JagmohanSharma/received_events","type":"User","site_admin":false},"created_at":"2016-08-17T07:11:13Z","updated_at":"2016-08-17T07:11:13Z","body":"actually we need to make it dynamic in nature as we should not configure this from applicaiton.yml cluster config. So as in SpringAggregatorFactory getClusterNames() we are reading cluster config to have List of cluster, same thing we need to achieve with reading these from consul. Now this I have achieved via configuring \r\n@Bean\r\n    HystrixTurbineLifecycle turbineContextListener(InstanceDiscovery instanceDiscovery) {\r\n        return new HystrixTurbineLifecycle(instanceDiscovery, discoveryClient);\r\n    }\r\n\r\nand I have removed @EnableTurbine from my Application class.  and in life cycle class I have configured this. \r\n@Override\r\n    public void start() {\r\n        logger.info(\"Initializing Turbine\");\r\n        PluginsFactory.setClusterMonitorFactory(new TurbineAggregatorFactory(discoveryClient));\r\n        PluginsFactory.setInstanceDiscovery(instanceDiscovery);\r\n        TurbineInit.init();\r\n        running.set(true);\r\n    }\r\nSo I am now able to getClusterNames() from consul services. \r\n\r\n******But Now I am facing issue with InstanceObservable pollDelayMillis property as it keeps trying in this interval time even /hystrix.stream is not working due to  “MaxConcurrentConnections reached: 5” issue with 503 error.   so we are facing service slowdown issue due to this. can we override this behaviour for pollDelayMillis as if /hystrix.stream is not working and it is not getting event stream then we not keep this trying continuously. but try after some time if its start working with proper event stream from services.** \r\n\r\n\r\n"}}
{"actor":{"display_login":"JagmohanSharma"}}