【问题标题】:Why is my Subscribe Function not Running?为什么我的订阅功能没有运行?
【发布时间】:2019-04-07 21:44:17
【问题描述】:

我已按照 AWS 网站上的示例进行操作 https://aws-amplify.github.io/docs/js/pubsub

无论我每次跑步时会发生什么 等待 PubSub.publish 我没有收到 AWS 的回复。任何帮助,将不胜感激。 我的代码超时了。

Triend 通过 MQTT react-native 与 AWS 交互的不同方式。到处找。没有使用这个的例子。

import Amplify, { PubSub, Auth } from 'aws-amplify';

import { AWSIoTProvider } from '@aws-amplify/pubsub/lib/Providers';

import aws_exports from './src/aws-exports';

// aythentication import
import { withAuthenticator } from 'aws-amplify-react-native';
Amplify.configure(aws_exports);


Amplify.addPluggable(new AWSIoTProvider({
     aws_pubsub_region: 'us-east-1',
     aws_pubsub_endpoint:  'wss://azk3aah4ivg82-ats.iot.us-east-1.amazonaws.com/mqtt',
}));

PubSub.subscribe(['$aws/things/B_Bone_1/shadow/get/accepted', '$aws/things/B_Bone_1/shadow/get/rejected']).subscribe({
    next: data => console.log('Message received get accepted', data),
    error: error => console.error(error),
    close: () => console.log('Done'),
});


//
export default class Main extends React.Component {
//...... sign in stuff This just makes a cognito accound and lets me log in. Its working
}


class App extends Component {
//constuct props 
///...
update = async () => {

    await PubSub.publish('$aws/things/B_Bone_1/shadow/update', {msg: '{"state":{"reported":{"temp": -1}}}' });

    Alert.alert('Update all local values from Device Shadow');
  }


render() {
    return (
    //A page with a button that runs update function
    );
    }}
    
//Stylesheet stuff
    

当调用 update 时,程序应该运行 subscribe 函数。但我得到一个超时错误,因为没有返回任何内容。 任何帮助都会很棒。

【问题讨论】:

    标签: javascript amazon-web-services react-native iot publish-subscribe


    【解决方案1】:

    您登录 VERBOSE 了吗?

    Amplify.Logger.LOG_LEVEL = 'VERBOSE';

    也许您需要提供者?

    core.js:6014 ERROR Error: Uncaught (in promise): Error: Could not find provider named [object Object]

    和我一样,还没解决:-(

    【讨论】:

      猜你喜欢
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多