Skip to content
Snippets Groups Projects
publishmessage.go 727 B
package produce

import (
	"github.com/streadway/amqp"
)

// PublishMessage will publish the message to the queue retrieved from the key value store, with the given sessionID
func (s *Service) PublishMessage(data *[]byte, sessionID *string) {
	// Use the sessionID to query the key value store to get the queue we need to send this message to
	clientQueueID := s.keyValueStore.Get(sessionID)

	// If this client has now disconnected
	if clientQueueID == "" {
		// TODO: Decide whether to throw away the message or perhaps cache it, for now throw it away
		return
	}

	headers := amqp.Table{}
	headers["sessionID"] = *sessionID
	headers["type"] = "queryResult"
	s.producerDriver.PublishMessage(data, &clientQueueID, &headers)
}