queuesgo

package module
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

Queues management

Management of asynchronous tasks between backend services

Status

This is a new library and is considered to be in Beta and the APIs can change as we adapt more use cases.

We'll follow semantic versioning, so, once we reach a stable state and release 1.0.0 API's should be stable inside releases with the same major number.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFields

func GetFields(val interface{}) map[string]interface{}

Returns a map string key, val interface with key: the name of the field, if it have a json tag it will take the tag name value: the type of the field if is primitive (string, int, long. bool...) as string if is a complex type (structure, map, slice) the value will have an slice with 2 positions the first position indicates the type, array for slices, map or the name of the structure the second position indicates the type of the slice or map, a map with the previous rules for embedded structures with maps you can assume a key string as it is the most usual, but for maps there is an extra position with the key type

func GetName

func GetName(val interface{}) string

func ValidateRegisteredType

func ValidateRegisteredType(obj interface{}, regType reflect.Type) bool

func ValidateType

func ValidateType(objType interface{}) bool

Types

type Event

type Event struct {
	Payload  interface{}   `json:"payload"`  // JSON body of the actual message
	Metadata EventMetadata `json:"metadata"` // Event info
}

func (Event) String

func (t Event) String() string

type EventMetadata

type EventMetadata struct {
	UserID        string `json:"user_id"`        // Id of the user triggering the event
	CorrelationID string `json:"correlation_id"` // Unique ID of the event, generated as is triggered the first time
	EventName     string `json:"event_name"`     // Event name (Shouldn't include origin or destination as is implicit on the topic/subscription and the extra origin field)
	Origin        string `json:"origin"`         // Service originating the event
	Timestamp     int64  `json:"timestamp"`      // Moment of the event generation (epoch millis)
	ObjectID      string `json:"object_id"`      // ID of the object changing on the event
}

func (*EventMetadata) IsZero

func (em *EventMetadata) IsZero() bool

type HandlerFunc

type HandlerFunc func(context.Context, Event) (bool, error)

Function that will handle the Event received, it should return if the message should be acknowledge to the queue provider, true to ack, false to indicate a eventual resend (The resend will depend of the subscriber implementation) The event payload will contain the information of the registered object type (If the registered type wasn't a pointer, it will return a pointer)

type PublicationResult

type PublicationResult struct {
	Result string
	Err    error
}

Async publication structure containing the expected sync response

type Publisher

type Publisher interface {
	/*
		Send a event to the topic registered on the chosen implementation waiting for the server confirmation
		This DOES NOT wait for the subscriber, just for the queue provider to acknowledge the message is queue.
		Returns a string with a success confirmation message according to the implementation, empty if an error occurs
		Returns an error if the given event is incorrect (Wrong payload type compared to the registered on the construction, missing metadata)
		Returns an error if the queue provider fails to send the message
	*/
	PublishSync(ctx context.Context, event *Event) (string, error)
	/*
		Send a event to the topic registered on the chosen implementation, without the queue provider server confirmation
		Returns a channel that will be closed when the queue provider server finish the execution
		The structure contained on the channel has not purpose on this version
		Returns error if the given event is incorrect (Wrong payload type compared to the registered on the construction, missing metadata)
	*/
	PublishAsync(ctx context.Context, event *Event) (<-chan PublicationResult, error)
}

type Subscriber

type Subscriber interface {
	/*
		Register the function to ve available on the subscription
		eventName: event that needs to be handled
		handler: the handler function that will be called when an event with the given name is the eventName given
	*/
	RegisterFunction(eventName string, handler HandlerFunc) error
	/*
		Blocks the current go routine to wait for events on the subscription name given on the chosen implementation
	*/
	Subscribe(ctx context.Context) error
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL