Bulbs python 连接远程 TitanDB + Rexster

1 投票
1 回答
1194 浏览
提问于 2025-04-18 15:00

我正在使用TitanGraphDB和Cassandra。我是这样启动Titan的:

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties

我有一个Rexster控制台,可以用来和上面的Titan和Cassandra进行交流。

cd rexster-console-2.3.0
bin/rexster-console.sh

我想用Titan图数据库来建模一个网络拓扑。我希望能通过我的Python程序来操作Titan图数据库。为此,我使用了一个叫做python bulbs的包。创建图的代码如下:

from bulbs.titan import Graph 
self.g = Graph()

现在,我的rexster控制台和Titan都在IP地址为192.168.65.93的机器上运行。如果我的Python应用程序也在同一台机器上运行,我就可以用self.g = Graph()来连接。

但如果我想从IP地址为192.168.65.94的Python应用程序连接到运行在192.168.65.93上的,该怎么做呢?

我可以传递一些参数(比如一个配置文件给Graph())吗?我在哪里可以找到这些信息呢?

1 个回答

2

只需要在Bulbs的Config对象中设置Titan图的URI:

>>> from bulbs.titan import Graph, Config
>>> config = Config('http://192.168.65.93:8182/graphs/graph')
>>> g = Graph(config)

可以查看Bulbs的Config...

还有Bulbs的Graph(注意Titan的Graph类是Rexster的Graph类的子类)...

我建议你阅读Bulbs的快速入门和其他文档,因为很多问题在里面都有解答...

快速入门使用bulbs.neo4jserver作为示例,但由于Bulbs的API在使用不同后端服务器时是一致的,因此快速入门中的示例同样适用于Titan服务器和Rexster。

要将Bulbs的快速入门适配到Titan或Rexster,只需将Graph的导入从...

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()

...改为...

>>> from bulbs.titan import Graph
>>> g = Graph()

...或者...

>>> from bulbs.rexster import Graph
>>> g = Graph()

撰写回答