+15
-1
README.md
+15
-1
README.md
···
20
21
When sending a message representing an action (subscribe, publish etc) then a uint16 binary message is sent.
22
23
+
When sending any other data, the length of the data is to be sent first using a binary uint32 and then the actual data sent afterwards.
24
+
25
+
## Running the server
26
+
27
+
There is a server that can be run using `docker-compose up message-server`. This will start a server running listening on port 3000.
28
+
29
+
## Example clients
30
+
There is an example application that implements the subscriber and publishers in the `example` directory.
31
+
32
+
Run `go build .` to build the file.
33
+
34
+
When running the example there are the following flags:
35
+
36
+
`publish` : settings this to true will allow messages to be sent every 500ms as well as consuming
37
+
`consume-from` : this allows you to specify what message to start from. If you don't set this or set it to be -1, you will start consuming from the next sent message.
+7
docker-compose.yaml
+7
docker-compose.yaml
+1
-1
dockerfile.example-server
dockerfile.server
+1
-1
dockerfile.example-server
dockerfile.server
+9
-5
example/main.go
+9
-5
example/main.go
···
11
"github.com/willdot/messagebroker/internal/server"
12
)
13
14
-
var consumeOnly *bool
15
var consumeFrom *int
16
17
func main() {
18
-
consumeOnly = flag.Bool("consume-only", false, "just consumes (doesn't start server and doesn't publish)")
19
consumeFrom = flag.Int("consume-from", -1, "index of message to start consuming from. If not set it will consume from the most recent")
20
flag.Parse()
21
22
-
if !*consumeOnly {
23
go sendMessages()
24
}
25
···
38
startAt = *consumeFrom
39
}
40
41
-
err = sub.SubscribeToTopics([]string{"topic a"}, startAtType, startAt)
42
if err != nil {
43
panic(err)
44
}
···
69
i := 0
70
for {
71
i++
72
-
msg := client.NewMessage("topic a", []byte(fmt.Sprintf("message %d", i)))
73
74
err = publisher.PublishMessage(msg)
75
if err != nil {
···
11
"github.com/willdot/messagebroker/internal/server"
12
)
13
14
+
var publish *bool
15
var consumeFrom *int
16
17
+
const (
18
+
topic = "topic-a"
19
+
)
20
+
21
func main() {
22
+
publish = flag.Bool("publish", false, "will also publish messages every 500ms until client is stopped")
23
consumeFrom = flag.Int("consume-from", -1, "index of message to start consuming from. If not set it will consume from the most recent")
24
flag.Parse()
25
26
+
if *publish {
27
go sendMessages()
28
}
29
···
42
startAt = *consumeFrom
43
}
44
45
+
err = sub.SubscribeToTopics([]string{topic}, startAtType, startAt)
46
if err != nil {
47
panic(err)
48
}
···
73
i := 0
74
for {
75
i++
76
+
msg := client.NewMessage(topic, []byte(fmt.Sprintf("message %d", i)))
77
78
err = publisher.PublishMessage(msg)
79
if err != nil {
example/server/main.go
cmd/server/main.go
example/server/main.go
cmd/server/main.go