-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (48 loc) · 1.56 KB
/
main.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
package main
/*
The starter example - minimum example that shows how to use client part of the library to execute and process transactions
*/
import (
"os"
"github.com/paladium/cubequeue"
"github.com/paladium/cubequeue/client"
"github.com/paladium/cubequeue/databases"
"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 := "billing"
//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", "billing", "transactions")
if err != nil {
panic(err)
}
//Configure the ServiceName - the same name should be used for your orchestrator
//TransactionQueue - where to publish the transaction to after processing it
//SubscribeSettings - how to subscribe to the queue
worker := client.NewBackgroundWorker(transport, database, &client.BackgroundWorkerSettings{
ServiceName: "billing",
TransactionQueue: "cubequeue",
SubscribeSettings: cubequeue.GetDefaultSubscribeSettings(queue),
})
worker.Run(client.TransactionRoutingTable{
"account.create": client.GetDefaultTransactionRoutingHandler(),
}, client.TransactionRoutingTable{
"account.create": client.GetDefaultTransactionRoutingHandler(),
})
}