Alex Ellis (OpenFaaS Ltd) c26ec5221e Updates for NATS Streaming support
NATS Streaming is deprecated and will be removed from OpenFaaS
CE in a future release for security reasons.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2023-01-17 21:55:48 +00:00

39 lines
910 B
Go

package handler
import (
"fmt"
"log"
"sync"
)
const sharedQueue = "faas-request"
// CreateNATSQueue ready for asynchronous message processing of paylods of
// up to a maximum of 256KB in size.
func CreateNATSQueue(address string, port int, clusterName, channel string, clientConfig NATSConfig) (*NATSQueue, error) {
var err error
natsURL := fmt.Sprintf("nats://%s:%d", address, port)
log.Printf("Opening connection to %s\n", natsURL)
clientID := clientConfig.GetClientID()
// If 'channel' is empty, use the previous default.
if channel == "" {
channel = sharedQueue
}
queue1 := NATSQueue{
ClientID: clientID,
ClusterID: clusterName,
NATSURL: natsURL,
Topic: channel,
maxReconnect: clientConfig.GetMaxReconnect(),
reconnectDelay: clientConfig.GetReconnectDelay(),
ncMutex: &sync.RWMutex{},
}
err = queue1.connect()
return &queue1, err
}