Created
April 12, 2018 21:40
-
-
Save arbarlow/8c28862026aa1689bfc84cb18cf62a5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/echo-health/accounts" | |
"github.com/lileio/pubsub" | |
"github.com/lileio/pubsub/kafka" | |
"github.com/sanity-io/litter" | |
k "github.com/segmentio/kafka-go" | |
"github.com/sirupsen/logrus" | |
) | |
type PSKafkaSubscriber struct{} | |
func (s *PSKafkaSubscriber) DoSomething(ctx context.Context, a *accounts.Account, _ *pubsub.Msg) error { | |
litter.Dump(a) | |
return nil | |
} | |
func (s *PSKafkaSubscriber) Setup(c *pubsub.Client) { | |
c.On(pubsub.HandlerOptions{ | |
Topic: "ps_kafka_test", | |
Name: "send_confirmation_email", | |
Handler: s.DoSomething, | |
AutoAck: true, | |
}) | |
} | |
func main() { | |
logrus.SetLevel(logrus.DebugLevel) | |
pubsub.SetClient(&pubsub.Client{ | |
ServiceName: "pstestservice", | |
Provider: &kafka.Provider{ | |
Brokers: []string{"localhost:9092"}, | |
Balancer: &k.LeastBytes{}, | |
}, | |
}) | |
// pubsub.Subscribe(&PSKafkaSubscriber{}) | |
res := pubsub.Publish(context.Background(), "ps_kafka_test", &accounts.Account{FirstName: "hello"}) | |
<-res.Ready | |
fmt.Printf("err = %+v\n", res.Err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment