-
Notifications
You must be signed in to change notification settings - Fork 0
/
servicebus.go
154 lines (126 loc) · 2.51 KB
/
servicebus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* =========================================================================== *
* define all interface in this file
* =========================================================================== *
*/
package servicebus
import (
"github.com/1-bi/uerrors"
"time"
)
/**
* create all interface context
*/
type ServiceEvent interface {
/**
* call one service handle
*/
On(serviceId string, fn func(ServiceEventHandler)) error
/**
* fire service in synchronous mode
*/
FireSyncService(serviceId string, runtimeArgs interface{}, timeout time.Duration, fn func(FutureReturnResult, uerrors.CodeError))
/**
* fire service in asynchronous mode
*/
FireService(serviceId string, runtimeArgs interface{}) error
}
/**
* create the service agent
*/
type ServiceAgent interface {
ServiceEvent
}
/**
* contruct service manager
*/
type ServiceManager interface {
ServiceEvent
/**
* boot listen service
*/
ListenServices() error
}
// --- create bus context ----
type EventbusContext interface {
GetRequestData() interface{}
/**
* Get the result inteface
*/
GetResult() Result
/**
* support service event
*/
GetServiceEvent() ServiceEvent
}
/**
* define base result
*/
type Result interface {
/**
* complement object
*/
Complete(refobj interface{})
/**
* add the result
*/
Fail(err uerrors.CodeError)
}
/**
* contruct service event handler
* @deplecated this object is not to use
*/
type ServiceEventHandler interface {
/**
* define request body object
*/
ConvertRequestBody(func() (reqData interface{}))
/**
* define process handler
*/
Process(func(bc EventbusContext) uerrors.CodeError)
}
/**
* return the service event futrue
*/
type Future interface {
/**
* wait the event complete
*/
Await() uerrors.CodeError
/**
* get the result object after await
*/
GetResult() (FutureReturnResult, uerrors.CodeError)
}
/**
* This interface will map the futurn result handle
*/
type FutureReturnResult interface {
/**
* define, ALL_COMPLETE , ANY_ERRORS , ALL_ERRORS
*/
State() int8
/**
* return all error from service event running
*/
Errors(procName string) uerrors.CodeError
/**
* rturn all return Results
*/
ReturnResults(procName string, inReturn interface{}) uerrors.CodeError
/**
* get the first error directly
*/
Error() uerrors.CodeError
/**
* get the first result directly
*/
ReturnResult(inReturn interface{}) uerrors.CodeError
}
/**
* define root type decoder
*/
type RootTypeDecoder interface {
ProvideRootRef() interface{}
}