-
Notifications
You must be signed in to change notification settings - Fork 287
Publish and Subscribe Audit Events
With many contributions being added to the OSS, it is very useful to gather events for tracing/monitoring purposes. In OSS 0.5.7, we added new mechanism that can allow contributions to publish events or subscribe to events.
Any contribution can publish an event as shown below:
import github.com/TIBCOSoftware/flogo-lib/core/event
.....
event.PostEvent(<EVENT_TYPE>, <EVENT_DATA>)
For better performance, ensure that at-least one listener is registered for given event type by calling event.HasListener(<EVENT_TYPE>) before constructing event data.
To turn off events, set FLOGO_PUBLISH_AUDIT_EVENTS=false
https://github.com/TIBCOSoftware/flogo-contrib/blob/master/action/flow/event/flowevents.go https://github.com/TIBCOSoftware/flogo-contrib/blob/master/action/flow/instance/instance.go https://github.com/TIBCOSoftware/flogo-contrib/blob/master/action/flow/instance/taskinst.go
You can register a listener for the set of event types as shown below:
package mylistener
import github.com/TIBCOSoftware/flogo-lib/core/event
func init() {
event.RegisterEventListener(&MyListener{name: "Listener1"}, []string{<EVENT_TYPE1>,<EVENT_TYPE2>})
}
type MyListener struct {
name string
}
func (ls *MyListener) Name() string {
return ls.name
}
func (ls *MyListener) HandleEvent(evt *core.EventContext) error {
switch evt.GetType() {
case <EVENT_TYPE1>:
case <EVENT_TYPE2>:
}
return nil
}
In below example, listener is registered for Flow and Task events published by FLOW action.
package main
import (
"github.com/TIBCOSoftware/flogo-lib/logger"
core "github.com/TIBCOSoftware/flogo-lib/core/event"
flow "github.com/TIBCOSoftware/flogo-contrib/action/flow/event"
)
func init() {
core.RegisterEventListener(&MyListener{name: "Listener1"}, []string{flow.FLOW_EVENT_TYPE, flow.TASK_EVENT_TYPE})
}
type SmapleListener struct {
name string
}
func (ls *SmapleListener) Name() string {
return ls.name
}
func (ls *SmapleListener) HandleEvent(evt *core.EventContext) error {
// Handle flow and task events
switch t := evt.GetEvent().(type) {
case flow.FlowEvent:
logger.Infof("Name: %s, ID: %s, Status: %s ", t.FlowName(), t.FlowID(), t.FlowStatus())
case flow.TaskEvent:
logger.Infof("Name: %s, FID: %s, Status: %s", t.TaskName(), t.FlowID(), t.TaskStatus())
}
return nil
}