mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-21 07:14:48 -07:00
initial work on publish
This commit is contained in:
@@ -47,6 +47,7 @@ type Storage struct {
|
|||||||
// Config represents a configuration for a server.Server.
|
// Config represents a configuration for a server.Server.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Addr string `json:"addr"`
|
Addr string `json:"addr"`
|
||||||
|
PubAddr string `json:"pub_addr"`
|
||||||
Storage Storage `json:"storage"`
|
Storage Storage `json:"storage"`
|
||||||
|
|
||||||
Private bool `json:"private"`
|
Private bool `json:"private"`
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ var exampleJson = `{
|
|||||||
|
|
||||||
"network": "tcp",
|
"network": "tcp",
|
||||||
"addr": ":34000",
|
"addr": ":34000",
|
||||||
|
"pub_addr": "tcp://*:34001",
|
||||||
"storage": {
|
"storage": {
|
||||||
"driver": "redis",
|
"driver": "redis",
|
||||||
"addr": "127.0.0.1:6379",
|
"addr": "127.0.0.1:6379",
|
||||||
|
|||||||
28
server/publish.go
Normal file
28
server/publish.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2013 The Chihaya Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the BSD 2-Clause license,
|
||||||
|
// which can be found in the LICENSE file.
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
zmq "github.com/alecthomas/gozmq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) publish() {
|
||||||
|
context, err := zmq.NewContext()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer context.Close()
|
||||||
|
|
||||||
|
socket, err := context.NewSocket(zmq.PUB)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer socket.Close()
|
||||||
|
|
||||||
|
socket.Bind(s.conf.PubAddr)
|
||||||
|
|
||||||
|
for msg := range s.pubChan {
|
||||||
|
socket.Send([]byte(msg), 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,8 @@ type Server struct {
|
|||||||
|
|
||||||
waitgroup sync.WaitGroup
|
waitgroup sync.WaitGroup
|
||||||
|
|
||||||
|
pubChan chan string
|
||||||
|
|
||||||
http.Server
|
http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +48,7 @@ func New(conf *config.Config) (*Server, error) {
|
|||||||
s := &Server{
|
s := &Server{
|
||||||
conf: conf,
|
conf: conf,
|
||||||
dbConnPool: pool,
|
dbConnPool: pool,
|
||||||
|
pubChan: make(chan string),
|
||||||
Server: http.Server{
|
Server: http.Server{
|
||||||
Addr: conf.Addr,
|
Addr: conf.Addr,
|
||||||
ReadTimeout: conf.ReadTimeout.Duration,
|
ReadTimeout: conf.ReadTimeout.Duration,
|
||||||
@@ -66,6 +69,7 @@ func (s *Server) ListenAndServe() error {
|
|||||||
s.startTime = time.Now()
|
s.startTime = time.Now()
|
||||||
|
|
||||||
go s.updateRPM()
|
go s.updateRPM()
|
||||||
|
go s.publish()
|
||||||
s.Serve(s.listener)
|
s.Serve(s.listener)
|
||||||
|
|
||||||
s.waitgroup.Wait()
|
s.waitgroup.Wait()
|
||||||
@@ -79,6 +83,7 @@ func (s *Server) Stop() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
close(s.pubChan)
|
||||||
return s.listener.Close()
|
return s.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,33 +3,54 @@ exec { 'echo this works': }
|
|||||||
|
|
||||||
group { 'puppet': ensure => 'present' }
|
group { 'puppet': ensure => 'present' }
|
||||||
|
|
||||||
exec { 'chown -R vagrant:vagrant /home/vagrant/': }
|
exec { 'chown -R vagrant:vagrant /home/vagrant/':
|
||||||
|
}
|
||||||
|
|
||||||
exec { 'apt-get update':
|
exec { 'apt-get update':
|
||||||
command => '/usr/bin/apt-get update',
|
command => '/usr/bin/apt-get update',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec { 'add-apt-repository ppa:chris-lea/zeromq && apt-get update':
|
||||||
|
require => Package['python-software-properties'],
|
||||||
|
alias => 'zmq_repo',
|
||||||
|
creates => '/etc/apt/sources.list.d/chris-lea-zeromq-precise.list',
|
||||||
|
}
|
||||||
|
|
||||||
exec { 'add-apt-repository ppa:duh/golang && apt-get update':
|
exec { 'add-apt-repository ppa:duh/golang && apt-get update':
|
||||||
alias => 'go_repo',
|
alias => 'go_repo',
|
||||||
creates => '/etc/apt/sources.list.d/gophers-go-precise.list',
|
creates => '/etc/apt/sources.list.d/gophers-go-precise.list',
|
||||||
require => Package['python-software-properties'],
|
require => Package['python-software-properties'],
|
||||||
}
|
}
|
||||||
|
|
||||||
package { 'python-software-properties':
|
package { 'pkg-config':
|
||||||
ensure => present,
|
|
||||||
require => Exec['apt-get update'],
|
require => Exec['apt-get update'],
|
||||||
|
ensure => present,
|
||||||
|
}
|
||||||
|
|
||||||
|
package { 'libzmq-dev':
|
||||||
|
require => [
|
||||||
|
Exec['zmq_repo'],
|
||||||
|
Package['pkg-config'],
|
||||||
|
],
|
||||||
|
ensure => present,
|
||||||
|
}
|
||||||
|
|
||||||
|
package { 'python-software-properties':
|
||||||
|
require => Exec['apt-get update'],
|
||||||
|
ensure => present,
|
||||||
}
|
}
|
||||||
|
|
||||||
package { 'git':
|
package { 'git':
|
||||||
ensure => present,
|
|
||||||
require => Exec['apt-get update'],
|
require => Exec['apt-get update'],
|
||||||
|
ensure => present,
|
||||||
}
|
}
|
||||||
|
|
||||||
package { 'golang':
|
package { 'golang':
|
||||||
ensure => present,
|
|
||||||
require => Exec['go_repo'],
|
require => Exec['go_repo'],
|
||||||
|
ensure => present,
|
||||||
}
|
}
|
||||||
|
|
||||||
exec { 'echo "export GOPATH=/home/vagrant/chihaya" > /etc/profile.d/gopath.sh':
|
exec { 'echo "export GOPATH=/home/vagrant/chihaya" > /etc/profile.d/gopath.sh':
|
||||||
|
alias => 'go_path',
|
||||||
creates => '/etc/profile.d/gopath.sh',
|
creates => '/etc/profile.d/gopath.sh',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user