-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tag 2021.01.17 add neo4j by spring data simple case for curreng guied…
…es. committer:陈晨
- Loading branch information
Showing
13 changed files
with
319 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### Open-Telemetry-Simple-Neo4j 案例工程 | ||
|
||
> Open-Telemetry-Simple-Neo4j 实际测试了 SpringData下的 Neo4j 。 | ||
##### 测试模块快速开始 | ||
|
||
1. 确保[Guides 案例工程下的步骤](../README.md)执行完毕。 | ||
|
||
2. 启动此模块[otel-simple-neo4j](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/otel-simple-neo4j/src/main/java/org/chenmudu/otel/neo4j)下的Neo4jRunMain. | ||
|
||
3. 访问http://localhost:10010/dataNeo4j。 | ||
|
||
4. Copy Console 中的 TraceId访问 http://localhost:16686/ 即可观测结果。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>open-telemetry-java-guides</artifactId> | ||
<groupId>org.chenmudu.otel</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.chenmudu.otel.neo4j</groupId> | ||
<artifactId>otel-simple-neo4j</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-neo4j</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
otel-simple-neo4j/src/main/java/org/chenmudu/otel/neo4j/Neo4jRunMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/13 00:15 | ||
*/ | ||
@SpringBootApplication | ||
public class Neo4jRunMain { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Neo4jRunMain.class, args); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...e-neo4j/src/main/java/org/chenmudu/otel/neo4j/controller/OtelTestDataNeo4jController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j.controller; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.chenmudu.otel.neo4j.entity.DeptEntity; | ||
import org.chenmudu.otel.neo4j.repository.DeptRepository; | ||
import org.chenmudu.otel.neo4j.repository.RelationShipRepository; | ||
import org.chenmudu.otel.neo4j.ship.RelationShip; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/15 23:19 | ||
*/ | ||
@Slf4j | ||
@RestController | ||
public class OtelTestDataNeo4jController { | ||
|
||
@Resource | ||
private DeptRepository deptRepository; | ||
@Resource | ||
private RelationShipRepository relationShipRepository; | ||
|
||
@GetMapping("/dataNeo4j") | ||
public String dataNeo4j() { | ||
DeptEntity ceo = DeptEntity.builder().name("CEO").build(); | ||
DeptEntity tech = DeptEntity.builder().name("Tech").build(); | ||
DeptEntity design = DeptEntity.builder().name("Design").build(); | ||
DeptEntity techChen = DeptEntity.builder().name("T_Zhang").build(); | ||
DeptEntity techLi = DeptEntity.builder().name("T_Li").build(); | ||
DeptEntity designWang = DeptEntity.builder().name("D_Wang").build(); | ||
|
||
deptRepository.saveAll(Arrays.asList(ceo, tech, design, techChen, techLi, designWang)); | ||
log.info("OtelTestDataNeo4jController dataNeo4j save all node!"); | ||
|
||
RelationShip ceo2Tech = RelationShip.builder().startNode(ceo).endNode(tech).build(); | ||
RelationShip ceo2Design = RelationShip.builder().startNode(ceo).endNode(design).build(); | ||
|
||
RelationShip tech2Chen = RelationShip.builder().startNode(tech).endNode(techChen).build(); | ||
RelationShip tech2Li = RelationShip.builder().startNode(tech).endNode(techLi).build(); | ||
|
||
RelationShip design2Wang = RelationShip.builder().startNode(design).endNode(designWang) | ||
.build(); | ||
relationShipRepository.saveAll(Arrays.asList(ceo2Tech, ceo2Design, tech2Chen, tech2Li, | ||
design2Wang)); | ||
|
||
Optional<RelationShip> shipOptional = relationShipRepository.findById(tech2Chen.getId()); | ||
|
||
return shipOptional.orElse(null).toString(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
otel-simple-neo4j/src/main/java/org/chenmudu/otel/neo4j/entity/DeptEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j.entity; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.neo4j.ogm.annotation.GeneratedValue; | ||
import org.neo4j.ogm.annotation.Id; | ||
import org.neo4j.ogm.annotation.NodeEntity; | ||
import org.neo4j.ogm.annotation.Property; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/15 23:25 | ||
*/ | ||
@NodeEntity(label = "dept") | ||
@Data | ||
@Builder | ||
public class DeptEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Property(name = "deptName") | ||
private String name; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
otel-simple-neo4j/src/main/java/org/chenmudu/otel/neo4j/repository/DeptRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j.repository; | ||
|
||
import org.chenmudu.otel.neo4j.entity.DeptEntity; | ||
import org.springframework.data.neo4j.repository.Neo4jRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/15 23:40 | ||
*/ | ||
@Repository | ||
public interface DeptRepository extends Neo4jRepository<DeptEntity, Long> { | ||
} |
28 changes: 28 additions & 0 deletions
28
...simple-neo4j/src/main/java/org/chenmudu/otel/neo4j/repository/RelationShipRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j.repository; | ||
|
||
import org.chenmudu.otel.neo4j.ship.RelationShip; | ||
import org.springframework.data.neo4j.repository.Neo4jRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/15 23:38 | ||
*/ | ||
@Repository | ||
public interface RelationShipRepository extends Neo4jRepository<RelationShip, Long> { | ||
} |
45 changes: 45 additions & 0 deletions
45
otel-simple-neo4j/src/main/java/org/chenmudu/otel/neo4j/ship/RelationShip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* MIT License | ||
* <p> | ||
* Copyright (c) 2020 chenmudu (陈晨) | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* <p> | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
package org.chenmudu.otel.neo4j.ship; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.chenmudu.otel.neo4j.entity.DeptEntity; | ||
import org.neo4j.ogm.annotation.EndNode; | ||
import org.neo4j.ogm.annotation.GeneratedValue; | ||
import org.neo4j.ogm.annotation.Id; | ||
import org.neo4j.ogm.annotation.RelationshipEntity; | ||
import org.neo4j.ogm.annotation.StartNode; | ||
|
||
/** | ||
* | ||
* @author [email protected] 2021/1/15 23:34 | ||
*/ | ||
@RelationshipEntity(type = "relationShip") | ||
@Data | ||
@Builder | ||
public class RelationShip { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@StartNode | ||
private DeptEntity startNode; // parent node. | ||
|
||
@EndNode | ||
private DeptEntity endNode; //end node. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
server.port=10010 | ||
|
||
spring.application.name=otel-simple-neo4j | ||
|
||
#neo4j by spring data. | ||
spring.data.neo4j.uri=bolt://xxx.xx.xx.xx:7687 | ||
spring.data.neo4j.username=xxx | ||
spring.data.neo4j.password=xxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<configuration> | ||
<jmxConfigurator/> | ||
<property name="charset" value="UTF-8" /> | ||
<property name="pattern" | ||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] - [%X{traceId},%X{spanId}]- %logger{30}.%method:%line %msg%n" /> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>${pattern}</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters