Newer
Older
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
package cmd
import (
"fmt"
"orus.io/xbus/xbus-stdlib/service"
"xbus.io/go-xbus/v4"
"xbus.io/go-xbus/v4/api"
)
type XbusOptions struct {
Config string `long:"config-file" ini-name:"config-file" description:"xbus client configuration file"`
}
func SetupXbusCmd(program *Program) *XbusCmd {
cmd := XbusCmd{}
c, err := program.Parser.AddCommand("xbus", "Standalone xbus client", "", &cmd)
if err != nil {
panic(err)
}
SetupXbusServeCmd(program, c)
return &cmd
}
type XbusCmd struct{}
func (p *Program) xbusClientOptions() (xbus.COptions, error) {
if p.XbusOptions.Config == "" {
return xbus.COptions{}, fmt.Errorf("%w: missing xbus.config-file", ErrInvalidConfiguration)
}
coptions, err := xbus.COptionsFromFile(p.XbusOptions.Config, api.Account_ACTOR, p.Logger)
// TODO allow the program user to make verifications on the configuration
return coptions, err
}
func (p *Program) xbusRegisterActors() error {
for _, factory := range p.setupXbusActors(p) {
switch f := factory.Factory.(type) {
case service.ConsumerFactory:
if err := service.RegisterConsumer(factory.Name, f); err != nil {
return err
}
case service.ConsumerFunc:
if err := service.RegisterConsumerFunc(factory.Name, f); err != nil {
return err
}
case service.WorkerFactory:
if err := service.RegisterWorker(factory.Name, f); err != nil {
return err
}
case service.WorkerFunc:
if err := service.RegisterWorkerFunc(factory.Name, f); err != nil {
return err
}
case xbus.NewActorServiceFunc:
xbus.RegisterActorService(factory.Name, f)
default:
return fmt.Errorf("%s has an factory type: %t", factory.Name, factory.Factory)
}
p.xbusActorNames = append(p.xbusActorNames, factory.Name)
}
return nil
}
func (p *Program) xbusUnregisterActors() {
for _, n := range p.xbusActorNames {
xbus.UnregisterActorService(n)
}
p.xbusActorNames = nil
}