AmPub is a very simple framework to help abstract the specifics of publishing to some message broker. It provides a simple HTTP API server and you provide the publishing implementation. Your client application can then communicate with the HTTP API without knowing the details about the implementation that was provided.
The envisioned use case is for an ambassador/adaptor container in a composite-container deployment.
package main
import (
"context"
"log"
"github.com/amaloy/ampub"
)
func main() {
// Create AmPub
ampub := new(ampub.AmPub)
// Create your publisher
publisher := new(examplePublisher)
// Run AmPub with your publisher
ampub.Run(publisher)
}
// examplePublisher - Implementation of ampub.Publisher that publishes to log
type examplePublisher struct {
}
func (p *examplePublisher) Publish(ctx context.Context, topic string, key string, data []byte) error {
// It's up to your implementation what to do with the values
log.Printf("topic=%s key=%s data=%s", topic, key, string(data))
return nil
}
POST /apiv1/topics/{T}
- Post the bytes in the request body to topic T.
POST /apiv1/topics/{T}/key/{K}
- Post the bytes in the request body to topic T given key K. A key is a common attribute in message systems and so it provided as an option.
AMPUB_ADDR
- The address to listen on, e.g.0.0.0.0:4567
, default is:8000
AMPUB_LOGONLY
- Iftrue
, the provided Publisher will be ignored and publishing will go tolog
ampub-gcppubsub - An implementation for Google Cloud Pub/Sub