Skip to content

MqttOverWSProvider only works with JSON messages #4040

@brimworks

Description

@brimworks

Describe the bug
If the MqttOverWSProvider is used for implementing the PubSub interface, and a non-JSON message is published to a topic that it is subscribed to, the following warning is printed:

[WARN] 27:28.905 MqttOverWSProvider - Error handling message, Array [
  [SyntaxError: JSON Parse error: Unexpected identifier "non-json-input"],
  "non-json-input",
]

To Reproduce
Steps to reproduce the behavior:

import Amplify from '@aws-amplify/core'
import PubSub from '@aws-amplify/pubsub';
import { AWSIoTProvider } from '@aws-amplify/pubsub/lib/Providers';

Amplify.configure(config);
Amplify.addPluggable(new AWSIoTProvider({
    aws_pubsub_region: 'XXXX',
    aws_pubsub_endpoint: 'wss://XXXX-ats.iot.us-east-1.amazonaws.com/mqtt',
}));

PubSub.subscribe("non-json-topic").subscribe({
            next: msg => console.log("got", msg),
            error: err => console.log("Failed to subscribe: ", err),
            close: () => console.log("close"),
        });

Note that you will need to publish a non-JSON message to the MQTT queue on the non-json-topic.

Expected behavior
An option to disable JSON serialization/deserialization during publish and subscribe so these non-JSON messages can be properly handled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PubSubRelated to PubSub categoryfeature-requestRequest a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions