0

I am working on a react project that uses AWS Amplify Authentication and PubSub.

The user signs in using a custom provider, and subscribes a topic based on their cognito-identity-id.

I am able to successfully sign in and subscribe to topics.

The data that is published to it is compressed binary data

...
const { gzip } = require('node-gzip')
payload = await gzip(data)
...

When I receive this data, I get the following warning in ConsoleLogger.js

[WARN] 50:28.664 MqttOverWSProvider  {
  "errorCode": 5,
  "errorMessage": "AMQJS0005E Internal error. Error Message: AMQJS0009E Malformed UTF data:8b -78 ., Stack trace: No Error Stack Available",
  "uri": "..."
}

The connectionState then goes to ConnectionDisrupted and it reconnects.

I don't have this issue when I publish a regular JSON object to the topic.

Code snippet:

Amplify.configure(awsExports)
Amplify.addPluggable(
  new AWSIoTProvider({
    aws_pubsub_endpoint: `wss://${awsExports.PubSub.endpoint}/mqtt`,
    aws_pubsub_region: awsExports.PubSub.region,
  })
)
...
PubSub.subscribe(`test/${signedInUserId}/companies`).subscribe({
    next:data=>console.log('got data')
  })

My plan is to get the binary data and use Pako.inflate() to convert it to JSON, but I can't get that far because it throws that warning/error before the next() is called.

Why am I getting this error when I receive binary data, and how do I get PubSub to accept compressed binary data?

Thank you.

sshakya
  • 75
  • 6
  • 1
    Unfortunately it appears that [`MqttOverWSProvider`](https://github.com/aws-amplify/amplify-js/blob/main/packages/pubsub/src/Providers/MqttOverWSProvider.ts#L192C4-L192C17) only handles `Strings` (if it handled bytes it would be using `payloadBytes` rather than `payloadString` - see [here](https://github.com/aws-amplify/amplify-js/blob/main/packages/pubsub/src/vendor/paho-mqtt.js#L2687)). [Related issue](https://stackoverflow.com/q/25547653/11810946) (behind the scenes `MqttOverWSProvider` uses a copy of the paho library). – Brits Aug 17 '23 at 21:17

0 Answers0