Documentation ¶
Index ¶
Constants ¶
const ( // MessageHistoryHeader is the header containing all channel hosts traversed by the message // This is an experimental header: https://github.com/knative/eventing/issues/638 MessageHistoryHeader = "ce-knativehistory" MessageHistorySeparator = "; " )
const (
// MessageReceiverPort is the port that MessageReceiver opens an HTTP server on.
MessageReceiverPort = 8080
)
Variables ¶
ErrUnknownChannel is returned when a message is received by a channel dispatcher for a channel that does not exist.
Functions ¶
func ParseChannel ¶
func ParseChannel(host string) (channel.ChannelReference, error)
ParseChannel converts the channel's hostname into a channel reference.
Types ¶
type DispatchDefaults ¶
type DispatchDefaults struct {
Namespace string
}
DispatchDefaults provides default parameter values used when dispatching a message.
type Dispatcher ¶
type Dispatcher interface { // DispatchMessage dispatches a message to a destination over HTTP. // // The destination and reply are DNS names. For names with a single label, // the default namespace is used to expand it into a fully qualified name // within the cluster. DispatchMessage(message *Message, destination, reply string, defaults DispatchDefaults) error }
type Message ¶
type Message struct { // Headers provide metadata about the message payload. All header keys // should be lowercase. Headers map[string]string `json:"headers,omitempty"` // Payload is the raw binary content of the message. The payload format is // often described by the 'content-type' header. Payload []byte `json:"payload,omitempty"` }
Message represents a chunk of data within a channel dispatcher. The message contains both a map of string headers and a binary payload. This struct gets marshaled/unmarshaled in order to preserve and pass Header information to the event subscriber.
A message may represent a CloudEvent.
func (*Message) AppendToHistory ¶
AppendToHistory appends a new host at the end of the list of hosts of the message history
type MessageDispatcher ¶
type MessageDispatcher struct {
// contains filtered or unexported fields
}
MessageDispatcher dispatches messages to a destination over HTTP.
func NewMessageDispatcher ¶
func NewMessageDispatcher(logger *zap.SugaredLogger) *MessageDispatcher
NewMessageDispatcher creates a new message dispatcher that can dispatch messages to HTTP destinations.
func (*MessageDispatcher) DispatchMessage ¶
func (d *MessageDispatcher) DispatchMessage(message *Message, destination, reply string, defaults DispatchDefaults) error
DispatchMessage dispatches a message to a destination over HTTP.
The destination and reply are DNS names. For names with a single label, the default namespace is used to expand it into a fully qualified name within the cluster.
type MessageReceiver ¶
type MessageReceiver struct {
// contains filtered or unexported fields
}
MessageReceiver starts a server to receive new messages for the channel dispatcher. The new message is emitted via the receiver function.
func NewMessageReceiver ¶
func NewMessageReceiver(receiverFunc func(channel.ChannelReference, *Message) error, logger *zap.SugaredLogger, opts ...ReceiverOptions) (*MessageReceiver, error)
NewMessageReceiver creates a message receiver passing new messages to the receiverFunc.
func (*MessageReceiver) HandleRequest ¶
func (r *MessageReceiver) HandleRequest(res http.ResponseWriter, req *http.Request)
HandleRequest is an http.Handler function. The request is converted to a Message and emitted to the receiver func.
The response status codes:
202 - the message was sent to subscribers 404 - the request was for an unknown channel 500 - an error occurred processing the request
func (*MessageReceiver) Start ¶
func (r *MessageReceiver) Start(stopCh <-chan struct{}) error
Start begings to receive messages for the receiver.
Only HTTP POST requests to the root path (/) are accepted. If other paths or methods are needed, use the HandleRequest method directly with another HTTP server.
This method will block until a message is received on the stop channel.
type ReceiverOptions ¶
type ReceiverOptions func(*MessageReceiver) error
ReceiverOptions provides functional options to MessageReceiver function.
func ResolveChannelFromHostHeader ¶
func ResolveChannelFromHostHeader(hostToChannelFunc ResolveChannelFromHostFunc) ReceiverOptions
ResolveChannelFromHostHeader is a ReceiverOption for NewMessageReceiver which enables the caller to overwrite the default behaviour defined by ParseChannel function.
type ResolveChannelFromHostFunc ¶
type ResolveChannelFromHostFunc func(string) (channel.ChannelReference, error)
ResolveChannelFromHostFunc function enables MessageReceiver to get the Channel Reference from incoming request HostHeader before calling receiverFunc.