go get -u github.com/tomwright/deliver
Publish + consume messages with standard interfaces.
This quick start assumes you already have your Subscriber
or Producer
created already.
For information on creating those objects, see Implementations below.
Below is an example message that may be published when a user has been created.
type UserCreated struct {
Username string `json:"username"`
}
func (m *UserCreated) Type() string {
return "user.created"
}
func (m *UserCreated) Payload() ([]byte, error) {
return json.Marshal(m)
}
func (m *UserCreated) WithPayload(bytes []byte) error {
return json.Unmarshal(bytes, m)
}
Message.Type()
response is used as the topic.- Messages are marked before the given
ConsumerFn
is executed.
Setup:
brokers := []string{"cmg-local-kafka:9092"}
publisher, err := deliver.NewKafkaPublisher(brokers)
subscriber := deliver.NewKafkaSubscriber(brokers)