nebula-java 自定义cypher接口查询

有nebula-java链接nebula graph自定义cypher查询接口的案例吗,想参考下

如果是 web service 到给定 space 的服务,做 space 内的数据读写,用 session pool

https://github.com/vesoft-inc/nebula-java/blob/master/examples/src/main/java/com/vesoft/nebula/examples/GraphSessionPoolExample.java

如果涉及跨 space 请求,用底层一点的 connection_pool 的话也可以,获得一个 session 然后可以 execute() 字符串查询,之后要记得把 session release。

https://github.com/vesoft-inc/nebula-java/blob/1eb0e16073bcc1b9e77feef989f7238831202941/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java#L100-L110

https://github.com/vesoft-inc/nebula-java/blob/master/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java

1 个赞

这个适合生产环境开发一些接口使用吗

可以的,nebula-java 就是官方出品的。

好的 谢谢


如果是三个节点的集群,这个地址怎么写呢


帮忙看下

报错信息去论坛搜下哈

这个忘记回了,aslist 后面就是个数组,你只要参考这种形式就行了

(new hostaddress(host:“127.0.0.1”,port:9669),new hostaddress(host:“127.0.0.2”,port:9669),new hostaddress(host:“127.0.0.3”,port:9669))

ip 记得改成你的节点的 ip,端口号记得也改下。

报错信息可以文本贴一下吗?

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/dillon.wang/Downloads/workspace/xiaoying/nebula-java/examples -Dmaven.home=/Users/dillon.wang/Downloads/software/apache-maven-3.5.4 -Dclassworlds.conf=/Users/dillon.wang/Downloads/software/apache-maven-3.5.4/bin/m2.conf -Dmaven.ext.class.path=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven-event-listener.jar -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58949:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/dillon.wang/Downloads/software/apache-maven-3.5.4/boot/plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2021.1.3 package
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.vesoft:examples:jar:3.0-SNAPSHOT
[WARNING] The expression ${parent.version} is deprecated. Please use ${project.parent.version} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] Inspecting build with total of 1 modules...
[INFO] Not installing Nexus Staging features:
[INFO]  * Preexisting staging related goal bindings found in 1 modules.
[INFO] 
[INFO] ------------------------< com.vesoft:examples >-------------------------
[INFO] Building examples 3.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for com.vesoft:client:jar:3.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.584 s
[INFO] Finished at: 2022-11-30T17:39:08+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project examples: Could not resolve dependencies for project com.vesoft:examples:jar:3.0-SNAPSHOT: Could not find artifact com.vesoft:client:jar:3.0-SNAPSHOT -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Process finished with exit code 1
<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.vesoft</groupId>
    <artifactId>nebula</artifactId>
    <packaging>pom</packaging>
    <version>3.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jts.version>1.16.1</jts.version>
    </properties>

    <!-- More Project Information -->
    <name>nebula-java</name>
    <description>Nebula Java Client 2.0</description>
    <url>https://github.com/vesoft-inc/nebula-java</url>
    <scm>
        <connection>scm:git:https://github.com/vesoft-inc/nebula-java</connection>
        <url>https://github.com/vesoft-inc/nebula-java</url>
        <developerConnection>scm:git:https://github.com/vesoft-inc/nebula-java</developerConnection>
    </scm>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>license</comments>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>nebula</id>
            <name>Nebula Graph</name>
            <email>nebula-java@vesoft-inc.com</email>
            <organization>vesoft</organization>
            <roles>
                <role>architect</role>
                <role>developer</role>
            </roles>
        </developer>
    </developers>
    <modules>
        <module>client</module>
        <module>examples</module>
    </modules>

    <profiles>
        <!-- Deployment profile (required so these plugins are only used when deploying) -->
        <profile>
            <id>deploy</id>
            <build>
                <plugins>
                    <!-- Source plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.2.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Javadoc plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.2.0</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- GPG plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <!-- Prevent `gpg` from using pinentry programs -->
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


    <distributionManagement>
        <repository>
            <id>ossrh</id>
            <name>Nexus Release Repository</name>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>ossrh</id>
            <name>Nexus Snapshot Repository</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <!-- Nexus Staging Plugin -->
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.7</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

官网直接下载下来的

来,看下这个。(顺便)我用了 snapshot 做关键词搜的。

嗯嗯好的 编译通过了,但是运行 还是找不到这个包

稍等,我让研发明天给你看看哈。

本地编译一下,不要只编译example这个module, 要编译root。 是idea的问题

1 个赞