question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to catch PubSub errors if MQTT connection lost or broken?

See original GitHub issue

** Which Category is your question related to? ** PubSub connection problems

** What AWS Services are you utilizing? ** PubSub in aws-amplify 1.1.19

** Provide additional details e.g. code snippets ** What is the best way to keep PubSub connection alive by using aws-amplify? Or is there even any way?

I am using similar code as you mention in the documentation: PubSub.subscribe(['myTopic1','myTopic1']).subscribe({ next: data => console.log('Message received', data), error: error => console.error(error), // this never logs anything) close: () => console.log('Done'), // this never logs anything) })

However, I have the problem that clients Internet connection can be lost for a short period of time and then these can no longer receive messages. For example, if portable Wifi router switch connection from 4G to 3G, I get the following message in console: ConsoleLogger.js:88 [WARN] 14:36.405 MqttOverWSProvider - ... { "errorCode": 4, "errorMessage": "AMQJS0004E Ping timed out.", "uri": "wss://..." } I would like to catch these connection problems somehow in order to subscribe to topics again so that I can keep connection alive.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:22 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
mevertcommented, Apr 9, 2019

In addition to AMQJS0004E Ping timed out error, AMQJS0007E Socket error:undefined (errorCode: 7) does not trigger the error. Despite the fact that it occurs when subscription fails. Documentation of PubSub says that error is “Triggered when subscription attempt fails”. However, looks like errors are not triggered…

@manueliglesias any idea when the fix for this issue is coming?

3reactions
matwerber1commented, Feb 24, 2019

+1 request for connection event handlers and methods to retrieve current status. Same for subscriptions if not already present.

For example, in code below, no errors are thrown even if I provide non-existent region or endpoint:

Amplify.addPluggable(new AWSIoTProvider({
      aws_pubsub_region: AWSIotConfiguration.region,
      aws_pubsub_endpoint: AWSIotConfiguration.endpoint,
    }));  

However, I later receive an uncaught (in promise) error when attempting the PubSub.subscribe() action. If we could know that the connection failed in advance we could avoid the unecessary subscription attempt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to catch PubSub errors if MQTT connection lost or broken?
What is the best way to keep PubSub connection alive by using aws-amplify? Or is there even any way? I am using similar...
Read more >
Resolving problem: MQTT client connection dropped - IBM
A dropped connection is defined by the MQTT client calling the MqttCallback.ConnectionLost method. The method is only called after the connection has been ......
Read more >
MQTT Keep Alive Interval Explained With Examples
MQTT uses a keepalive mechanism for checking the status of the TCP/IP connection.On a quiet TCP/IP connection an MQTT client will send a ......
Read more >
MQTT Client and Broker and MQTT Server and Connection ...
In this post, we will discuss the roles of the MQTT client and broker, the parameters and options that are available when you...
Read more >
mqttclient.subscribe(topics, qos, callback) - Dev Center
We recommend that you wrap all mqttclient.subscribe() calls in a try... catch statement. Even if the client is connected at the time of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found