View a markdown version of this page

读取 Neptune 流数据 - Amazon Neptune

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

读取 Neptune 流数据

以下示例说明如何从属性图流端点读取记录。你可以使用 AWS CLI、适用于 Python 的 AWS SDK (Boto3)、或。awscurl curl

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))

要对直播进行分页,请在响应opNumlastEventId中使用commitNum和:

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 身份验证时,curl不使用 Sigv4 签名才能使用。如果启用了 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魔法。