-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeclare.go
55 lines (46 loc) · 1.28 KB
/
declare.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
/*
* Copyright (c) 2021-present unTill Pro, Ltd.
*/
package router2
import (
"context"
"encoding/json"
"time"
ibus "github.com/untillpro/airs-ibus"
ibusnats "github.com/untillpro/airs-ibusnats"
"github.com/untillpro/godif"
"github.com/untillpro/godif/services"
)
func DeclareEmbeddedRouter(routerSrv Service) {
queuesNames := []string{}
for name := range routerSrv.QueuePartitions {
queuesNames = append(queuesNames, name)
}
queueNamesJSON, _ = json.Marshal(&queuesNames) // error impossible
godif.ProvideSliceElement(&services.Services, &routerSrv)
if len(routerSrv.NATSServers) > 0 {
godif.Require(&ibus.SendRequest2)
}
}
func Declare(ctx context.Context, cqn ibusnats.CurrentQueueName, busTimeout time.Duration) {
queues := ibusnats.QueuesPartitionsMap{
"airs-bp": airsBPPartitionsAmount,
}
params := ProvideRouterParamsFromCmdLine()
params.QueuesPartitions = queues
if len(params.NATSServers) > 0 {
ibusnatsSrv := &ibusnats.Service{
NATSServers: params.NATSServers,
Queues: queues,
CurrentQueueName: cqn,
Verbose: ibusnats.Verbose(params.Verbose),
}
ibusnats.Declare(ibusnatsSrv)
}
routerSrv := Service{
RouterParams: params,
QueuePartitions: queues,
busTimeout: busTimeout,
}
DeclareEmbeddedRouter(routerSrv)
}