Documentation
¶
Index ¶
- Constants
- Variables
- func NewLambdaHandler(consumer ILambdaConsumer) lambda.Handler
- type AWSSessionsCache
- type CallbackFunction
- type CallbackKey
- type CallbackRegistry
- type GetLoggerFunc
- type ILambdaConsumer
- type IMessageValidator
- type IPublisher
- type IQueueConsumer
- type JSONTime
- type LambdaHandler
- type LambdaRequest
- type ListenRequest
- type Logger
- type LoggingFields
- type Message
- type MessageDefaultHeadersHook
- type MessageRouteKey
- type NewData
- type PreDeserializeHook
- type PreProcessHookLambda
- type PreProcessHookSQS
- type PreSerializeHook
- type Publisher
- type SQSRequest
- type Settings
Constants ¶
const ( FormatVersionV1 = "1.0" FormatCurrentVersion = FormatVersionV1 )
Message format versions
Variables ¶
var ErrRetry = errors.New("Retry error")
ErrRetry should cause the task to retry, but not treat the retry as an error
Functions ¶
func NewLambdaHandler ¶
func NewLambdaHandler(consumer ILambdaConsumer) lambda.Handler
NewLambdaHandler returns a new lambda Handler that can be started like so:
func main() { lambda.StartHandler(NewLambdaHandler(consumer)) }
If you want to add additional error handle (e.g. panic catch etc), you can always use your own Handler, and call LambdaHandler.Invoke
Types ¶
type AWSSessionsCache ¶
type AWSSessionsCache struct {
// contains filtered or unexported fields
}
AWSSessionsCache is a cache that holds sessions
func NewAWSSessionsCache ¶
func NewAWSSessionsCache() *AWSSessionsCache
NewAWSSessionsCache creates a new session cache
func (*AWSSessionsCache) GetSession ¶
func (c *AWSSessionsCache) GetSession(settings *Settings) *session.Session
GetSession retrieves a session if it is cached, otherwise creates one
type CallbackFunction ¶
CallbackFunction is the function signature for a hedwig callback function
type CallbackKey ¶
type CallbackKey struct { // Message type MessageType string // Message major version MessageMajorVersion int }
CallbackKey is a key identifying a hedwig callback
type CallbackRegistry ¶
type CallbackRegistry struct {
// contains filtered or unexported fields
}
CallbackRegistry maps hedwig messages to callback functions and callback datas
func NewCallbackRegistry ¶
func NewCallbackRegistry() *CallbackRegistry
NewCallbackRegistry creates a callback registry
func (*CallbackRegistry) RegisterCallback ¶
func (cr *CallbackRegistry) RegisterCallback(cbk CallbackKey, cbf CallbackFunction, newData NewData)
RegisterCallback registers the given callback function to the given message type and message major version. Required for consumers. An error will be returned if an incoming message is missing a callback.
type GetLoggerFunc ¶
GetLoggerFunc returns the logger object
func LogrusGetLoggerFunc ¶
func LogrusGetLoggerFunc(fn func(ctx context.Context) *logrus.Entry) GetLoggerFunc
type ILambdaConsumer ¶
type ILambdaConsumer interface { // HandleLambdaInput processes hedwig messages for the provided message types for Lambda apps HandleLambdaEvent(ctx context.Context, snsEvent events.SNSEvent) error }
ILambdaConsumer represents a lambda event consumer
func NewLambdaConsumer ¶
func NewLambdaConsumer(sessionCache *AWSSessionsCache, settings *Settings) ILambdaConsumer
NewLambdaConsumer creates a new consumer object used for lambda apps
type IMessageValidator ¶
IMessageValidator handles validating Hedwig messages
func NewMessageValidator ¶
func NewMessageValidator(schemaFilePath string) (IMessageValidator, error)
NewMessageValidator creates a new validator from the given file
func NewMessageValidatorFromBytes ¶
func NewMessageValidatorFromBytes(schemaFile []byte) (IMessageValidator, error)
NewMessageValidatorFromBytes from an byte encoded schema file
type IPublisher ¶
IPublisher handles all publish related functions
func NewPublisher ¶
func NewPublisher(sessionCache *AWSSessionsCache, settings *Settings) IPublisher
NewPublisher creates a new Publisher
type IQueueConsumer ¶
type IQueueConsumer interface { // ListenForMessages starts a hedwig listener for the provided message types // // This function never returns by default. Possible shutdown methods: // 1. Cancel the context - returns immediately. // 2. Set a deadline on the context of less than 10 seconds - returns after processing current messages. // 3. Run for limited number of loops by setting LoopCount on the request - returns after running loop a finite // number of times ListenForMessages(ctx context.Context, request *ListenRequest) error }
IQueueConsumer represents a hedwig queue consumer
func NewQueueConsumer ¶
func NewQueueConsumer(sessionCache *AWSSessionsCache, settings *Settings) IQueueConsumer
NewQueueConsumer creates a new consumer object used for a queue
type JSONTime ¶
JSONTime is just a wrapper around time that serializes time to epoch in milliseconds
func (JSONTime) MarshalJSON ¶
MarshalJSON changes time to epoch in milliseconds
func (*JSONTime) UnmarshalJSON ¶
UnmarshalJSON changes time from epoch in milliseconds
type LambdaHandler ¶
type LambdaHandler struct {
// contains filtered or unexported fields
}
LambdaHandler implements Lambda.Handler interface
type LambdaRequest ¶
type LambdaRequest struct { // Context for request Context context.Context // SNS record for this request EventRecord *events.SNSEventRecord }
LambdaRequest contains request objects for a lambda
type ListenRequest ¶
type ListenRequest struct { NumMessages uint32 // default 1 VisibilityTimeoutS uint32 // defaults to queue configuration LoopCount uint32 // defaults to infinite loops }
ListenRequest represents a request to listen for messages
type Logger ¶
type Logger interface { // Error logs an error with a message. `fields` can be used as additional metadata for structured logging. // You can generally expect one of these fields to be available: message_sqs_id, message_sns_id. // By default fields are logged as a map using fmt.Sprintf Error(err error, message string, fields LoggingFields) // Warn logs a warn level log with a message. `fields` param works the same as `Error`. Warn(err error, message string, fields LoggingFields) // Info logs a debug level log with a message. `fields` param works the same as `Error`. Info(message string, fields LoggingFields) // Debug logs a debug level log with a message. `fields` param works the same as `Error`. Debug(message string, fields LoggingFields) }
Logger represents an logging interface that this library expects
type LoggingFields ¶
type LoggingFields map[string]interface{}
type Message ¶
type Message struct { Data interface{} `json:"data"` FormatVersion string `json:"format_version"` ID string `json:"id"` Metadata *metadata `json:"metadata"` Schema string `json:"schema"` DataSchemaVersion *semver.Version `json:"-"` // contains filtered or unexported fields }
Message model for hedwig messages.
func NewMessage ¶
func NewMessage(settings *Settings, dataType string, dataSchemaVersion string, headers map[string]string, data interface{}) (*Message, error)
NewMessage creates new Hedwig messages based off of message type and schema version
func (*Message) DataJSONString ¶
DataJSONString returns a string representation of Message
func (*Message) JSONString ¶
JSONString returns a string representation of Message
func (*Message) UnmarshalJSON ¶
UnmarshalJSON serializes the message from json
type MessageDefaultHeadersHook ¶
MessageDefaultHeadersHook is called to return default headers per message
type MessageRouteKey ¶
type MessageRouteKey struct { // Message type MessageType string // Message major version MessageMajorVersion int }
MessageRouteKey is a key identifying a message route
type NewData ¶
type NewData func() interface{}
NewData is a function that returns a pointer to struct type that a hedwig message data should conform to
type PreDeserializeHook ¶
PreDeserializeHook is called after a message has been deserialized from JSON, but before a Message is created and validated. This hook may be used to modify the format over the wire.
type PreProcessHookLambda ¶
type PreProcessHookLambda func(r *LambdaRequest) error
PreProcessHookLambda is called on a sns event before any processing happens for a lambda. This hook may be used to perform initializations such as set up a global request id based on message headers.
type PreProcessHookSQS ¶
type PreProcessHookSQS func(r *SQSRequest) error
PreProcessHookSQS is called on a message before any processing happens for a SQS queue. This hook may be used to perform initializations such as set up a global request id based on message headers.
type PreSerializeHook ¶
PreSerializeHook is called before a message is serialized to JSON. This hook may be used to modify the format over the wire.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher handles hedwig publishing for Automatic
type SQSRequest ¶
type SQSRequest struct { // Context for request Context context.Context // SQS message for this request QueueMessage *sqs.Message }
SQSRequest contains request objects for a SQS handler
type Settings ¶
type Settings struct { // AWS Region AWSRegion string // AWS account id AWSAccountID string // AWS access key AWSAccessKey string // AWS secret key AWSSecretKey string // AWS session tokenthat represents temporary credentials (i.e. for Lambda app) AWSSessionToken string // AWS read timeout for publisher AWSReadTimeoutS time.Duration // optional; default: 2 seconds // AWS debug request error logs toggle AWSDebugRequestLogEnabled bool // CallbackRegistry contains callbacks and message data factories by message type and message version CallbackRegistry *CallbackRegistry // GetLogger is a function that takes the context object and returns a logger. This may be used to plug in // your desired logger library. Defaults to using std library. // Convenience structs are provided for popular libraries: LogrusGetLoggerFunc GetLogger GetLoggerFunc // Returns default headers for a message before a message is published. This will apply to ALL messages. // Can be used to inject custom headers (i.e. request id). MessageDefaultHeadersHook MessageDefaultHeadersHook // Maps message type and major version to topic names // <message type>, <message version> => topic name // An entry is required for every message type that the app wants to consumer or publish. It is // recommended that major versions of a message be published on separate topics. MessageRouting map[MessageRouteKey]string // Hedwig pre process hook called before any processing is done on message PreProcessHookLambda PreProcessHookLambda // optional PreProcessHookSQS PreProcessHookSQS // optional // Hedwig hook called before a message is serialized to JSON PreSerializeHook PreSerializeHook // optional // Hedwig hook called before a message has been deserialized into a Message struct PreDeserializeHook PreDeserializeHook // optional // Publisher name Publisher string // Hedwig queue name. Exclude the `HEDWIG-` prefix QueueName string // ShutdownTimeout is the time the app has to shut down before being brutally killed ShutdownTimeout time.Duration // optional; defaults to 10s // Message validator using JSON schema for validation. Additional JSON schema formats may be added. // Please see github.com/santhosh-tekuri/jsonschema for more details. Validator IMessageValidator }
Settings for Hedwig