Objective
It is unavoidable to use Dropwizard as the service framework. Continuous learning. The last time you used feign in Dropwizard, using Hystrix, was a basic primer. The next step is optimization based on this.
Separate the logic that needs to use the configuration from the application.
In the beginning of the demo, because do not know dropwizard how to spread the class, how to inject, put all the initialization of everything into the application to new out. Now we find a way to detach some of the configuration logic.
Now pull out the feign base configuration:
Public classConnectivitybundleImplementsconfiguredbundle@Override Public void Run(helloworldconfiguration Configuration, Environment environment)throwsException {//init hystrix configmap<string, object> hystrixconfig = Configuration.Gethystrixconfig(); for(FinalMap.Entry<string, object> config:hystrixconfig.EntrySet()) {ConfigurationManager.getconfiginstance().SetProperty(config.GetKey(), CONFIG.GetValue()); System. out.println(config.GetKey()); } }@Override Public void Initialize(bootstrap<?> Bootstrap) { }}
Then, add it in the application.
Com.test.HelloWorldApplication
@Overridepublicvoidinitialize(Bootstrap<HelloWorldConfiguration> bootstrap) { bootstrap.addBundle(newConnectivityBundle());}
Use Dropwizard (2)-Configure classification Configuredbundle