Skip to content

Message delivery not working if publisher is sending message to early after connect #483

@koh-osug

Description

@koh-osug

The subscribe function is called from a subscriber with node.services.pubsub.subscribe(PEER_SUBSCRIPTION_TOPIC) and the other publishing peer is sending a notification with node.services.pubsub.publish(PEER_SUBSCRIPTION_TOPIC, new Uint8Array(BSON.serialize({ipAddress: argv.ipAddress}).buffer)).
What I notice is that the publishing only works if the subscription of the other peer is know, i.e. if the publish is executed too early before the subscribe is known, publish is not doing anything and any listener node.services.pubsub.addEventListener('message', (message) => {...} is never called in the subscriber. To make it work I have to wait until the publishing peer is connected and I have to use a delay in the publisher like:

        setTimeout( () => {
            node.services.pubsub.publish(PEER_SUBSCRIPTION_TOPIC, new Uint8Array(BSON.serialize({ipAddress: argv.ipAddress}).buffer))
        }, 5000)

What is the correct way to send a message from a publisher, so that a connecting client can receive it without using this delay? is there a callback?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions