Skip to content

Commit

Permalink
tag 2021.01.17 add neo4j by spring data simple case for curreng guied…
Browse files Browse the repository at this point in the history
…es. committer:陈晨
  • Loading branch information
chenmudu committed Jan 16, 2021
1 parent 545219d commit 72eb013
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name
* [Open-Telemetry-Java 示例工程(基于 Spring Data 示例Data系列)](otel-simple-spring-data)
* [Open-Telemetry-Java 示例工程(基于 Spring Amqp 示例RabbitMq)](otel-simple-rabbit)
* [Open-Telemetry-Java 示例工程(基于 Spring Kafka 示例KafkaMq)](otel-simple-kafka)
* [Open-Telemetry-Java 示例工程(基于 Spring Neo4j 示例Neo4j)](otel-simple-neo4j)
* [Open-Telemetry-Java 示例工程(关于 Otel Collector 个人配置参考)](https://github.com/chenmudu/open-telemetry-java-guides/tree/master/config/otel-col-config.yaml)

#### 测试环境
Expand Down Expand Up @@ -147,7 +148,7 @@ OTEL_RESOURCE_ATTRIBUTES=service.name=your service name
| Jedis-Client | 2.9.0 |Y | 1.4+ |
| Redisson-Client | 0.0.0 |N 还未测试 | 3.0+ |
| Spring-data-Es | 2.1.14(3.1.17.RELEASE) |Y | 1.8+ |
| Spring-data-Neo4j | 2.1.14(5.1.17.RELEASE) |N 还未测试 | 1.8+ |
| Spring-data-Neo4j | 2.1.14(5.1.17.RELEASE) |N | 1.8+ |
| Spring-Rabbit | 2.1.14(2.1.14.RELEASE) |Y ||
| Rabbit-Client | 5.4.3 |Y | 2.7+ |
| Spring-Kafka | 2.1.13 |Y ||
Expand Down
13 changes: 13 additions & 0 deletions otel-simple-neo4j/README.md
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/ 即可观测结果。
36 changes: 36 additions & 0 deletions otel-simple-neo4j/pom.xml
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>
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);
}
}
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();
}

}
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;

}
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> {
}
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> {
}
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.
}
8 changes: 8 additions & 0 deletions otel-simple-neo4j/src/main/resources/application.properties
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
15 changes: 15 additions & 0 deletions otel-simple-neo4j/src/main/resources/logback.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ spring.data.elasticsearch.cluster-nodes=${spring.local.ip}:9300

spring.main.allow-bean-definition-overriding=true

## data-neo4j
# data-neo4j
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<module>otel-simple-tailbase</module>
<module>otel-simple-webflux</module>
<module>otel-simple-webmvc</module>
<module>otel-simple-neo4j</module>
</modules>

<dependencyManagement>
Expand Down

0 comments on commit 72eb013

Please sign in to comment.