| | |
| | | |
| | | import ( |
| | | "log" |
| | | "strings" |
| | | "time" |
| | | |
| | | "golang.org/x/net/context" |
| | |
| | | ctx context.Context |
| | | sock mangos.Socket |
| | | |
| | | publishCh chan []string |
| | | publishCh chan []byte |
| | | } |
| | | |
| | | func Server(urlServer string, urlPubSub string, opt Options) (*DiscoveryServer, error) { |
| | |
| | | d.services.Add(responses) |
| | | return |
| | | } |
| | | //fmt.Println(" err: ",err.Error()) |
| | | //log.Println("DiscoveryServer: Error reading SURVEY responses", err.Error()) |
| | | } else { |
| | | responses.Add(string(msg)) |
| | | } |
| | |
| | | url: url, |
| | | sock: sock, |
| | | |
| | | publishCh: make(chan []string), |
| | | publishCh: make(chan []byte), |
| | | } |
| | | |
| | | go publiser.run() |
| | | return publiser, nil |
| | | } |
| | | |
| | | func (p *Publisher) Publish(msg []string) { |
| | | func (p *Publisher) Publish(msg []byte) { |
| | | p.publishCh <- msg |
| | | } |
| | | |
| | |
| | | close(p.publishCh) |
| | | return |
| | | case msg := <-p.publishCh: |
| | | err := p.sock.Send([]byte(strings.Join(msg, "|"))) |
| | | err := p.sock.Send(msg) |
| | | if err != nil { |
| | | log.Println("DiscoveryServer: Error PUBLISHING changes to the socket", err.Error()) |
| | | } |
| | |
| | | //s.publisher.Publish(s.nodes.ToSlice())//publish nodes changed |
| | | } |
| | | |
| | | func (d *DiscoveryServer) PublishMsg(msg string){ |
| | | d.services.publisher.Publish([]string{msg}) |
| | | } |
| | | func (d *DiscoveryServer) PublishMsg(msg string) { |
| | | d.services.publisher.Publish([]byte(msg)) |
| | | } |