Skip to content

* Subscriptions on pubsubs #1102

@leshy

Description

@leshy

Allowing pubsubs to pattern match (or subscribe all) would allow us to create generic bridges

"all protocols to rerun"

"ros to lcm"

"lcm to foxglove" <- 2 line fg bridge

etc

current spec

class PubSub(Generic[TopicT, MsgT], ABC):
    """Abstract base class for pub/sub implementations with sugar methods."""

    @abstractmethod
    def publish(self, topic: TopicT, message: MsgT) -> None:
        """Publish a message to a topic."""
        ...

    @abstractmethod
    def subscribe(
        self, topic: TopicT, callback: Callable[[MsgT, TopicT], None]
    ) -> Callable[[], None]:
        """Subscribe to a topic with a callback. returns unsubscribe function"""
        ...

what would be an api for this?

pubsub.subscribe_all()

or do we just agree about regex or * matching?

issue is obviously general protocol pattern matching capability, not everything can regex, how do we specify this?

proposal:

SubAllPubsub(Pubsub):
     @abstractmethod
     def subscribe_all():
         ....

# implies .subscribe() supports "/bla/*" for topics, but not full regex
StarPubsub(SubAllPubsub):
    ...

# supports full regex
RegexPubsub(SubAllPubsub):
    ...

so we can specify type layer topic pattern matching capability,
provide subscribe_all method for this common usecase

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions