1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-05 13:15:11 +02:00

queue: add pubsub abstraction (#792)

* add pubsub abstraction
This commit is contained in:
Tony Chen 2021-03-20 15:21:50 +08:00 committed by GitHub
parent 1b16831cf6
commit dc9c808e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -45,9 +45,9 @@ This document defines the roadmap for Kratos development.
- [ ] Streaming Handler
- [ ] Cache
- [ ] go-redis
- [ ] Queue
- [ ] Broker API
- [ ] Kafka
- [x] Pubsub
- [x] Absctraction
- [x] Kafka
- [ ] Nats
- [ ] Database
- [ ] Ent

3
pubsub/README.md Normal file
View File

@ -0,0 +1,3 @@
# Pubsub
* [Kafka](https://github.com/go-kratos/kafka)

39
pubsub/pubsub.go Normal file
View File

@ -0,0 +1,39 @@
package pubsub
import (
"context"
)
// Message is an absctraction for all messages that
// are sent to quque or received from queue.
type Message struct {
Key string
Value []byte
Header map[string]string
}
// Event given to a subscription handler for processing.
type Event interface {
Message() *Message
Ack() error
Nack() error
}
// Handler is a callback function that processes messages delivered
// to asynchronous subscribers.
type Handler func(context.Context, Event) error
// Publisher is absctraction for sending messages
// to queue.
type Publisher interface {
Publish(ctx context.Context, msg *Message) error
PublishAsync(ctx context.Context, msg *Message, callback func(err error)) error
Close() error
}
// Subscriber is an absctraction for receiving messages
// from queue.
type Subscriber interface {
Subscribe(ctx context.Context, h Handler) error
Close() error
}