Commit 47538921 by amir

- create with metrics false/true

- init metrics publisher only once
parent 30f9cd9f
### Microservice Framework in JAVA ### Microservice Framework in JAVA
## Version 1.2.1:
- create with metrics false/true
- init metrics publisher only once
## Version 1.2.0: ## Version 1.2.0:
- Add Graphite Repoter for metrics: - Add Graphite Repoter for metrics:
......
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '1.2.0' version '1.2.1'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
......
...@@ -32,6 +32,7 @@ import microservice.params.RestClientParams; ...@@ -32,6 +32,7 @@ import microservice.params.RestClientParams;
public class IRestClientRestImpl implements ICommandClient public class IRestClientRestImpl implements ICommandClient
{ {
public static final String HYSTRIX_PLUGIN_HYSTRIX_METRICS_PUBLISHER_IMPLEMENTATION = "hystrix.plugin.HystrixMetricsPublisher.implementation";
private static final int POLLING_DELAY = 500; private static final int POLLING_DELAY = 500;
/************************************************************************* /*************************************************************************
...@@ -220,8 +221,7 @@ public class IRestClientRestImpl implements ICommandClient ...@@ -220,8 +221,7 @@ public class IRestClientRestImpl implements ICommandClient
/*********************************************************************************************************************************************/ /*********************************************************************************************************************************************/
private static final String COMMAND_ERROR = "Command Error: ";
private static final String COMMAND_ERROR = "Command Error: ";
RestClientParams clientParams = null; RestClientParams clientParams = null;
SimpleRestClient httpRestClient = null; SimpleRestClient httpRestClient = null;
// HystrixMetricsPoller poller = null; // HystrixMetricsPoller poller = null;
...@@ -240,15 +240,28 @@ public class IRestClientRestImpl implements ICommandClient ...@@ -240,15 +240,28 @@ public class IRestClientRestImpl implements ICommandClient
httpRestClient.Initialize(clientParams.getMaxConnection()); httpRestClient.Initialize(clientParams.getMaxConnection());
if (clientParams.isMetricsEnabled()) if (clientParams.isMetricsEnabled())
{ {
IMetricsFactoryImpl factoryImpl = (IMetricsFactoryImpl) IMetricsFactoryImpl.getInstance(); initMetricsPublisher();
HystrixMetricsPublisher publisher = new HystrixCodaHaleMetricsPublisher(factoryImpl.getMetrics());
HystrixPlugins.getInstance().registerMetricsPublisher(publisher);
// jsonListener = new MetricJsonListener(); // jsonListener = new MetricJsonListener();
// poller = new HystrixMetricsPoller(jsonListener, POLLING_DELAY); // poller = new HystrixMetricsPoller(jsonListener, POLLING_DELAY);
// poller.start(); // poller.start();
} }
} }
private synchronized void initMetricsPublisher() {
String publisherStr = System.getProperty(HYSTRIX_PLUGIN_HYSTRIX_METRICS_PUBLISHER_IMPLEMENTATION);
if(publisherStr == null) {
try {
IMetricsFactoryImpl factoryImpl = (IMetricsFactoryImpl) IMetricsFactoryImpl.getInstance();
HystrixMetricsPublisher publisher = new HystrixCodaHaleMetricsPublisher(factoryImpl.getMetrics());
HystrixPlugins.getInstance().registerMetricsPublisher(publisher);
System.setProperty(HYSTRIX_PLUGIN_HYSTRIX_METRICS_PUBLISHER_IMPLEMENTATION, publisher.getClass().getName());
}
catch (IllegalStateException ise){
}
}
}
public IRestClientRestImpl withServiceDiscovery(IServiceDiscovery servDisco) public IRestClientRestImpl withServiceDiscovery(IServiceDiscovery servDisco)
{ {
serviceDiscovery = Optional.ofNullable(servDisco); serviceDiscovery = Optional.ofNullable(servDisco);
......
...@@ -11,6 +11,12 @@ public class RestClientParams extends BaseClientParams ...@@ -11,6 +11,12 @@ public class RestClientParams extends BaseClientParams
this.address = address; this.address = address;
} }
public RestClientParams(String serviceName,boolean useCache,int cacheTimeout,String address, String cacheHost,boolean enableMetrics)
{
super(serviceName, useCache, cacheTimeout,enableMetrics,cacheHost);
this.address = address;
}
public RestClientParams(String serviceName,boolean useCache,int cacheTimeout,String address,String cacheHost, int maxConnection) public RestClientParams(String serviceName,boolean useCache,int cacheTimeout,String address,String cacheHost, int maxConnection)
{ {
super(serviceName, useCache, cacheTimeout,true,cacheHost); super(serviceName, useCache, cacheTimeout,true,cacheHost);
......
...@@ -34,6 +34,7 @@ public class TestMicroClient ...@@ -34,6 +34,7 @@ public class TestMicroClient
{ {
ICommandClient cmdClient = new IRestClientRestImpl(clientParams).withServiceDiscovery(serDisco); ICommandClient cmdClient = new IRestClientRestImpl(clientParams).withServiceDiscovery(serDisco);
client = new MicroserviceClient(cmdClient,clientParams); client = new MicroserviceClient(cmdClient,clientParams);
new MicroserviceClient(new IRestClientRestImpl(clientParams),clientParams);
CommandParams cmdParams = new CommandParams("entities", "MCX/entities/lili/person", null, null, null); CommandParams cmdParams = new CommandParams("entities", "MCX/entities/lili/person", null, null, null);
System.out.println("Start Testing"); System.out.println("Start Testing");
for (int i = 0 ; i < MAX_ITERATION; i++) for (int i = 0 ; i < MAX_ITERATION; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment