TinkerPop SDK连接JanusGraph配置


import static org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1.TOKEN_SERIALIZE_RESULT_TO_STRING;

import java.util.HashMap;
import java.util.Map;
import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
import org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1;
import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * Gremlin配置
 *
 */
@ConditionalOnProperty(value = "gremlin.enabled", havingValue = "true")
@Configuration
public class GremlinConfig {

    @Autowired
    private Environment env;


    @Bean
    public Cluster cluster() {
        String gremlinServerIp = env.getProperty("gremlinServerIp");
        Integer gremlinServerPort = Integer.parseInt(env.getProperty("gremlinServerPort"));
        String gremlinServerUserName = env.getProperty("gremlinServerUserName");
        String gremlinServerPassword = env.getProperty("gremlinServerPassword");

        // 设置正确的 serializer
        MessageSerializer serializer = new GraphBinaryMessageSerializerV1();
        Map config = new HashMap<>();
        config.put(TOKEN_SERIALIZE_RESULT_TO_STRING, true);
        serializer.configure(config, null);
        Cluster cluster = Cluster.build()
                .addContactPoint(gremlinServerIp).port(gremlinServerPort)
                .credentials(gremlinServerUserName, gremlinServerPassword)
                .serializer(serializer)
                .create();
        return cluster;
    }

    @Bean
    public Client client(Cluster cluster) {
        Client client = cluster.connect();
        return client;
    }
    
}

pom依赖配置

            
                org.apache.tinkerpop
                gremlin-core
                3.6.2
            
            
                org.apache.tinkerpop
                gremlin-driver
                3.6.2
            

你可能感兴趣的:(java,spring,spring,boot,Gremlin,图数据库)