Android AWS Appsync订阅不会触发事件

时间:2019-04-25 10:34:57

标签: android kotlin subscription aws-appsync

AWS Appsync订阅不会触发事件。我没有从套接字接收事件。该监视程序似乎工作正常,因为如果我传递了错误的令牌(用于测试),则会触发onFailure事件。

我所做的是:

更新我的项目gradle:

classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.7.+'

更新我的应用gradle:

apply plugin: 'com.amazonaws.appsync'

和依赖项:

implementation 'com.amazonaws:aws-android-sdk-appsync:2.7.+' 
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

将这些文件放入app / src / main / graphql

  

queries.graphql

subscription subscribeToNotify($userId: ID!, $deviceId: ID!){ subscribeToNotify(userId: $userId, deviceId: $deviceId){ userId deviceId body } }
  

schema.json(从控制台下载)

我的配置json是:

{
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "1.0",
"IdentityManager": {
    "Default": {}
},
"AppSync": {
    "Default": {
        "ApiUrl": "https://XXX",
        "Region": "eu-west-1",
        "AuthMode": "OPENID_CONNECT"
    },
    "Demo": {
        "ApiUrl": "https://XXX",
        "Region": "eu-west-2",
        "AuthMode": "OPENID_CONNECT"
    }
}

}

清单: `

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />



<service android:name="org.eclipse.paho.android.service.MqttService" />

我的活动

 private lateinit var appSyncClient : AWSAppSyncClient
    private lateinit var watcher: AppSyncSubscriptionCall<SubscribeToNotifySubscription.Data>

    private var callback:AppSyncSubscriptionCall.Callback<SubscribeToNotifySubscription.Data> = object : AppSyncSubscriptionCall.Callback<SubscribeToNotifySubscription.Data> {

        override fun onResponse(response: Response<SubscribeToNotifySubscription.Data>) {
            runOnUiThread {
                Timber.i("Subcription onResponse invoked  $response")
                Timber.e("Subcription onResponse invoked  $response")
                Timber.d("Subcription onResponse invoked  $response")
            }
        }
        override fun onCompleted() {
            Timber.i("Subcription onCompleted invoked")
        }

        override fun onFailure(e: ApolloException) {
            Timber.e("Subcription ERROR $e")
        }
    }

override fun subscribeToNotification(userID: String, deviceID: String, clearToken:String) {
        try{

            Timber.d("subscribeToNotification INVOKED")

            val clientConfiguration : AWSConfiguration =  AWSConfiguration(this)

            appSyncClient =  AWSAppSyncClient.builder().context(applicationContext).awsConfiguration(clientConfiguration).oidcAuthProvider { clearToken }.build()
            //subscribeToNotify

            var app_event_subscription = SubscribeToNotifySubscription.builder().deviceId(deviceID).userId(userID!!).build()

            watcher = appSyncClient.subscribe(app_event_subscription)
            watcher.execute(callback)

        }catch (ex:Exception){
            Timber.e("EXCEPTION CONNETING "+ex.message)
        }
    }

当后端向我发送通知时,日志控制台中什么也没有出现,但我可以阅读到该替换已完成:

  

2019-04-25 10:49:28.456 12082-1​​2317 / infinite_software.intelligence_center.intelligencecenter D / RealSubscriptionManager:订阅基础结构:将订阅对象com.amazonaws.mobileconnectors.appsync.subscription.SubscriptionObject@4d109b1添加到主题156616541434 / 2b4hzivvqwidw2m / subscribeToNotify / 85582f91c6e6a66749f4e0e9c4d74ea7abef52b2e4c0242517e5236d4d51be60。订阅对象总数:1

和有效的调度程序(每X秒):

  

2019-04-25 10:50:59.996   12082-1​​2082 / infinite_software.intelligence_center.intelligencecenter   D / AlarmPingSender:发送Ping:1556185859996 2019-04-25   10:51:00.006   12082-1​​2082 / infinite_software.intelligence_center.intelligencecenter   D / AlarmPingSender:在1556185890006 2019-04-25安排下一个警报   10:51:00.006   12082-1​​2082 / infinite_software.intelligence_center.intelligencecenter   D / AlarmPingSender:使用setExactAndAllowWhileIdle的警报计划,   下一个:30000 2019-04-25 10:51:00.033   12082-1​​2350 / infinite_software.intelligence_center.intelligencecenter   D / AlarmPingSender:成功。发布   锁定(MqttService.client.dcuju2iftbdgplcvdamtlghzuu):1556185860033

我错过了什么吗?

0 个答案:

没有答案
相关问题