Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
读取海王星流数据
以下示例显示如何从属性图流端点读取记录。你可以使用 Amazon CLI, Amazon 适用于 Python 的 SDK (Boto3), awscurl,或 curl。
- Amazon 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
有关更多信息,请参阅 获取属性图直播 在 Amazon 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))
要在直播中进行分页,请使用 commitNum 和 opNum 来自 lastEventId 在回应中:
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
这个例子假设你的 Amazon 证书是在您的环境中配置的。替换 us-east-1 使用您的 Neptune 集群所在的区域。
有关使用的更多信息 awscurl 使用 IAM 身份验证,请参阅 使用 awscurl 使用临时证书安全地连接到启用了 IAM 身份验证的数据库集群。
- curl
-
curl https://your-neptune-endpoint:port/propertygraph/stream?limit=10
使用 curl 如果没有 SigV4 签名,则只有在您的 Neptune 集群上禁用 IAM 身份验证时才有效。如果启用了 IAM 身份验证,请使用 awscurl 或者 Amazon CLI 取而代之。
对于 SPARQL 图,请替换 /propertygraph/stream 和 /sparql/stream 在前面的例子中。使用时 Amazon CLI 或 SDK,使用 get-sparql-stream 要么 client.get_sparql_stream() 取而代之。
在图表笔记本中查看流数据
如果你使用 海王星图形笔记本, %stream_viewer line magic 提供了无需编写代码即可交互式浏览直播记录的可视化界面。在笔记本电脑单元中运行以下命令:
%stream_viewer
您可以选择指定查询语言和页面大小:
%stream_viewer sparql --limit 20
有关更多信息,请参阅 %stream_v iewer 线路的魔法。
这个 %stream_viewer 只有引擎版本 1.0.5.1 及更早版本完全支持 magic。