为什么我的订阅功能未运行?

时间:2019-04-07 21:44:17

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

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

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

通过MQTT react-native与AWS进行交互的Triend不同方式。到处搜寻。没有使用此示例。

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时,程序应运行订阅功能。但是我收到超时错误,因为什么也没有返回。 任何帮助都将是惊人的。

1 个答案:

答案 0 :(得分:0)

您已登录VERBOSE吗?

Amplify.Logger.LOG_LEVEL = 'VERBOSE';

  

也许您需要提供者?

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

像我一样,尚未解决:-(