-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.go
40 lines (33 loc) · 1.22 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package equeue
import (
"context"
"github.com/cloudevents/sdk-go/v2/binding"
"github.com/cloudevents/sdk-go/v2/binding/format"
)
type Driver interface {
// Send sends a message to the stream associated with the topic. msg.Finish() is called when
// sending is done.
Send(c context.Context, topic string, msg binding.Message) error
Consumer(topic string, subscriptionName string) (Consumer, error)
Close() error
}
type receivedMessageFormatKey struct{}
func withForcedReceivedMessageFormat(ctx context.Context, f format.Format) context.Context {
return context.WithValue(ctx, receivedMessageFormatKey{}, f)
}
// ForcedReceivedMessageFormat returns format to convert the received message to event.Event. Do not
// use this function except in Driver implementations.
func ForcedReceivedMessageFormat(ctx context.Context) format.Format {
f := ctx.Value(receivedMessageFormatKey{})
if f == nil {
return nil
}
return f.(format.Format)
}
type Consumer interface {
// Receive blocks until a message is received or an error occurs. If Consumer is stopped,
// ErrConsumerStoped is returned. The caller is responsible for calling `Finish()` on the
// returned message.
Receive(ctx context.Context) (binding.Message, error)
Stop() error
}