-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (64 loc) · 1.81 KB
/
Copy pathmain.go
File metadata and controls
68 lines (64 loc) · 1.81 KB
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
package main
/*
The starter example, that you can plug into your orchestrator and start writing handlers
The starter example uses mongodb as persistence and rabbitmq as transport
You can configure as many transaction types
The custom-handler example demonstrates how to override the default handler with custom logic
*/
import (
"os"
"github.com/paladium/cubequeue"
"github.com/paladium/cubequeue/databases"
"github.com/paladium/cubequeue/models"
"github.com/sirupsen/logrus"
)
func setLogging() {
logrus.SetFormatter(&logrus.TextFormatter{
DisableColors: true,
FullTimestamp: true,
})
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.DebugLevel)
}
func main() {
queue := "cubequeue"
//Setup the logging
setLogging()
transport, err := cubequeue.NewTransactionTransport(cubequeue.TransactionTransportConnectionSetting{
URL: "amqp://guest:guest@localhost:5672",
Queue: cubequeue.GetDefaultQueueSetting(queue),
})
if err != nil {
panic(err)
}
database, err := databases.NewTransactionMongoDBDatabase("mongodb://localhost:27017", "cubequeue", "transactions")
if err != nil {
panic(err)
}
orchestrator := cubequeue.NewTransactionOrchestrator(&models.TransactionConfig{
Services: map[string]models.TransactionService{
"backend": {
Description: "Main backend",
Name: "backend",
Queue: "cube-backend",
},
"billing": {
Description: "Billing service",
Name: "billing",
Queue: "cube-billing",
},
},
Transactions: map[string]models.Transaction{
"account.create": {
Description: "Create a new account",
Stages: []string{
"backend",
"billing",
},
},
},
}, transport, database)
orchestrator.Run(cubequeue.RoutingTable{
"account.create": cubequeue.GetDefaultRoutingHandler(),
}, cubequeue.GetDefaultSubscribeSettings(queue))
}