Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Define interface for mutable and immutable messages
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleasa authored and Achilleas Anagnostopoulos committed Dec 7, 2016
1 parent a442017 commit 4bbce0a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions transport/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package transport

import "io"

// ImmutableMessage defines an interface for read-only messages received by a
// Transport.
type ImmutableMessage interface {
// ImmutableMessage implements io.Closer. All messages should be closed
// when they are no longer being used.
io.Closer

// Sender returns the name of the service that sent the mesage.
Sender() string

// Receiver returns the name of the service that will receive the message.
Receiver() string

// Endpoint returns the receiving service endpoint where the message
// will be routed to. The receiving service name combined with the
// endpoint name should be unique among all running services.
Endpoint() string

// Headers returns a map of header values associated with the message.
Headers() map[string]string

// Payload returns the payload associated with the message as a byte
// slice or an error if one is encoded in the message.
Payload() ([]byte, error)
}

// Message defines an interface for messages whose headers and payload can be
// modified by the sender. Message instances are typically used by clients to
// send RPC requests or by servers to respond to incoming messages.
type Message interface {
ImmutableMessage

// SetPayload sets the content of this message. The content may be either
// a byte slice or an error message.
SetPayload(payload []byte, err error)

// SetHeader sets the content of a message header to the specified value.
// If the specified header already exists, its value will be overwritten
// by the new value.
SetHeader(name, value string)

// SetHeaders sets the contents of a batch of headers. This is equivalent
// to iterating the map and calling SetHeader for each key/value.
SetHeaders(headers map[string]string)
}

0 comments on commit 4bbce0a

Please sign in to comment.