View a markdown version of this page

读取海王星流数据 - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

读取海王星流数据

以下示例显示如何从属性图流端点读取记录。你可以使用 AWS 适用于 Python 的软件开发工具包 (Boto3) awscurl、或。 AWS CLIcurl

AWS CLI
aws neptunedata get-propertygraph-stream \ --endpoint-url https://your-neptune-endpoint:port \ --iterator-type TRIM_HORIZON \ --limit 10

要从流中的特定位置读取,请使用--commit-num--iterator-type参数:

aws neptunedata get-propertygraph-stream \ --endpoint-url https://your-neptune-endpoint:port \ --limit 10 \ --commit-num 1 \ --iterator-type AT_SEQUENCE_NUMBER

有关更多信息,请参阅《命令参考》中的 get-propertygraph-stream 。 AWS CLI

SDK (Python)
import boto3 import json from botocore.config import Config client = boto3.client( 'neptunedata', region_name='us-east-1', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=65) ) response = client.get_propertygraph_stream( limit=10, iteratorType='TRIM_HORIZON' ) print(json.dumps(response['records'], indent=2, default=str))

要对直播进行分页,请在响应lastEventId中使用commitNumopNum from:

last_event = response['lastEventId'] next_response = client.get_propertygraph_stream( limit=10, commitNum=last_event['commitNum'], opNum=last_event['opNum'], iteratorType='AFTER_SEQUENCE_NUMBER' )
awscurl
awscurl https://your-neptune-endpoint:port/propertygraph/stream?limit=10 \ --region us-east-1 \ --service neptune-db
注意

此示例假设您的 AWS 证书是在您的环境中配置的。替换us-east-1为 Neptune 集群的区域。

有关awscurl与 IAM 身份验证一起使用的更多信息,请参阅使用带有临时证书的 awscurl 安全地连接到启用了 IAM 身份验证的数据库集群

curl
curl https://your-neptune-endpoint:port/propertygraph/stream?limit=10
注意

只有在您的 Neptune 集群上禁用了 IAM 身份验证时,在没有 SigV4 签名curl的情况下使用才有效。如果启用了 IAM 身份验证,则 AWS CLI 改用awscurl或。

对于 SPARQL 图,请将前面示例/sparql/stream中的替换为/propertygraph/stream。使用 AWS CLI 或 SDK 时,client.get_sparql_stream()改用get-sparql-stream或。

在图表笔记本中查看流数据

如果您使用 Neptune 图形笔记本%stream_viewer线条魔法提供了一个可视化界面,无需编写代码即可交互式浏览直播记录。在笔记本电脑单元中运行以下命令:

%stream_viewer

您可以选择指定查询语言和页面大小:

%stream_viewer sparql --limit 20

有关更多信息,请参阅 %stream_viewer 行魔术命令

注意

只有引擎版本 1.0.5.1 及更早版本完全支持该%stream_viewer魔法。