Proto API and grpc bindings for pubsub capabilities
pubsub-api provides Proto API and grpc bindings for pubsub capabilities
NOTE: At this time, only the Python API is working, Golang and others to come later.
The pubsub resource implements the following API:
The publish() command takes:
- topic: The pubsub topic to publish to
- message: the message to publish to the topic
- qos: the quality of service, if supported by the broker (for example, MQTT accepts 0|1|2)
The subscribe() command takes:
- topic: The pubsub topic to subscribe to
The unsubscribe() command takes:
- topic: The pubsub topic to unsubscribe to
Because this module uses a custom protobuf-based API, you must include this project in your client code. One way to do this is to include it in your requirements.txt as follows:
pubsub_api @ git+https://github.com/viam-labs/pubsub-api.git@main
You can now import and use it in your code as follows:
from pubsub_python import Pubsub
api = Pubsub.from_robot(robot, name="pubsub")
api.publish("topic", "message", 0)
See client.py for an example.
Because this module uses a custom protobuf-based API, you must import and use in your client code as follows:
import pubsub "github.com/viam-labs/pubsub-api/src/pubsub_go"
api, err := pubsub.FromRobot(robot, "pubsub")
fmt.Println("err", err)
api.Publish(context.Background(), "topic", "message", 0)
See client.go for an example.
To rebuild the GRPC bindings, run:
make generate
Then, in `src/pubsub_python/grpc/pubsub_grpc.py change:
import pubsub_pb2
to:
from . import pubsub_pb2
Then, update the version in pyproject.toml