Commit a15d7791 by Amir Aharon

Merge branch 'Feature-SeperateServices' into 'develop'

Feature seperate services

See merge request !6
parents e667691a 37eb61d8
Showing with 368 additions and 181 deletions
### Microservice Framework in JAVA ### Microservice Framework in JAVA
## 2.3.0
- Seperate Services from main lib
- Split to common,clients,servicePubSub and app jars
-
## 2.2.0 ## 2.2.0
- Add Pulsar PubSub Implementation - Add Pulsar PubSub Implementation
- Add Either as default for optional - Add Either as default for optional
...@@ -37,13 +41,13 @@ ...@@ -37,13 +41,13 @@
- add ZeroMQ support for Rest - add ZeroMQ support for Rest
## 1.3.8: Add colorful logging ## 1.3.8: Add colorful logging
## 1.3.7: Add Pagination - PageBuilder ## 1.3.7: Add Pagination - PageBuilder
## 1.3.6: upgrade common-utils 1.2.0 ## 1.3.6: upgrade common-common.microservice.utils 1.2.0
## 1.3.2: ## 1.3.2:
- add getMD5Hash, catch unhandled exceptions, add command-params builder - add getMD5Hash, catch unhandled exceptions, add command-params builder
## 1.3.1: ## 1.3.1:
- add rabbotmq command client + change version to 1.3.1 - add rabbotmq command client + change version to 1.3.1
## 1.3.0: ## 1.3.0:
- add service authorization with jwt - add microservice.service authorization with jwt
- env param override config file - env param override config file
## 1.2.5: ## 1.2.5:
- support rabbit on server side - support rabbit on server side
...@@ -68,10 +72,10 @@ ...@@ -68,10 +72,10 @@
- Add '/_stat' in monitoring to returns stats of metrics, more to come - Add '/_stat' in monitoring to returns stats of metrics, more to come
- Change '/reload' to '/_reload' - Change '/reload' to '/_reload'
## Version '1.1.0': ## Version '1.1.0':
- Add resolveService in service discovery, used by http command-client to resolve the address - Add resolveService in microservice.service discovery, used by http command-client to resolve the address
of the dest service of the dest microservice.service
# Env for service discovery: # Env for microservice.service discovery:
service.resolver.polling.interval (milli) default is 5000 microservice.service.resolver.polling.interval (milli) default is 5000
# Env for jwt: # Env for jwt:
jwt.token.in.authorization : true jwt.token.in.authorization : true
jwt.salt : "12345678901234567890123456789012" jwt.salt : "12345678901234567890123456789012"
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '2.2.0' version '2.3.0'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
...@@ -18,9 +18,42 @@ repositories { ...@@ -18,9 +18,42 @@ repositories {
} }
sourceSets { sourceSets {
main main {
// client java {
common srcDir 'src/main/java'
exclude '**'
}
}
common {
java.srcDir 'src/main/java/microservice/common'
resources.srcDir 'src/main/java/microservice/common/resources'
}
clients {
java.srcDir'src/main/java/microservice/clients'
resources.srcDir 'src/main/java/microservice/clients/resources'
}
servicePubsub {
java.srcDir 'src/main/java/microservice/service/pubsub'
resources.srcDir 'src/main/java/microservice/service/resources'
}
app {
java.srcDir 'src/main/java/microservice/app'
resources.srcDir 'src/main/java/microservice/resources'
compileClasspath += sourceSets.servicePubsub.runtimeClasspath
compileClasspath += sourceSets.clients.runtimeClasspath
}
test {
compileClasspath += sourceSets.common.runtimeClasspath
compileClasspath += sourceSets.servicePubsub.runtimeClasspath
compileClasspath += sourceSets.clients.runtimeClasspath
compileClasspath += sourceSets.app.runtimeClasspath
}
} }
dependencies { dependencies {
...@@ -33,36 +66,40 @@ dependencies { ...@@ -33,36 +66,40 @@ dependencies {
'com.netflix.hystrix:hystrix-core:1.4.14' 'com.netflix.hystrix:hystrix-core:1.4.14'
) )
// clientCompile ( clientsCompile (
// files('build/common/microservice-common.jar'), files('build/common/microservice-common.jar'),
//// files('build/common/activities-common.jar'), 'com.ipgallery.common:utils:1.2.5',
// //'com.ipgallery.common:microservice:2.1.1' 'com.netflix.rxjava:rxjava-apache-http:0.20.7',
// ) 'com.netflix.hystrix:hystrix-metrics-event-stream:1.4.12',
'com.squareup.okhttp3:okhttp:3.8.0'
compile ( )
servicePubsubCompile (
files('build/common/microservice-common.jar'), files('build/common/microservice-common.jar'),
// files('build/client/microservice-client.jar'), 'org.apache.pulsar:pulsar-client:2.4.2',
'org.apache.pulsar:pulsar-client-admin:2.4.2'
)
appCompile (
files('build/common/microservice-common.jar'),
files('build/clients/microservice-clients.jar'),
'io.jsonwebtoken:jjwt:0.6.0', 'io.jsonwebtoken:jjwt:0.6.0',
'io.undertow:undertow-core:2.0.28.Final', 'io.undertow:undertow-core:2.0.28.Final',
'com.fasterxml.jackson.core:jackson-databind:2.2.3', 'com.fasterxml.jackson.core:jackson-databind:2.2.3',
'io.dropwizard.metrics:metrics-core:3.1.0', 'io.dropwizard.metrics:metrics-core:3.1.0',
'com.netflix.hystrix:hystrix-codahale-metrics-publisher:1.4.14',
'com.netflix.hystrix:hystrix-metrics-event-stream:1.4.12',
'redis.clients:jedis:2.4.2', 'redis.clients:jedis:2.4.2',
'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2', 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2',
'com.ipgallery.common:utils:1.2.5', 'com.ipgallery.common:utils:1.2.5',
'com.ipgallery.common:rabbitmq:1.0.3', 'com.ipgallery.common:rabbitmq:1.0.3',
'com.ecwid.consul:consul-api:1.1.9', 'com.ecwid.consul:consul-api:1.1.9',
//'com.github.davidb:metrics-influxdb:0.9.3'
'com.github.davidb:metrics-influxdb:0.8.2', 'com.github.davidb:metrics-influxdb:0.8.2',
'io.dropwizard.metrics:metrics-graphite:3.2.5', 'io.dropwizard.metrics:metrics-graphite:3.2.5',
'org.zeromq:jeromq:0.4.0', 'org.zeromq:jeromq:0.4.0',
'org.elasticsearch.client:rest:5.4.1', 'org.elasticsearch.client:rest:5.4.1',
'com.netflix.rxjava:rxjava-apache-http:0.20.7', 'com.netflix.rxjava:rxjava-apache-http:0.20.7',
'com.squareup.okhttp3:okhttp:3.8.0', 'com.netflix.hystrix:hystrix-metrics-event-stream:1.4.12',
'org.apache.pulsar:pulsar-client:2.4.2', 'com.squareup.okhttp3:okhttp:3.8.0'
'org.apache.pulsar:pulsar-client-admin:2.4.2'
) )
// compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.2' // compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.2'
...@@ -77,26 +114,56 @@ dependencies { ...@@ -77,26 +114,56 @@ dependencies {
task commonJar(type: Jar) { task commonJar(type: Jar) {
from configurations.commonCompile.collect { zipTree it } from configurations.commonCompile.collect { zipTree it }
from sourceSets.common.output from sourceSets.common.output
version = '1.0.0' version = '1.0.1'
archiveName = "microservice-common.jar" archiveName = "microservice-common.jar"
destinationDir = file("build/common") destinationDir = file("build/common")
} }
//// client // pubsub
//task clientJar(type: Jar) { task servicePubsubJar(type: Jar) {
// dependsOn commonJar dependsOn commonJar
// mustRunAfter commonJar mustRunAfter commonJar
// from configurations.clientCompile.collect { zipTree it } //from configurations.servicePubsubCompile.collect { zipTree it }
// from sourceSets.client.output from sourceSets.servicePubsub.output
// version = '1.0.0' version = '1.0.0'
// archiveName = "microservice-client.jar" archiveName = "microservice-service-pubsub.jar"
// destinationDir = file("build/client") destinationDir = file("build/servicePubsub")
//} }
// client
task clientsJar(type: Jar) {
dependsOn commonJar
mustRunAfter commonJar
//from configurations.clientsCompile.collect { zipTree it }
from sourceSets.clients.output
version = '1.0.0'
archiveName = "microservice-clients.jar"
destinationDir = file("build/clients")
}
jar { // app
task appJar(type: Jar) {
dependsOn commonJar dependsOn commonJar
mustRunAfter commonJar mustRunAfter commonJar
from configurations.appCompile.collect { zipTree it }
from sourceSets.app.output
version = version // '2.3.0'
archiveName = "microservice-app.jar"
destinationDir = file("build/app")
} }
assemble {
dependsOn commonJar
dependsOn clientsJar
dependsOn servicePubsubJar
dependsOn appJar
}
//jar {
// dependsOn servicePubsubJar
// mustRunAfter servicePubsubJar
//}
// from configurations.compile.collect { zipTree it } // from configurations.compile.collect { zipTree it }
// from sourceSets.main.output // from sourceSets.main.output
// //version = '2.2.0' // //version = '2.2.0'
...@@ -116,10 +183,10 @@ publishing { ...@@ -116,10 +183,10 @@ publishing {
} }
} }
mavenJava(MavenPublication) { // mavenJava(MavenPublication) {
artifactId 'microservice' // artifactId 'microservice'
from components.java // from components.java
} // }
// client(MavenPublication) { // client(MavenPublication) {
...@@ -164,5 +231,53 @@ publishing { ...@@ -164,5 +231,53 @@ publishing {
artifact commonJar artifact commonJar
} }
clients(MavenPublication) {
artifactId 'microservice-clients'
version clientsJar.version
// adding dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.clientsCompile.dependencies.each {
if (it.group != null && it.name != null){
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
artifact clientsJar
} }
servicePubsub(MavenPublication) {
artifactId 'microservice-service-pubsub'
version servicePubsubJar.version
// adding dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.servicePubsubCompile.dependencies.each {
if (it.group != null && it.name != null){
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
artifact servicePubsubJar
}
app(MavenPublication) {
artifactId 'microservice-app'
version appJar.version
// adding dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
}
artifact appJar
}
}
} }
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
+- counters and metrics in the reactor +- counters and metrics in the reactor
+- validateRequest in RestService , the jwt issues +- validateRequest in RestService , the jwt issues
+- Add monitoring apis +- Add monitoring apis
+- All the validation ,pre/post handling that was were done by the handler will be done by the base service +- All the validation ,pre/post handling that was were done by the handler will be done by the base microservice.service
- add Runtime Test: - add Runtime Test:
addTest(const char *testName, nsMicroservice_Iface::TestFunction testFunction); addTest(const char *testName, nsMicroservice_Iface::TestFunction testFunction);
addTest(nsMicroservice_Iface::ITest *p_testClass) addTest(nsMicroservice_Iface::ITest *p_testClass)
+- Add true async in http rest service, that we can send response after handleRequest ends. +- Add true async in http rest microservice.service, that we can send response after handleRequest ends.
// exchange.dispatch(() -> { // exchange.dispatch(() -> {
// new Timer().schedule(new TimerTask() { // new Timer().schedule(new TimerTask() {
// public void run() { // public void run() {
......
package microservice; package microservice;
import common.microservice.io.iface.*; import common.microservice.io.iface.*;
import common.microservice.io.impl.ILoggerConsoleImpl;
import io.undertow.Handlers; import io.undertow.Handlers;
import io.undertow.Undertow; import io.undertow.Undertow;
import io.undertow.Undertow.Builder; import io.undertow.Undertow.Builder;
...@@ -9,8 +10,8 @@ import io.undertow.server.handlers.PathHandler; ...@@ -9,8 +10,8 @@ import io.undertow.server.handlers.PathHandler;
import io.undertow.server.handlers.resource.ClassPathResourceManager; import io.undertow.server.handlers.resource.ClassPathResourceManager;
import io.undertow.util.MimeMappings; import io.undertow.util.MimeMappings;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import microservice.params.RMQClientParams; import common.microservice.params.RMQClientParams;
import microservice.params.RestServerParams; import common.microservice.params.RestServerParams;
import microservice.handlers.*; import microservice.handlers.*;
import microservice.io.iface.IRestServer; import microservice.io.iface.IRestServer;
import microservice.io.impl.*; import microservice.io.impl.*;
...@@ -42,7 +43,7 @@ import static io.undertow.Handlers.resource; ...@@ -42,7 +43,7 @@ import static io.undertow.Handlers.resource;
* @author amir * @author amir
* *
*/ */
public class MicroserviceApp public class MicroserviceApp implements IApp
{ {
private static MicroserviceApp sInstance = null; private static MicroserviceApp sInstance = null;
...@@ -630,7 +631,7 @@ public class MicroserviceApp ...@@ -630,7 +631,7 @@ public class MicroserviceApp
.filter(p -> p != null) .filter(p -> p != null)
.forEach(servicesMap -> .forEach(servicesMap ->
servicesMap.forEach((serviceKey, service) -> { servicesMap.forEach((serviceKey, service) -> {
service.init(); service.init(this);
if (enableMetrics) if (enableMetrics)
service.withMetricsFactory(IMetricsFactoryImpl.getInstance()); service.withMetricsFactory(IMetricsFactoryImpl.getInstance());
service.register(serviceDiscovery, id); service.register(serviceDiscovery, id);
...@@ -691,14 +692,14 @@ public class MicroserviceApp ...@@ -691,14 +692,14 @@ public class MicroserviceApp
} }
/** // /**
* logging utils // * logging utils
*/ // */
public void logRcid(String from, String rcid){ // public void logRcid(String from, String rcid){
getLogger().info(from + " RCID: " + rcid); // getLogger().info(from + " RCID: " + rcid);
} // }
//
public void logMcid(String from, String mcid){ // public void logMcid(String from, String mcid){
getLogger().info(from + " MCID: " + mcid); // getLogger().info(from + " MCID: " + mcid);
} // }
} }
package microservice; package microservice;
import clients.microservice.impl.IRestClientHttpImpl;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.CacheClient; import common.CacheClient;
import common.JsonHandler; import common.JsonHandler;
...@@ -10,8 +11,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -10,8 +11,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import common.microservice.io.iface.IRestClient; import common.microservice.io.iface.IRestClient;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import microservice.io.impl.IRestClientHttpImpl; import common.microservice.params.BaseClientParams;
import microservice.params.BaseClientParams;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
/** /**
......
...@@ -11,6 +11,8 @@ import common.microservice.io.iface.IMetricsFactory; ...@@ -11,6 +11,8 @@ import common.microservice.io.iface.IMetricsFactory;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import static common.microservice.services.CommonServices.buildServiceKey;
/** /**
* ------------ * ------------
* Services -> | | -> Methods * Services -> | | -> Methods
...@@ -86,20 +88,20 @@ public class Reactor implements CommonServices.IServiceReactor { ...@@ -86,20 +88,20 @@ public class Reactor implements CommonServices.IServiceReactor {
methodKeyList.add(key); methodKeyList.add(key);
} }
public static String buildServiceKey(CommonServices.MethodParams methodParams) { // public static String buildServiceKey(CommonServices.MethodParams methodParams) {
return Constants.SLASH_SEPERATOR + // return Constants.SLASH_SEPERATOR +
methodParams.getServiceType().name() + Constants.TYPE_PREFIX_SEPERATOR + // methodParams.getServiceType().name() + Constants.TYPE_PREFIX_SEPERATOR +
methodParams.getServiceCommand().toString() + Constants.TYPE_PREFIX_SEPERATOR + // methodParams.getServiceCommand().toString() + Constants.TYPE_PREFIX_SEPERATOR +
methodParams.getResourceUri(); // methodParams.getResourceUri();
} // }
public static String buildServiceKey(Enums.EnumServiceType enumServiceType, // public static String buildServiceKey(Enums.EnumServiceType enumServiceType,
CommonServices.IServiceCommands serviceCommands, // CommonServices.IServiceCommands serviceCommands,
String resourceUri) { // String resourceUri) {
return new StringBuilder(32).append(Constants.SLASH_SEPERATOR).append(enumServiceType.name()).append(Constants.TYPE_PREFIX_SEPERATOR) // return new StringBuilder(32).append(Constants.SLASH_SEPERATOR).append(enumServiceType.name()).append(Constants.TYPE_PREFIX_SEPERATOR)
.append(serviceCommands.toString()).append(Constants.TYPE_PREFIX_SEPERATOR) // .append(serviceCommands.toString()).append(Constants.TYPE_PREFIX_SEPERATOR)
.append(resourceUri).toString(); // .append(resourceUri).toString();
} // }
/** /**
* delegating the msg/request from the service to the method if any * delegating the msg/request from the service to the method if any
......
...@@ -167,7 +167,7 @@ public class IMetricsFactoryImpl implements IMetricsFactory ...@@ -167,7 +167,7 @@ public class IMetricsFactoryImpl implements IMetricsFactory
.convertDurationsTo(TimeUnit.MILLISECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS)
.filter(MetricFilter.ALL) .filter(MetricFilter.ALL)
.skipIdleMetrics(true) .skipIdleMetrics(true)
.tag("service", MicroserviceApp.getsInstance().getAppName()) .tag("microservice/service/microservice/microservice", MicroserviceApp.getsInstance().getAppName())
.tag("instance", MicroserviceApp.getsInstance().getId()) .tag("instance", MicroserviceApp.getsInstance().getId())
.tag("server", MicroserviceApp.getsInstance().getServerName()) .tag("server", MicroserviceApp.getsInstance().getServerName())
.transformer(new CategoriesMetricMeasurementTransformer("module", "artifact")) .transformer(new CategoriesMetricMeasurementTransformer("module", "artifact"))
......
...@@ -4,13 +4,14 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -4,13 +4,14 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller;
import common.microservice.io.iface.ILogger;
import http.simpleRestClient.SimpleRestResponse; import http.simpleRestClient.SimpleRestResponse;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import common.microservice.io.iface.IRestClient; import common.microservice.io.iface.IRestClient;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import microservice.params.BaseClientParams; import common.microservice.params.BaseClientParams;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import microservice.params.RMQClientParams; import common.microservice.params.RMQClientParams;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import rabbitmq.client.RMQRestClient; import rabbitmq.client.RMQRestClient;
import rabbitmq.common.RMQId; import rabbitmq.common.RMQId;
...@@ -28,6 +29,7 @@ import java.util.function.Consumer; ...@@ -28,6 +29,7 @@ import java.util.function.Consumer;
public class IRMQClientRestImpl implements IRestClient public class IRMQClientRestImpl implements IRestClient
{ {
private static int REQUEST_TIMEOUT = 30000; private static int REQUEST_TIMEOUT = 30000;
private ILogger logger;
/*********************************************************************************************/ /*********************************************************************************************/
/* JSON LISTENER /* JSON LISTENER
...@@ -112,6 +114,11 @@ public class IRMQClientRestImpl implements IRestClient ...@@ -112,6 +114,11 @@ public class IRMQClientRestImpl implements IRestClient
} }
@Override @Override
public void init(ILogger logger) {
this.logger = logger;
}
@Override
public BaseRestResponse create(CommandParams reqCtx) public BaseRestResponse create(CommandParams reqCtx)
{ {
BaseRestResponse brr = null; BaseRestResponse brr = null;
......
...@@ -13,7 +13,7 @@ import microservice.handlers.MBIHandler; ...@@ -13,7 +13,7 @@ import microservice.handlers.MBIHandler;
import common.microservice.io.iface.IPubSub; import common.microservice.io.iface.IPubSub;
import microservice.io.iface.IRestServer; import microservice.io.iface.IRestServer;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import microservice.params.RMQClientParams; import common.microservice.params.RMQClientParams;
public class IRestServerRMQImpl implements IRestServer { public class IRestServerRMQImpl implements IRestServer {
......
...@@ -19,7 +19,7 @@ import microservice.handlers.RestHandler; ...@@ -19,7 +19,7 @@ import microservice.handlers.RestHandler;
import common.microservice.io.iface.IPubSub; import common.microservice.io.iface.IPubSub;
import microservice.io.iface.IRestServer; import microservice.io.iface.IRestServer;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import microservice.params.RestServerParams; import common.microservice.params.RestServerParams;
import static io.undertow.Handlers.resource; import static io.undertow.Handlers.resource;
public class IRestServerUndertowImpl implements IRestServer { public class IRestServerUndertowImpl implements IRestServer {
......
package microservice.services; package microservice.service.pubsub.impl;
import common.microservice.io.iface.IApp;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
...@@ -46,7 +47,7 @@ public class IPubSubServiceMqttImpl extends CommonServices.IPubSubService { ...@@ -46,7 +47,7 @@ public class IPubSubServiceMqttImpl extends CommonServices.IPubSubService {
} }
@Override @Override
public boolean init() { public boolean init(IApp app) {
try { try {
......
package microservice.services; package microservice.service.pubsub.impl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -8,6 +8,7 @@ import common.microservice.services.CommonServices; ...@@ -8,6 +8,7 @@ import common.microservice.services.CommonServices;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import common.microservice.types.UserProfile; import common.microservice.types.UserProfile;
import common.microservice.utils.IDGenerator; import common.microservice.utils.IDGenerator;
import common.microservice.utils.Logging;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.ExpiredJwtException;
import io.undertow.Handlers; import io.undertow.Handlers;
...@@ -26,16 +27,16 @@ import common.microservice.security.EncryptionUtils; ...@@ -26,16 +27,16 @@ import common.microservice.security.EncryptionUtils;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import microservice.handlers.BaseHandler; import microservice.handlers.BaseHandler;
import microservice.handlers.Reactor;
import microservice.io.impl.IRequestRestImpl; import microservice.io.impl.IRequestRestImpl;
import microservice.io.impl.IResponseRestImpl; import microservice.io.impl.IResponseRestImpl;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import microservice.params.RestServerParams; import common.microservice.params.RestServerParams;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import static common.microservice.services.CommonServices.buildServiceKey;
import static io.undertow.Handlers.resource; import static io.undertow.Handlers.resource;
import static common.microservice.defs.Constants.*; import static common.microservice.defs.Constants.*;
...@@ -48,7 +49,6 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -48,7 +49,6 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
RestServerParams restServerParams = null; RestServerParams restServerParams = null;
Undertow restServer = null; Undertow restServer = null;
Thread restThread = null; Thread restThread = null;
MicroserviceApp msAppInstance = null;
private String appName; private String appName;
public ObjectMapper objMapper = null; public ObjectMapper objMapper = null;
protected Enums.EnumAuthenticationType authType = Enums.EnumAuthenticationType.DEFAULT; protected Enums.EnumAuthenticationType authType = Enums.EnumAuthenticationType.DEFAULT;
...@@ -80,7 +80,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -80,7 +80,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
try { try {
if (restClient != null) { if (restClient != null) {
if (cmdParams.getRcid() != null) // log rcid if (cmdParams.getRcid() != null) // log rcid
msAppInstance.logRcid("handleSyncRespCommand." + name,cmdParams.getRcid()); Logging.logRcid(logger,"handleSyncRespCommand." + name,cmdParams.getRcid());
resp = command.get(); resp = command.get();
}; };
} catch (Exception e) { } catch (Exception e) {
...@@ -96,7 +96,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -96,7 +96,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
boolean retstat; boolean retstat;
try { try {
if (cmdParams.getRcid() != null) // log rcid if (cmdParams.getRcid() != null) // log rcid
msAppInstance.logRcid("handleAsyncRespCommand." + name,cmdParams.getRcid()); Logging.logRcid(logger,"handleAsyncRespCommand." + name,cmdParams.getRcid());
retstat = command.getAsBoolean(); retstat = command.getAsBoolean();
} catch (Exception e) { } catch (Exception e) {
retstat = false; retstat = false;
...@@ -145,19 +145,21 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -145,19 +145,21 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
} }
@Override @Override
public boolean init() { public boolean init(IApp app) {
boolean stat = true; boolean stat = true;
if (MicroserviceApp.getsInstance() != null) { this.app = app;
msAppInstance = MicroserviceApp.getsInstance(); if (app != null) {
logger = msAppInstance.getLogger(); logger = app.getLogger();
this.appName = msAppInstance.getAppName(); this.appName = app.getAppName();
} }
switch (getServiceMode()){ switch (getServiceMode()){
case E_CLIENT: case E_CLIENT:
initRestClient();
break; break;
case E_CLIENT_SERVER: case E_CLIENT_SERVER:
case E_SERVER: case E_SERVER:
initRestClient();
stat = buildRestServer(); stat = buildRestServer();
break; break;
default: default:
...@@ -168,6 +170,12 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -168,6 +170,12 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
return stat; return stat;
} }
private void initRestClient() {
if (restClient != null) {
restClient.init(logger);
}
}
private boolean buildRestServer() { private boolean buildRestServer() {
String host = this.restServerParams.getHost(); String host = this.restServerParams.getHost();
if (host == null || Network.LOCALHOST.equals(host)) if (host == null || Network.LOCALHOST.equals(host))
...@@ -235,7 +243,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -235,7 +243,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
/** /**
* finally we can delegate * finally we can delegate
*/ */
String key = Reactor.buildServiceKey(Enums.EnumServiceType.E_REST,reqContext.enumRestCommands,reqContext.request.getRelativePath()); String key = buildServiceKey(Enums.EnumServiceType.E_REST,reqContext.enumRestCommands,reqContext.request.getRelativePath());
reactor.delegate(this, key ,reqContext); reactor.delegate(this, key ,reqContext);
} }
} else { } else {
...@@ -289,7 +297,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -289,7 +297,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
if (reqCtx.rcid == null) // create a new one if (reqCtx.rcid == null) // create a new one
reqCtx.rcid = IDGenerator.createUUID(); reqCtx.rcid = IDGenerator.createUUID();
else // log it else // log it
msAppInstance.logRcid("getRequestContext",reqCtx.rcid); Logging.logRcid(logger,"getRequestContext",reqCtx.rcid);
return reqCtx; return reqCtx;
} }
...@@ -345,7 +353,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -345,7 +353,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
apiDocMimeMappingsBuilder.addMapping("yaml", "text/x-yaml"); apiDocMimeMappingsBuilder.addMapping("yaml", "text/x-yaml");
apiDocMimeMappingsBuilder.addMapping("html", "text/html"); apiDocMimeMappingsBuilder.addMapping("html", "text/html");
pathHandler.addPrefixPath("/static", resource(new ClassPathResourceManager(getClass().getClassLoader(),getClass().getPackage()))//"static")) pathHandler.addPrefixPath("/static", resource(new ClassPathResourceManager(getClass().getClassLoader(),getClass().getPackage()))//"static"))
.addWelcomeFiles("microservice/services/metrics.html") .addWelcomeFiles("microservice/service/pubsub/metrics.html")
.setMimeMappings(apiDocMimeMappingsBuilder.build()) .setMimeMappings(apiDocMimeMappingsBuilder.build())
.setDirectoryListingEnabled(false)); .setDirectoryListingEnabled(false));
} }
...@@ -429,7 +437,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements ...@@ -429,7 +437,7 @@ public class IRestServiceHttpImpl extends CommonServices.IRestService implements
} }
else else
{ {
msAppInstance.getLogger().error(NO_TOKEN_FOR_REQUEST); logger.error(NO_TOKEN_FOR_REQUEST);
sendErrorResp(restContext.response,NO_TOKEN_FOR_REQUEST); sendErrorResp(restContext.response,NO_TOKEN_FOR_REQUEST);
valid = false; valid = false;
} }
......
package microservice.services; package microservice.service.pubsub.impl;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -8,17 +8,15 @@ import common.microservice.io.iface.*; ...@@ -8,17 +8,15 @@ import common.microservice.io.iface.*;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import common.microservice.utils.IDGenerator; import common.microservice.utils.IDGenerator;
import microservice.MicroserviceApp;
import common.microservice.context.CrudMethod; import common.microservice.context.CrudMethod;
import common.microservice.context.RestContext; import common.microservice.context.RestContext;
import common.microservice.context.RestMsg; import common.microservice.context.RestMsg;
import common.microservice.context.RestResponse; import common.microservice.context.RestResponse;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import microservice.handlers.Reactor;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import microservice.params.ZMQParams; import common.microservice.params.ZMQParams;
import microservice.services.protocol.zmq.RestImpl; import microservice.service.pubsub.impl.protocol.zmq.RestImpl;
import common.microservice.utils.ICacheClientGuavaImpl; import common.microservice.utils.ICacheClientGuavaImpl;
import microservice.utils.ZSocketPool; import microservice.utils.ZSocketPool;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
...@@ -35,6 +33,7 @@ import java.util.stream.IntStream; ...@@ -35,6 +33,7 @@ import java.util.stream.IntStream;
import static common.microservice.defs.Constants.EXIT_MSG; import static common.microservice.defs.Constants.EXIT_MSG;
import static common.microservice.defs.Constants.EXIT_MSG_LEN; import static common.microservice.defs.Constants.EXIT_MSG_LEN;
import static common.microservice.services.CommonServices.buildServiceKey;
/** /**
* Created by amir on 14/05/17. * Created by amir on 14/05/17.
...@@ -154,15 +153,15 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -154,15 +153,15 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
private ILogger logger= null; private ILogger logger= null;
private CommonServices.ICacheClient<Long,CacheEntry> responseCacheClient = null; private CommonServices.ICacheClient<Long,CacheEntry> responseCacheClient = null;
public ClientWorker(int workerNumber, CommonServices.ICacheClient<Long, CacheEntry> responseCacheClient) { public ClientWorker(ILogger logger,int workerNumber, CommonServices.ICacheClient<Long, CacheEntry> responseCacheClient) {
this.workerNumber = workerNumber; this.workerNumber = workerNumber;
this.responseCacheClient = responseCacheClient; this.responseCacheClient = responseCacheClient;
bindAddress = ADDRESS + String.valueOf(workerNumber); bindAddress = ADDRESS + String.valueOf(workerNumber);
this.logger = logger;
} }
@Override @Override
public boolean init() { public boolean init() {
logger = MicroserviceApp.getsInstance().getLogger();
pull = new ZSocket(ZMQ.PULL); pull = new ZSocket(ZMQ.PULL);
return pull.bind(bindAddress); return pull.bind(bindAddress);
} }
...@@ -287,10 +286,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -287,10 +286,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
private ZMQParams.ServerParams zmqParams; private ZMQParams.ServerParams zmqParams;
private ZSocket pull = null; private ZSocket pull = null;
private ZSocket push = null; private ZSocket push = null;
private ILogger logger;
private int numOfServerWorkers; private int numOfServerWorkers;
public ServerReceive(ZMQParams.ServerParams zmqParams, int numOfServerWorkers) { public ServerReceive(ILogger logger,ZMQParams.ServerParams zmqParams, int numOfServerWorkers) {
this.zmqParams = zmqParams; this.zmqParams = zmqParams;
this.numOfServerWorkers = numOfServerWorkers; this.numOfServerWorkers = numOfServerWorkers;
this.logger = logger;
} }
...@@ -329,7 +330,7 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -329,7 +330,7 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
} }
}); });
runThread.start(); runThread.start();
MicroserviceApp.getsInstance().getLogger().info("ZMQ server started successfully on host: " + zmqParams.getHost() + ", and port: " + String.valueOf(zmqParams.getPort())); logger.info("ZMQ server started successfully on host: " + zmqParams.getHost() + ", and port: " + String.valueOf(zmqParams.getPort()));
} }
@Override @Override
...@@ -352,15 +353,16 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -352,15 +353,16 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
private CommonServices.IServiceReactor reactor = null; private CommonServices.IServiceReactor reactor = null;
private CommonServices.IRestService parentService = null; private CommonServices.IRestService parentService = null;
public ObjectMapper objMapper = null; public ObjectMapper objMapper = null;
private ILogger logger= null; private ILogger logger = null;
private ZSocketPool serverSendPool = null; private ZSocketPool serverSendPool = null;
private int workerNumber = 0; private int workerNumber = 0;
private String bindAddress = null; private String bindAddress = null;
public ServerWorker(CommonServices.IServiceReactor reactor, public ServerWorker(ILogger logger, CommonServices.IServiceReactor reactor,
CommonServices.IRestService parentService, CommonServices.IRestService parentService,
ZSocketPool serverSendPool, ZSocketPool serverSendPool,
int workerNumber) { int workerNumber) {
this.logger = logger;
this.reactor = reactor; this.reactor = reactor;
this.parentService = parentService; this.parentService = parentService;
this.serverSendPool = serverSendPool; this.serverSendPool = serverSendPool;
...@@ -371,7 +373,6 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -371,7 +373,6 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
@Override @Override
public boolean init() { public boolean init() {
logger = MicroserviceApp.getsInstance().getLogger();
pull = new ZSocket(ZMQ.PULL); pull = new ZSocket(ZMQ.PULL);
objMapper = new ObjectMapper(); objMapper = new ObjectMapper();
return pull.bind(bindAddress); return pull.bind(bindAddress);
...@@ -393,7 +394,7 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -393,7 +394,7 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
if (receiveMsg != null){ if (receiveMsg != null){
RestContext restContext = getRequestContext(receiveMsg); RestContext restContext = getRequestContext(receiveMsg);
if (restContext != null){ if (restContext != null){
String key = Reactor.buildServiceKey(Enums.EnumServiceType.E_REST, String key = buildServiceKey(Enums.EnumServiceType.E_REST,
restContext.enumRestCommands, restContext.enumRestCommands,
restContext.request.getRelativePath()); restContext.request.getRelativePath());
reactor.delegate(parentService, key ,restContext); reactor.delegate(parentService, key ,restContext);
...@@ -547,9 +548,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -547,9 +548,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
ByteBuffer respBB = ByteBuffer.allocate(CAPACITY); ByteBuffer respBB = ByteBuffer.allocate(CAPACITY);
FlatBufferBuilder respBuilder = new FlatBufferBuilder(); FlatBufferBuilder respBuilder = new FlatBufferBuilder();
public ServerReply(ILogger logger) {
this.logger = logger;
}
@Override @Override
public boolean init() { public boolean init() {
logger = MicroserviceApp.getsInstance().getLogger();
pull = new ZSocket(ZMQ.PULL); pull = new ZSocket(ZMQ.PULL);
return pull.bind(ADDRESS); return pull.bind(ADDRESS);
} }
...@@ -822,11 +826,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -822,11 +826,12 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
} }
@Override @Override
public boolean init() { public boolean init(IApp app) {
boolean retstat = true; boolean retstat = true;
if (MicroserviceApp.getsInstance() != null) { this.app = app;
this.appName = MicroserviceApp.getsInstance().getAppName(); if (app != null) {
this.logger = MicroserviceApp.getsInstance().getLogger(); this.appName = app.getAppName();
this.logger = app.getLogger();
} }
switch (getServiceMode()){ switch (getServiceMode()){
...@@ -853,24 +858,24 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements ...@@ -853,24 +858,24 @@ public class IRestServiceZmqImpl extends CommonServices.IRestService implements
public boolean allocateServer() { public boolean allocateServer() {
allWorkersList.add(new ServerReply()); allWorkersList.add(new ServerReply(logger));
/** /**
* init server send pool * init server send pool
*/ */
serverSendPool = ZSocketPool.buildPool(ServerReply.ADDRESS,ZMQ.PUSH,numOfServerWorkers); serverSendPool = ZSocketPool.buildPool(ServerReply.ADDRESS,ZMQ.PUSH,numOfServerWorkers);
for (int i = 0; i < numOfServerWorkers; i++){ for (int i = 0; i < numOfServerWorkers; i++){
allWorkersList.add(new ServerWorker(reactor,this,serverSendPool,i)); allWorkersList.add(new ServerWorker(logger,reactor,this,serverSendPool,i));
} }
// must be after the workers // must be after the workers
allWorkersList.add(new ServerReceive(serverParams,numOfServerWorkers)); allWorkersList.add(new ServerReceive(logger,serverParams,numOfServerWorkers));
return serverSendPool != null; return serverSendPool != null;
} }
public boolean allocateClient() { public boolean allocateClient() {
responseCacheClient = new ICacheClientGuavaImpl<>(EXPIRES_MILLI_SECONDS); responseCacheClient = new ICacheClientGuavaImpl<>(EXPIRES_MILLI_SECONDS);
for (int i = 0; i < numOfClientWorkers; i++){ for (int i = 0; i < numOfClientWorkers; i++){
allWorkersList.add(new ClientWorker(i,responseCacheClient)); allWorkersList.add(new ClientWorker(logger,i,responseCacheClient));
} }
// must be after workers // must be after workers
allWorkersList.add(new ClientReceive(clientReceiveParams,numOfClientWorkers)); allWorkersList.add(new ClientReceive(clientReceiveParams,numOfClientWorkers));
......
package microservice.services.protocol.zmq; package microservice.service.pubsub.impl.protocol.zmq;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.flatbuffers.FlatBufferBuilder; import com.google.flatbuffers.FlatBufferBuilder;
import common.microservice.io.iface.IApp;
import common.microservice.utils.IDGenerator; import common.microservice.utils.IDGenerator;
import microservice.MicroserviceApp;
import common.microservice.context.ParamValue; import common.microservice.context.ParamValue;
import common.microservice.context.QueueMsg; import common.microservice.context.QueueMsg;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import microservice.handlers.Reactor;
import common.microservice.io.iface.ILogger; import common.microservice.io.iface.ILogger;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import microservice.params.ZMQParams; import common.microservice.params.ZMQParams;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import microservice.utils.ZSocketPool; import microservice.utils.ZSocketPool;
import org.zeromq.ZMQ; import org.zeromq.ZMQ;
...@@ -24,6 +23,8 @@ import java.util.List; ...@@ -24,6 +23,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import static common.microservice.services.CommonServices.buildServiceKey;
/** /**
* MsgQueue implementation in ZMQ * MsgQueue implementation in ZMQ
*/ */
...@@ -56,7 +57,7 @@ public class IMsgQServiceZmqImpl extends CommonServices.IMsgQService { ...@@ -56,7 +57,7 @@ public class IMsgQServiceZmqImpl extends CommonServices.IMsgQService {
QueueMsg queueMsg = QueueMsg.getRootAsQueueMsg(bb); QueueMsg queueMsg = QueueMsg.getRootAsQueueMsg(bb);
if (queueMsg != null){ if (queueMsg != null){
MsgQContext msgQContext = getMsgQContext(queueMsg); MsgQContext msgQContext = getMsgQContext(queueMsg);
String key = Reactor.buildServiceKey(Enums.EnumServiceType.E_MSGQ, String key = buildServiceKey(Enums.EnumServiceType.E_MSGQ,
CommonServices.EnumMsgQueueCommands.E_QUEUE, CommonServices.EnumMsgQueueCommands.E_QUEUE,
msgQContext.topic); msgQContext.topic);
reactor.delegate(parentService, key ,msgQContext); reactor.delegate(parentService, key ,msgQContext);
...@@ -82,11 +83,12 @@ public class IMsgQServiceZmqImpl extends CommonServices.IMsgQService { ...@@ -82,11 +83,12 @@ public class IMsgQServiceZmqImpl extends CommonServices.IMsgQService {
@Override @Override
public boolean init() { public boolean init(IApp app) {
boolean retstat = true; boolean retstat = true;
if (MicroserviceApp.getsInstance() != null) { this.app = app;
this.appName = MicroserviceApp.getsInstance().getAppName(); if (app != null) {
this.logger = MicroserviceApp.getsInstance().getLogger(); this.appName = app.getAppName();
this.logger = app.getLogger();
} }
if (getServiceMode() != null) { if (getServiceMode() != null) {
......
package microservice.services.protocol.zmq; package microservice.service.pubsub.impl.protocol.zmq;
import common.microservice.context.RestMsg; import common.microservice.context.RestMsg;
import common.microservice.io.iface.IRequest; import common.microservice.io.iface.IRequest;
import common.microservice.io.iface.IResponse; import common.microservice.io.iface.IResponse;
import microservice.services.IRestServiceZmqImpl; import microservice.service.pubsub.impl.IRestServiceZmqImpl;
import microservice.utils.ZSocketPool; import microservice.utils.ZSocketPool;
import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.SerializationUtils;
import org.zeromq.ZMQ; import org.zeromq.ZMQ;
......
package microservice.services.protocol.zmq; package microservice.service.pubsub.impl.protocol.zmq;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -6,7 +6,7 @@ import common.microservice.utils.IDGenerator; ...@@ -6,7 +6,7 @@ import common.microservice.utils.IDGenerator;
import microservice.MicroserviceApp; import microservice.MicroserviceApp;
import common.microservice.context.RestContext; import common.microservice.context.RestContext;
import common.microservice.io.iface.ILogger; import common.microservice.io.iface.ILogger;
import microservice.params.ZMQParams; import common.microservice.params.ZMQParams;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import org.zeromq.ZMQ; import org.zeromq.ZMQ;
import org.zeromq.ZSocket; import org.zeromq.ZSocket;
......
package microservice.utils; package microservice.utils;
import clients.microservice.impl.IRestClientHttpImpl;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import common.microservice.io.iface.IRestClient; import common.microservice.io.iface.IRestClient;
import microservice.io.impl.IRestClientHttpImpl; import common.microservice.params.PulsarParams;
import microservice.params.PulsarParams; import microservice.service.pubsub.impl.IRestServiceHttpImpl;
import microservice.services.IPubSubServicePulsarImpl; import microservice.service.pubsub.impl.IRestServiceZmqImpl;
import microservice.services.IRestServiceHttpImpl; import common.microservice.params.RestClientParams;
import microservice.services.IRestServiceZmqImpl; import common.microservice.params.RestServerParams;
import microservice.params.RestClientParams; import common.microservice.params.ZMQParams;
import microservice.params.RestServerParams; import microservice.service.pubsub.impl.protocol.zmq.IMsgQServiceZmqImpl;
import microservice.params.ZMQParams; import service.microservice.IPubSubServicePulsarImpl;
import microservice.services.protocol.zmq.IMsgQServiceZmqImpl;
/** /**
* Created by amir on 09/05/17. * Created by amir on 09/05/17.
......
package common.microservice.io.iface;
public interface IApp {
ILogger getLogger();
String getAppName();
String getServerName();
String getId();
IConfiguration getConfiguration();
}
...@@ -12,7 +12,7 @@ import java.util.function.Consumer; ...@@ -12,7 +12,7 @@ import java.util.function.Consumer;
public interface IRestClient public interface IRestClient
{ {
static final String COMMAND_ERROR = "Command Error: "; static final String COMMAND_ERROR = "Command Error: ";
void init(ILogger logger);
public abstract class Command extends HystrixCommand<BaseRestResponse> { public abstract class Command extends HystrixCommand<BaseRestResponse> {
protected CommandParams reqCtx = null; protected CommandParams reqCtx = null;
......
package microservice.io.impl; package common.microservice.io.impl;
import common.microservice.io.iface.ILogger; import common.microservice.io.iface.ILogger;
......
package microservice.params; package common.microservice.params;
public class BaseClientParams public class BaseClientParams
{ {
......
package microservice.params; package common.microservice.params;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
......
package microservice.params; package common.microservice.params;
public class RMQClientParams extends BaseClientParams public class RMQClientParams extends BaseClientParams
{ {
......
package microservice.params; package common.microservice.params;
public class RestClientParams extends BaseClientParams public class RestClientParams extends BaseClientParams
{ {
......
package microservice.params; package common.microservice.params;
import java.util.Optional; import java.util.Optional;
......
package microservice.params; package common.microservice.params;
import jdk.nashorn.internal.ir.EmptyNode; //import jdk.nashorn.internal.ir.EmptyNode;
/** /**
* Created by amir on 14/05/17. * Created by amir on 14/05/17.
......
...@@ -3,10 +3,7 @@ package common.microservice.services; ...@@ -3,10 +3,7 @@ package common.microservice.services;
import common.microservice.context.CrudMethod; import common.microservice.context.CrudMethod;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import common.microservice.io.iface.IMetricsFactory; import common.microservice.io.iface.*;
import common.microservice.io.iface.IRequest;
import common.microservice.io.iface.IResponse;
import common.microservice.io.iface.IServiceDiscovery;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
...@@ -35,8 +32,8 @@ public class CommonServices { ...@@ -35,8 +32,8 @@ public class CommonServices {
public static abstract class IService { public static abstract class IService {
protected IServiceReactor reactor = null; protected IServiceReactor reactor = null;
protected IMetricsFactory metricsFactory = null; protected IMetricsFactory metricsFactory = null;
protected IApp app = null;
public abstract boolean init(); public abstract boolean init(IApp app);
public abstract void run(); public abstract void run();
public abstract void shutdown(); public abstract void shutdown();
public abstract void handleNotImplmented(IMsgContext msgContext); public abstract void handleNotImplmented(IMsgContext msgContext);
...@@ -339,4 +336,21 @@ public class CommonServices { ...@@ -339,4 +336,21 @@ public class CommonServices {
public abstract void stop() throws InterruptedException; public abstract void stop() throws InterruptedException;
} }
public static String buildServiceKey(CommonServices.MethodParams methodParams) {
return Constants.SLASH_SEPERATOR +
methodParams.getServiceType().name() + Constants.TYPE_PREFIX_SEPERATOR +
methodParams.getServiceCommand().toString() + Constants.TYPE_PREFIX_SEPERATOR +
methodParams.getResourceUri();
}
public static String buildServiceKey(Enums.EnumServiceType enumServiceType,
CommonServices.IServiceCommands serviceCommands,
String resourceUri) {
return new StringBuilder(32).append(Constants.SLASH_SEPERATOR).append(enumServiceType.name()).append(Constants.TYPE_PREFIX_SEPERATOR)
.append(serviceCommands.toString()).append(Constants.TYPE_PREFIX_SEPERATOR)
.append(resourceUri).toString();
}
} }
package common.microservice.utils;
import common.microservice.io.iface.ILogger;
public class Logging {
/**
* logging utils
*/
public static void logRcid(ILogger logger,String from, String rcid){
logger.info(from + " RCID: " + rcid);
}
public static void logMcid(ILogger logger,String from, String mcid){
logger.info(from + " MCID: " + mcid);
}
}
package microservice.services; package service.microservice;
import common.microservice.context.PubSubMsg; import common.microservice.context.PubSubMsg;
import common.microservice.defs.Constants; import common.microservice.defs.Constants;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import common.microservice.io.iface.IApp;
import common.microservice.io.iface.ILogger; import common.microservice.io.iface.ILogger;
import common.microservice.io.iface.IServiceDiscovery; import common.microservice.io.iface.IServiceDiscovery;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import common.microservice.utils.IDGenerator; import common.microservice.utils.IDGenerator;
import microservice.MicroserviceApp; import common.microservice.params.PulsarParams;
import microservice.handlers.Reactor;
import microservice.params.PulsarParams;
import org.apache.pulsar.client.admin.PulsarAdmin; import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException; import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.admin.Tenants; import org.apache.pulsar.client.admin.Tenants;
...@@ -28,6 +27,8 @@ import java.util.concurrent.ExecutorService; ...@@ -28,6 +27,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static common.microservice.services.CommonServices.buildServiceKey;
/** /**
* This class implements PubSubService for Apache Pulsar * This class implements PubSubService for Apache Pulsar
...@@ -81,16 +82,16 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService { ...@@ -81,16 +82,16 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService {
} }
@Override @Override
public boolean init() { public boolean init(IApp app) {
final MicroserviceApp microserviceApp = MicroserviceApp.getsInstance(); this.app = app;
if (microserviceApp != null) { if (app != null) {
clientId = microserviceApp.getAppName() + '-' clientId = app.getAppName() + '-'
+ microserviceApp.getServerName() + '-' + app.getServerName() + '-'
+ microserviceApp.getId(); + app.getId();
logger = MicroserviceApp.getsInstance().getLogger(); logger = app.getLogger();
namespacePrefix = TOPIC_PREFIX + "/" + microserviceApp.getAppName(); namespacePrefix = TOPIC_PREFIX + "/" + app.getAppName();
} else { } else {
// for tests where there is no MicroserviceApp // for tests where there is no MicroserviceApp
namespacePrefix = TOPIC_PREFIX + "/" + "testApp"; namespacePrefix = TOPIC_PREFIX + "/" + "testApp";
...@@ -167,7 +168,7 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService { ...@@ -167,7 +168,7 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService {
if (topic.length() > namespacePrefix.length() && if (topic.length() > namespacePrefix.length() &&
topic.startsWith(namespacePrefix)) { topic.startsWith(namespacePrefix)) {
topic = topic.substring(namespacePrefix.length()); topic = topic.substring(namespacePrefix.length());
String key = Reactor.buildServiceKey(Enums.EnumServiceType.E_PUBSUB, String key = buildServiceKey(Enums.EnumServiceType.E_PUBSUB,
CommonServices.EnumPubSubCommands.E_NOTIFY, CommonServices.EnumPubSubCommands.E_NOTIFY,
topic); topic);
reactor.delegate(this, key, msgCtx); reactor.delegate(this, key, msgCtx);
...@@ -334,9 +335,8 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService { ...@@ -334,9 +335,8 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService {
* wildcard topic: * wildcard topic:
* {persistent|non-persistent}://<tenant>/<namespace>/<regular expression> * {persistent|non-persistent}://<tenant>/<namespace>/<regular expression>
*/ */
final MicroserviceApp microserviceApp = MicroserviceApp.getsInstance();
String pattern = namespacePrefix + "/.*"; String pattern = namespacePrefix + "/.*";
adminValidateTenantAndNamespace(Constants.DEFAULT_TENANT,microserviceApp.getAppName()); adminValidateTenantAndNamespace(Constants.DEFAULT_TENANT,app.getAppName());
Pattern allTopicsInNamespace = Pattern.compile(pattern); Pattern allTopicsInNamespace = Pattern.compile(pattern);
consumer = client.newConsumer(JSONSchema.of(PubSubMsg.class)) consumer = client.newConsumer(JSONSchema.of(PubSubMsg.class))
.subscriptionName(clientId) .subscriptionName(clientId)
......
...@@ -4,10 +4,10 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -4,10 +4,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import common.microservice.io.iface.IRestClient; import common.microservice.io.iface.IRestClient;
import microservice.io.impl.IRMQClientRestImpl; import microservice.io.impl.IRMQClientRestImpl;
import microservice.params.BaseClientParams; import common.microservice.params.BaseClientParams;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import common.microservice.params.CommandParamsBuilder; import common.microservice.params.CommandParamsBuilder;
import microservice.params.RMQClientParams; import common.microservice.params.RMQClientParams;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import org.junit.Test; import org.junit.Test;
import rx.Observable; import rx.Observable;
......
...@@ -3,7 +3,7 @@ package microservice; ...@@ -3,7 +3,7 @@ package microservice;
import common.microservice.io.iface.ILogger; import common.microservice.io.iface.ILogger;
import microservice.io.impl.ILoggerConsoleImpl; import common.microservice.io.impl.ILoggerConsoleImpl;
import org.junit.Test; import org.junit.Test;
import java.time.LocalDateTime; import java.time.LocalDateTime;
......
...@@ -25,7 +25,7 @@ import org.junit.Test; ...@@ -25,7 +25,7 @@ import org.junit.Test;
import microservice.MicroserviceClient.EnumRestClientType; import microservice.MicroserviceClient.EnumRestClientType;
import common.microservice.params.CommandParams; import common.microservice.params.CommandParams;
import microservice.params.RestClientParams; import common.microservice.params.RestClientParams;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
......
package microservice; package microservice;
import clients.microservice.impl.IRestClientHttpImpl;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import common.microservice.context.RestContext; import common.microservice.context.RestContext;
import common.microservice.defs.Enums; import common.microservice.defs.Enums;
import common.microservice.params.CommandParams;
import common.microservice.services.CommonServices;
import common.microservice.io.iface.IRestClient; import common.microservice.io.iface.IRestClient;
import microservice.io.impl.*; import common.microservice.params.*;
import microservice.services.IRestServiceHttpImpl; import common.microservice.services.CommonServices;
import microservice.params.*;
import microservice.services.IRestServiceZmqImpl;
import common.microservice.types.BaseRestResponse; import common.microservice.types.BaseRestResponse;
import microservice.io.impl.IRestServerRMQImpl;
import microservice.io.impl.IRestServerUndertowImpl;
import microservice.io.impl.IServiceDiscoveryConsulImpl;
import microservice.service.pubsub.impl.IRestServiceHttpImpl;
import microservice.service.pubsub.impl.IRestServiceZmqImpl;
import microservice.utils.ServiceBuilderFactory; import microservice.utils.ServiceBuilderFactory;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import org.junit.Test; import org.junit.Test;
...@@ -38,7 +39,7 @@ public class TestMicroserviceApp { ...@@ -38,7 +39,7 @@ public class TestMicroserviceApp {
String appName = "testApp"; String appName = "testApp";
//ILogger logger = new ILogger4jImpl(appName); //ILogger logger = new ILogger4jImpl(appName);
microservice.MicroserviceApp msApp = new microservice.MicroserviceApp(appName); MicroserviceApp msApp = new microservice.MicroserviceApp(appName);
msApp.withMetrics() msApp.withMetrics()
//.withDefaultServiceAuthorization() //.withDefaultServiceAuthorization()
.withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0)) .withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0))
......
...@@ -14,7 +14,7 @@ import com.google.common.cache.CacheBuilder; ...@@ -14,7 +14,7 @@ import com.google.common.cache.CacheBuilder;
import common.JsonHandler; import common.JsonHandler;
import io.undertow.predicate.Predicate; import io.undertow.predicate.Predicate;
import io.undertow.util.PathMatcher; import io.undertow.util.PathMatcher;
import microservice.params.ZMQParams; import common.microservice.params.ZMQParams;
import common.microservice.services.CommonServices; import common.microservice.services.CommonServices;
import microservice.utils.ServiceBuilderFactory; import microservice.utils.ServiceBuilderFactory;
......
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