This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicPublisher.go
68 lines (54 loc) · 1.58 KB
/
basicPublisher.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
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/KrylixZA/GoRabbitMqBroker/bindingType"
"github.com/KrylixZA/GoRabbitMqBroker/broker"
"github.com/KrylixZA/GoRabbitMqBroker/logs"
"github.com/KrylixZA/GoRabbitMqBroker/models"
uuid "github.com/satori/go.uuid"
)
func main() {
numOfMsgsToPublish := flag.Int("n", 1, "Defines the number of messages to publish to RabbitMQ.")
flag.Parse()
log.Printf("Publishing %d messages...", *numOfMsgsToPublish)
publisherConfig := models.Config{
Username: "admin",
Password: "admin",
RabbitMqHost: "localhost",
VirtualHost: "/",
PublisherConfig: &models.PublisherConfig{
ExchangeName: "amq.topic",
BindingType: bindingType.Topic,
Durable: true,
MandatoryQueueBind: false,
},
}
broker := broker.NewMessagePublisher(publisherConfig, logs.Logger{})
defer broker.Close()
for i := 0; i < *numOfMsgsToPublish; i++ {
testDataPayload := basicDistributedMessage{
Data: fmt.Sprintf("[%d] My test message", i),
}
broker.Publish("myTestRoutingKey", testDataPayload)
}
}
type basicDistributedMessage struct {
Data string `json:"data"`
}
func (distributedMessage basicDistributedMessage) GetData() interface{} {
return distributedMessage.Data
}
func (distributedMessage basicDistributedMessage) GetTimestamp() time.Time {
return time.Now()
}
func (distributedMessage basicDistributedMessage) GetMessageId() string {
uuId, _ := uuid.NewV4()
return uuId.String()
}
func (distributedMessage basicDistributedMessage) GetCorrelationId() string {
uuId, _ := uuid.NewV4()
return uuId.String()
}