2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
21 Abstract: mangos (NNG) Pub/Sub SBI implementation
29 "nanomsg.org/go/mangos/v2"
30 "nanomsg.org/go/mangos/v2/protocol/pub"
31 _ "nanomsg.org/go/mangos/v2/transport/all"
36 var sock mangos.Socket
39 Creates the NNG publication channel
41 func openNngPub(url string) error {
43 if sock, err = pub.NewSocket(); err != nil {
44 return errors.New("can't get new pub socket due to:" + err.Error())
46 rtmgr.Logger.Info("publishing on: " + url)
47 if err = sock.Listen(url); err != nil {
48 return errors.New("can't publish on socket " + url + " due to:" + err.Error())
53 func closeNngPub() error {
54 if err := sock.Close(); err != nil {
55 return errors.New("can't close socket due to:" + err.Error())
60 func publishAll(policies *[]string) error {
61 for _, pe := range *policies {
62 if err := sock.Send([]byte(pe)); err != nil {
63 return errors.New("Unable to send policy entry due to: " + err.Error())
66 rtmgr.Logger.Info("NNG PUB: OK (# of Entries:" + strconv.Itoa(len((*policies))) + ")")