-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel.go
36 lines (31 loc) · 1.06 KB
/
channel.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
package mq
import (
"github.com/c3sr/mq/interfaces"
"github.com/google/uuid"
)
// channel implements interfaces.Channel.
type channel struct {
queueName string
queueChannel interfaces.QueueChannel
}
// SendMessage wraps the given message string in an interfaces.Message and sends
// it to the underlying message queue.
//
// A random UUID is generated and assigned to the Message's CorrelationId. This
// UUID is returned.
func (c *channel) SendMessage(message string) (correlationId string, err error) {
correlationId = uuid.New().String()
err = c.SendResponse(message, correlationId)
return correlationId, err
}
// SendResponse wraps the given message string in an interfaces.Message and sends
// it to the underlying message queue.
//
// The given correlationId is assigned the the Message's CorrelationId.
func (c *channel) SendResponse(message string, correlationId string) error {
return c.queueChannel.Publish("", c.queueName, false, false, interfaces.Message{
ContentType: "text/plain",
CorrelationId: correlationId,
Body: []byte(message),
})
}