yangyoupeng

1microservice-monitor组件。添加入口方法:Application,旨在让monitor也作为独立的服务发布。

2.添加monitor使用的配置文件。
Showing 15 changed files with 200 additions and 31 deletions
......@@ -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>
......
......@@ -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>
......
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);
}
}
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
<?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
......@@ -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>
<!--被HydraFilter使用-->
<!--被ZhaotracerFilter使用-->
<bean id="tracer" class="com.zhaoonline.microservice.framework.monitor.trace.Tracer" factory-method="getTracer">
<property name="traceService" ref="traceService"/>
<property name="transfer" ref="transfer"/>
......
......@@ -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="esRep" />
<dubbo:service interface="com.zhaoonline.microservice.framework.monitor.repo.SpanInfoRepositoryService" ref="spanRep" />
<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
......
......@@ -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("127.0.0.1", 9300);
hostPorts.put("192.168.0.162", 9300);
config.setHostPorts(hostPorts);
TransportClient client=ElasticClientFactory.createClient(config);
......
......@@ -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>
......
......@@ -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");
......
......@@ -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>
......
application.message=Hello ZhaoOnline
application.message=\u8D75\u6D8C\u5728\u7EBFAPI GateWay\u6B22\u8FCE\u60A8
spring.application.name=apigateway
server.port=8090
server.port=80
spring.mvc.view.prefix: /WEB-INF/view/
spring.mvc.view.suffix: .jsp
......
......@@ -11,7 +11,7 @@
<property name="clusterName" value="zhaoonline"></property>
<property name="hostPorts">
<map>
<entry key="127.0.0.1" value="9300"/>
<entry key="192.168.0.162" value="9300"/>
</map>
</property>
</bean>
......
......@@ -15,7 +15,7 @@ public class ESUserInfoReposityUtils {
ElasticConfiguration config=new ElasticConfiguration();
config.setClusterName("zhaoonline");
Map<String, Integer> hostPorts=new HashMap<>();
hostPorts.put("127.0.0.1", 9300);
hostPorts.put("192.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);
......
......@@ -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("127.0.0.1", 9300);
hostPorts.put("192.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("127.0.0.1");
hp.setPort(9080);
hp.setHost("192.168.0.92");
hp.setPort(9858);
hostposts.add(hp);
newServiceInfo.setHostports(hostposts);
......