https://repost.aws/questions/QUU7Rks5l1Rda3VqSH9bOg_w

0

【以下的问题经过翻译处理】 你好, 我有以下代码可以在注册到Greengrass的任何设备上使用IPC套接字。但是我无法找到在nodejs中执行它的好例子。有办法实现吗?我找不到像Python版本中设置SVCUID参数的地方。我的当前无法工作的nodejs版本如下所示: Nodejs版本: ... import { greengrass,iot,io,mqtt } from 'aws-iot-device-sdk-v2'; … const hostname = process.env.AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT;

const clientBootstrap = new io.ClientBootstrap(); const configBuilder = iot.AwsIotMqttConnectionConfigBuilder.new_websocket_builder() .with_clean_session(false) .with_socket_options( new io.SocketOptions(io.SocketType.STREAM, io.SocketDomain.LOCAL, 3000) );

const config = configBuilder.build(); config.host_name = hostname; config.port = 8033;

const client = new mqtt.MqttClient(clientBootstrap); const connection = client.new_connection(config);

Python版本: … import os

from awscrt.io import ( ClientBootstrap, DefaultHostResolver,。 EventLoopGroup,, SocketDomain,, SocketOptions,, ) from awsiot.eventstreamrpc import Connection,LifecycleHandler, MessageAmendment

TIMEOUT = 10

class IPCUtils: def connect(self): elg = EventLoopGroup() resolver = DefaultHostResolver(elg) bootstrap = ClientBootstrap(elg,resolver) socket_options = SocketOptions() socket_options.domain = SocketDomain.Local amender = MessageAmendment.create_static_authtoken_amender(os.getenv("SVCUID")) hostname = os.getenv("AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT") connection = Connection( host_name=hostname, port=8033, bootstrap=bootstrap, socket_options=socket_options, connect_message_amender=amender, ) self.lifecycle_handler = LifecycleHandler() connect_future = connection.connect(self.lifecycle_handler) connect_future.result(TIMEOUT) return connection

谢谢, Sukru

profile picture
专家
已提问 5 个月前58 查看次数
1 回答
0

【以下的回答经过翻译处理】 Greengrass IPC目前还不支持NodeJS,但这项功能将在今年推出。 您必须使用受支持的SDK语言:https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-requirements

祝好,

Michael

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则