Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yangyoupeng
/
microservice
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yangyoupeng
2016-10-26 17:35:24 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0edd6b61e62301c0907291bb21eeed205748bcce
0edd6b61
1 parent
50f35080
1microservice-monitor组件。添加入口方法:Application,旨在让monitor也作为独立的服务发布。
2.添加monitor使用的配置文件。
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
200 additions
and
31 deletions
src/microservice-parent/microservice-framework-core/pom.xml
src/microservice-parent/microservice-framework-monitor/pom.xml
src/microservice-parent/microservice-framework-monitor/src/main/java/com/zhaoonline/microservice/framework/monitor/main/Application.java
src/microservice-parent/microservice-framework-monitor/src/main/resources/application.properties
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-bean.xml
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-config.xml → src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-client-config.xml
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-repo-config.xml → src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-service-config.xml
src/microservice-parent/microservice-framework-monitor/src/test/java/com/zhaoonline/microservice/framework/monitor/es/CreateIndexWithMapping.java
src/microservice-parent/microservice-msq/pom.xml
src/microservice-parent/microservice-msq/src/test/java/com/zhaoonline/message/test/queue/TestAliyunMNS.java
src/microservice-parent/pom.xml
src/microservice-parent/support-gateway/src/main/resources/application.properties
src/microservice-parent/support-gateway/src/main/resources/elastic-config.xml
src/microservice-parent/support-gateway/src/test/java/com/zhaoonline/support/gateway/security/ESUserInfoReposityUtils.java
src/microservice-parent/support-gateway/src/test/java/com/zhaoonline/support/gateway/service/ESServiceInfoLoaderUtils.java
src/microservice-parent/microservice-framework-core/pom.xml
View file @
0edd6b6
...
...
@@ -18,8 +18,9 @@
<artifactId>
alpaca-config-zookeeper
</artifactId>
</dependency>
<dependency>
<groupId>
com.esotericsoftware
.kryo
</groupId>
<groupId>
com.esotericsoftware
</groupId>
<artifactId>
kryo
</artifactId>
<version>
3.0.3
</version>
</dependency>
<dependency>
<groupId>
de.javakaffee
</groupId>
...
...
src/microservice-parent/microservice-framework-monitor/pom.xml
View file @
0edd6b6
...
...
@@ -15,6 +15,12 @@
<groupId>
com.zhaoonline
</groupId>
<artifactId>
microservice-framework-core
</artifactId>
<version>
${project.version}
</version>
<exclusions>
<exclusion>
<groupId>
com.zhaoonline
</groupId>
<artifactId>
alpaca-config-zookeeper
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
...
...
@@ -80,6 +86,16 @@
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.1
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-checkstyle-plugin
</artifactId>
<version>
2.17
</version>
...
...
@@ -100,6 +116,25 @@
</execution>
</executions>
</plugin>
<!-- 是为了将工程打包runnable jar包 ,如果不指定mainClass,那么maven就会搜索包含main方法的类。 -->
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<mainClass>
com.zhaoonline.support.gateway.main.Application
</mainClass>
<addResources>
true
</addResources>
<layout>
jar
</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
...
src/microservice-parent/microservice-framework-monitor/src/main/java/com/zhaoonline/microservice/framework/monitor/main/Application.java
0 → 100644
View file @
0edd6b6
package
com
.
zhaoonline
.
microservice
.
framework
.
monitor
.
main
;
import
java.util.concurrent.CountDownLatch
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.ImportResource
;
import
org.springframework.context.annotation.Lazy
;
@Configuration
@EnableAutoConfiguration
@ComponentScan
(
basePackages
=
"com.zhaoonline.microservice.framework.monitor"
)
@ImportResource
(
locations
={
"classpath:trace-service-config.xml"
})
public
class
Application
{
@Bean
@Lazy
public
CountDownLatch
closeLatch
()
{
return
new
CountDownLatch
(
1
);
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
SpringApplication
app
=
new
SpringApplication
(
Application
.
class
);
app
.
setRegisterShutdownHook
(
false
);
boolean
isWeb
=
false
;
app
.
setWebEnvironment
(
isWeb
);
app
.
setBannerMode
(
Banner
.
Mode
.
OFF
);
ConfigurableApplicationContext
context
=
app
.
run
(
args
);
if
(!
isWeb
){
becomeDeamon
(
context
);
}
}
private
static
void
becomeDeamon
(
ConfigurableApplicationContext
context
)
throws
InterruptedException
{
CountDownLatch
closeLatch
=
context
.
getBean
(
CountDownLatch
.
class
);
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
closeLatch
.
countDown
();
}
}));
closeLatch
.
await
();
context
.
close
();
System
.
exit
(
0
);
}
}
src/microservice-parent/microservice-framework-monitor/src/main/resources/application.properties
0 → 100644
View file @
0edd6b6
spring.application.name
=
servicemonitor
es.host
=
192.168.0.162
es.port
=
9300
zookeeper.hostport
=
zookeeper://192.168.0.91:2181?client=curator
\ No newline at end of file
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-bean.xml
0 → 100644
View file @
0edd6b6
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo=
"http://code.alibabatech.com/schema/dubbo"
xmlns:util=
"http://www.springframework.org/schema/util"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd"
>
<bean
id=
"esConfiguration"
class=
"com.zhaoonline.microservice.framework.monitor.es.ElasticConfiguration"
>
<property
name=
"clusterName"
value=
"zhaoonline"
></property>
<property
name=
"hostPorts"
>
<map>
<entry
key=
"${es.host}"
value=
"${es.port}"
/>
</map>
</property>
</bean>
<bean
id=
"esClient"
class=
"com.zhaoonline.microservice.framework.monitor.es.ElasticClientFactory"
factory-method=
"createClient"
>
<constructor-arg
ref=
"esConfiguration"
/>
</bean>
<bean
id=
"appserRepo"
class=
"com.zhaoonline.microservice.framework.monitor.repo.AppServiceRepo"
>
<property
name=
"client"
ref=
"esClient"
></property>
</bean>
<bean
id=
"seedRep"
class=
"com.zhaoonline.microservice.framework.monitor.repo.SeedRepo"
>
<property
name=
"client"
ref=
"esClient"
></property>
</bean>
<bean
id=
"metaInfoRep"
class=
"com.zhaoonline.microservice.framework.monitor.repo.ESMetaInfoRepositoryService"
>
<property
name=
"appserRepo"
ref=
"appserRepo"
></property>
<property
name=
"seedRep"
ref=
"seedRep"
></property>
</bean>
<bean
id=
"spanRep"
class=
"com.zhaoonline.microservice.framework.monitor.repo.ESSpanInfoRepositoryService"
>
<property
name=
"client"
ref=
"esClient"
></property>
</bean>
<!--
<bean id="traceService" class="com.zhaoonline.microservice.framework.monitor.service.TraceService">
<property name="spanRep" ref="spanRep"></property>
<property name="metaInfoRep" ref="metaInfoRep"></property>
</bean>
<bean id="transfer" class="com.zhaoonline.microservice.framework.monitor.service.DefaultSyncTransfer">
<property name="traceService" ref="traceService"/>
<constructor-arg ref="configuration"/>
</bean>
<bean id="tracer" class="com.zhaoonline.microservice.framework.monitor.trace.Tracer" factory-method="getTracer">
<property name="traceService" ref="traceService"/>
<property name="transfer" ref="transfer"/>
</bean>
-->
</beans>
\ No newline at end of file
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-config.xml
→
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-c
lient-c
onfig.xml
View file @
0edd6b6
...
...
@@ -26,14 +26,14 @@
</dubbo:reference>
<bean
id=
"traceService"
class=
"com.zhaoonline.microservice.framework.monitor.service.TraceService"
>
<property
name=
"metaInfoRep"
ref=
"
hydraService
"
></property>
<property
name=
"spanRep"
ref=
"
leaderService
"
></property>
<property
name=
"metaInfoRep"
ref=
"
metaInfoRep
"
></property>
<property
name=
"spanRep"
ref=
"
spanRep
"
></property>
</bean>
<bean
id=
"transfer"
class=
"com.zhaoonline.microservice.framework.monitor.service.DefaultSyncTransfer"
>
<property
name=
"traceService"
ref=
"traceService"
/>
<constructor-arg
ref=
"configuration"
/>
</bean>
<!--被
Hydra
Filter使用-->
<!--被
Zhaotracer
Filter使用-->
<bean
id=
"tracer"
class=
"com.zhaoonline.microservice.framework.monitor.trace.Tracer"
factory-method=
"getTracer"
>
<property
name=
"traceService"
ref=
"traceService"
/>
<property
name=
"transfer"
ref=
"transfer"
/>
...
...
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-
repo
-config.xml
→
src/microservice-parent/microservice-framework-monitor/src/main/resources/trace-
service
-config.xml
View file @
0edd6b6
...
...
@@ -7,14 +7,14 @@
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
>
<
dubbo:application
name=
"monitor-repository"
/>
<
import
resource=
"classpath:trace-bean.xml"
/>
<dubbo:
registry
address=
"multicast://224.5.6.7:1234"
/>
<dubbo:
application
name=
"${spring.application.name}"
/>
<dubbo:
protocol
name=
"dubbo"
port=
"20880
"
/>
<dubbo:
registry
address=
"${zookeeper.hostport}
"
/>
<dubbo:service
interface=
"com.zhaoonline.microservice.framework.monitor.repo.SpanInfoRepositoryService"
ref=
"
es
Rep"
/>
<dubbo:service
interface=
"com.zhaoonline.microservice.framework.monitor.repo.SpanInfoRepositoryService"
ref=
"
span
Rep"
/>
<
bean
id=
"esRep"
class=
"com.zhaoonline.microservice.framework.monitor.repo.ESSpanInfoRepositoryService"
/>
<
dubbo:service
interface=
"com.zhaoonline.microservice.framework.monitor.repo.MetaInfoRepositoryService"
ref=
"metaInfoRep"
/>
</beans>
\ No newline at end of file
...
...
src/microservice-parent/microservice-framework-monitor/src/test/java/com/zhaoonline/microservice/framework/monitor/es/CreateIndexWithMapping.java
View file @
0edd6b6
...
...
@@ -11,6 +11,7 @@ import org.elasticsearch.client.transport.TransportClient;
import
org.elasticsearch.common.xcontent.XContentBuilder
;
import
org.elasticsearch.common.xcontent.json.JsonXContent
;
public
class
CreateIndexWithMapping
{
private
TransportClient
client
;
...
...
@@ -26,7 +27,7 @@ public class CreateIndexWithMapping {
ElasticConfiguration
config
=
new
ElasticConfiguration
();
config
.
setClusterName
(
"zhaoonline"
);
Map
<
String
,
Integer
>
hostPorts
=
new
HashMap
<
String
,
Integer
>();
hostPorts
.
put
(
"1
27.0.0.1
"
,
9300
);
hostPorts
.
put
(
"1
92.168.0.162
"
,
9300
);
config
.
setHostPorts
(
hostPorts
);
TransportClient
client
=
ElasticClientFactory
.
createClient
(
config
);
...
...
src/microservice-parent/microservice-msq/pom.xml
View file @
0edd6b6
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.zhaoonline
</groupId>
<artifactId>
microservice-parent
</artifactId>
<version>
0.0.1
-SNAPSHOT
</version>
<version>
1.0.0
-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<artifactId>
microservice-msq
</artifactId>
...
...
src/microservice-parent/microservice-msq/src/test/java/com/zhaoonline/message/test/queue/TestAliyunMNS.java
View file @
0edd6b6
...
...
@@ -73,12 +73,12 @@ public class TestAliyunMNS {
String
messageBody
=
"broadcast message to all the consumers:hello the world."
;
//
TopicMessage tMessage = new RawTopicMessage();
//
tMessage.setBaseMessageBody(messageBody);
//
tMessage.setBaseMessageBody(messageBody);
//
pullTopic.publishMessage(tMessage);
//
tMessage.setBaseMessageBody("second message.");
//
pullTopic.publishMessage(tMessage);
TopicMessage
tMessage
=
new
RawTopicMessage
();
tMessage
.
setBaseMessageBody
(
messageBody
);
tMessage
.
setBaseMessageBody
(
messageBody
);
pullTopic
.
publishMessage
(
tMessage
);
tMessage
.
setBaseMessageBody
(
"second message."
);
pullTopic
.
publishMessage
(
tMessage
);
// CloudQueue queueForConsumer1 = client.getQueueRef("consumer001");
...
...
src/microservice-parent/pom.xml
View file @
0edd6b6
...
...
@@ -218,12 +218,22 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<version>
3.0.1
</version>
<configuration>
<encoding>
UTF-8
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
3.0.0
</version>
<configuration>
<attach>
true
</attach>
<encoding>
UTF-8
</encoding>
</configuration>
<executions>
<execution>
...
...
src/microservice-parent/support-gateway/src/main/resources/application.properties
View file @
0edd6b6
application.message
=
Hello ZhaoOnline
application.message
=
\u
8D75
\u
6D8C
\u5728\u
7EBFAPI GateWay
\u
6B22
\u
8FCE
\u
60A8
spring.application.name
=
apigateway
server.port
=
80
90
server.port
=
80
spring.mvc.view.prefix
:
/WEB-INF/view/
spring.mvc.view.suffix
:
.jsp
...
...
src/microservice-parent/support-gateway/src/main/resources/elastic-config.xml
View file @
0edd6b6
...
...
@@ -11,7 +11,7 @@
<property
name=
"clusterName"
value=
"zhaoonline"
></property>
<property
name=
"hostPorts"
>
<map>
<entry
key=
"1
27.0.0.1
"
value=
"9300"
/>
<entry
key=
"1
92.168.0.162
"
value=
"9300"
/>
</map>
</property>
</bean>
...
...
src/microservice-parent/support-gateway/src/test/java/com/zhaoonline/support/gateway/security/ESUserInfoReposityUtils.java
View file @
0edd6b6
...
...
@@ -15,7 +15,7 @@ public class ESUserInfoReposityUtils {
ElasticConfiguration
config
=
new
ElasticConfiguration
();
config
.
setClusterName
(
"zhaoonline"
);
Map
<
String
,
Integer
>
hostPorts
=
new
HashMap
<>();
hostPorts
.
put
(
"1
27.0.0.1
"
,
9300
);
hostPorts
.
put
(
"1
92.168.0.162
"
,
9300
);
config
.
setHostPorts
(
hostPorts
);
TransportClient
clinet
=
ElasticClientFactory
.
createClient
(
config
);
...
...
@@ -23,7 +23,7 @@ public class ESUserInfoReposityUtils {
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setUserName
(
"test"
);
userInfo
.
setPassword
(
"
passward
"
);
userInfo
.
setPassword
(
"
123456
"
);
userInfo
.
setEnabled
(
true
);
IndexResponse
indexResponse
=
esUserInfoReposity
.
addUser
(
userInfo
);
...
...
src/microservice-parent/support-gateway/src/test/java/com/zhaoonline/support/gateway/service/ESServiceInfoLoaderUtils.java
View file @
0edd6b6
...
...
@@ -19,18 +19,21 @@ public static void main(String[] args) throws JsonProcessingException {
ElasticConfiguration
config
=
new
ElasticConfiguration
();
config
.
setClusterName
(
"zhaoonline"
);
Map
<
String
,
Integer
>
hostPorts
=
new
HashMap
<>();
hostPorts
.
put
(
"1
27.0.0.1
"
,
9300
);
hostPorts
.
put
(
"1
92.168.0.162
"
,
9300
);
config
.
setHostPorts
(
hostPorts
);
TransportClient
clinet
=
ElasticClientFactory
.
createClient
(
config
);
ESServiceInfoLoader
esUserInfoReposity
=
new
ESServiceInfoLoader
(
clinet
);
ServiceInfo
newServiceInfo
=
localHttpService
(
"wxtest"
);
boolean
indexResponse
=
esUserInfoReposity
.
addServiceInfo
(
newServiceInfo
);
// ServiceInfo serviceInfo=esUserInfoReposity.findServiceInfo("dubbo2");
// System.out.println(serviceInfo);
for
(
int
i
=
0
;
i
<
100
;
i
++){
ServiceInfo
newServiceInfo
=
dubboService
(
"dubbo"
+
i
);
boolean
indexResponse
=
esUserInfoReposity
.
addServiceInfo
(
newServiceInfo
);
}
//
for(int i=0;i<100;i++){
//
ServiceInfo newServiceInfo = dubboService("dubbo"+i);
//
boolean indexResponse=esUserInfoReposity.addServiceInfo(newServiceInfo);
//
}
// esUserInfoReposity.deleteServiceInfoByID("AVdQXuvQOMXcvNgV3j29");
}
...
...
@@ -63,16 +66,16 @@ private static ServiceInfo dubboService(String serviceName) {
return
servicInfo
;
}
private
static
ServiceInfo
localHttpService
()
{
private
static
ServiceInfo
localHttpService
(
String
serviceName
)
{
ServiceInfo
newServiceInfo
=
new
ServiceInfo
();
newServiceInfo
.
setValid
(
true
);
newServiceInfo
.
setServiceName
(
"hello"
);
newServiceInfo
.
setServiceName
(
serviceName
);
newServiceInfo
.
setServiceType
(
"HTTP"
);
List
<
HostPort
>
hostposts
=
new
ArrayList
<
HostPort
>();
HostPort
hp
=
new
HostPort
();
hp
.
setHost
(
"1
27.0.0.1
"
);
hp
.
setPort
(
9
080
);
hp
.
setHost
(
"1
92.168.0.92
"
);
hp
.
setPort
(
9
858
);
hostposts
.
add
(
hp
);
newServiceInfo
.
setHostports
(
hostposts
);
...
...
Please
register
or
login
to post a comment