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달 전62회 조회
1개 답변
0

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

祝好,

Michael

profile picture
전문가
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인