Commit 47538921 by amir

- create with metrics false/true

- init metrics publisher only once
parent 30f9cd9f
### Microservice Framework in JAVA
## Version 1.2.1:
- create with metrics false/true
- init metrics publisher only once
## Version 1.2.0:
- Add Graphite Repoter for metrics:
......
group 'com.ipgallery.common'
version '1.2.0'
version '1.2.1'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -32,6 +32,7 @@ import microservice.params.RestClientParams;
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;
/*************************************************************************
......@@ -220,7 +221,6 @@ public class IRestClientRestImpl implements ICommandClient
/*********************************************************************************************************************************************/
private static final String COMMAND_ERROR = "Command Error: ";
RestClientParams clientParams = null;
SimpleRestClient httpRestClient = null;
......@@ -240,15 +240,28 @@ public class IRestClientRestImpl implements ICommandClient
httpRestClient.Initialize(clientParams.getMaxConnection());
if (clientParams.isMetricsEnabled())
{
IMetricsFactoryImpl factoryImpl = (IMetricsFactoryImpl) IMetricsFactoryImpl.getInstance();
HystrixMetricsPublisher publisher = new HystrixCodaHaleMetricsPublisher(factoryImpl.getMetrics());
HystrixPlugins.getInstance().registerMetricsPublisher(publisher);
initMetricsPublisher();
// jsonListener = new MetricJsonListener();
// poller = new HystrixMetricsPoller(jsonListener, POLLING_DELAY);
// 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)
{
serviceDiscovery = Optional.ofNullable(servDisco);
......
......@@ -11,6 +11,12 @@ public class RestClientParams extends BaseClientParams
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)
{
super(serviceName, useCache, cacheTimeout,true,cacheHost);
......
......@@ -34,6 +34,7 @@ public class TestMicroClient
{
ICommandClient cmdClient = new IRestClientRestImpl(clientParams).withServiceDiscovery(serDisco);
client = new MicroserviceClient(cmdClient,clientParams);
new MicroserviceClient(new IRestClientRestImpl(clientParams),clientParams);
CommandParams cmdParams = new CommandParams("entities", "MCX/entities/lili/person", null, null, null);
System.out.println("Start Testing");
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