AWS Appsync subscription does not fire events.I did not receive events from the socket. The watcher seems to work fine because if i pass a wrong token (for test) it fire onFailure event.
What i have done is:
Update my project gradle:
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.7.+'
Update my app gradle:
apply plugin: 'com.amazonaws.appsync'
and dependencies:
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'
Put these files inside app/src/main/graphql
queries.graphql
subscription subscribeToNotify($userId: ID!, $deviceId: ID!){ subscribeToNotify(userId: $userId, deviceId: $deviceId){ userId deviceId body } }
schema.json (downloaded from console)
My configuration json is:
{
"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"
}
}
}
Manifest: `
<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" />
My activity:
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)
}
}
When the backend send me a notification nothing appear in log console but i can read that the subsription is done:
2019-04-25 10:49:28.456 12082-12317/infinite_software.intelligence_center.intelligencecenter D/RealSubscriptionManager: Subscription Infrastructure: Adding subscription object com.amazonaws.mobileconnectors.appsync.subscription.SubscriptionObject@4d109b1 to topic 156616541434/2b4hzivvqvdwzmcy4wibyy2sku/subscribeToNotify/85582f91c6e6a66749f4e0e9c4d74ea7abef52b2e4c0242517e5236d4d51be60. Total subscription objects: 1
and the scheduler that works (every X seconds):
2019-04-25 10:50:59.996 12082-12082/infinite_software.intelligence_center.intelligencecenter D/AlarmPingSender: Sending Ping at:1556185859996 2019-04-25 10:51:00.006 12082-12082/infinite_software.intelligence_center.intelligencecenter D/AlarmPingSender: Schedule next alarm at 1556185890006 2019-04-25 10:51:00.006 12082-12082/infinite_software.intelligence_center.intelligencecenter D/AlarmPingSender: Alarm scheule using setExactAndAllowWhileIdle, next: 30000 2019-04-25 10:51:00.033 12082-12350/infinite_software.intelligence_center.intelligencecenter D/AlarmPingSender: Success. Release lock(MqttService.client.dcuju2iftbdgplcvdamtlghzuu):1556185860033
I missing something ?