Documentation ¶
Index ¶
- func GetFields(val interface{}) map[string]interface{}
- func GetName(val interface{}) string
- func ValidateRegisteredType(obj interface{}, regType reflect.Type) bool
- func ValidateType(objType interface{}) bool
- type Event
- type EventMetadata
- type HandlerFunc
- type PublicationResult
- type Publisher
- type Subscriber
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 ValidateRegisteredType ¶
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 }
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 ¶
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 ¶
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 }