func ZmqRead(key_type string, key string) string { rep_port, err_rep_port := strconv.Atoi(*LifeCycleConfig["db_rep_port"]) req_port, err_req_port := strconv.Atoi(*LifeCycleConfig["db_req_port"]) if err_rep_port != nil || err_req_port != nil { golerror.Boohoo("Port parameters to bind, error-ed while conversion to number.", true) } sock := golzmq.ZmqRequestSocket(*LifeCycleConfig["db_uri"], rep_port, req_port) response, _ := golzmq.ZmqRequest(sock, "read", key_type, key) return response }
/* proxyDestination create a ZMQ Proxy Reader from source of Proxy. */ func proxyDestination(destination *EngineDestination) error { socket := golzmq.ZmqRequestSocket(destination.DestinationIP, destination.DestinationPorts) for { request := <-destination.DestinationChannel reply, errorRequest := golzmq.ZmqRequestByte(socket, request) if errorRequest != nil { fmt.Println("ERROR:", errorRequest) return errorRequest } destination.SourceChannel <- reply } }
func ZmqRequest(ip string, ports []int, request string) { _socket := golzmq.ZmqRequestSocket(ip, ports) val, err := golzmq.ZmqRequest(_socket, request) golassert.AssertEqual(err, nil) fmt.Println(val) }
"flag" "fmt" "time" golassert "github.com/abhishekkr/gol/golassert" golhashmap "github.com/abhishekkr/gol/golhashmap" golzmq "github.com/abhishekkr/gol/golzmq" goshare "github.com/abhishekkr/goshare" goshare_requestor "github.com/abhishekkr/goshare/requestor" ) var ( request_port01 = flag.Int("req-port01", 9797, "what Socket PORT to run at") request_port02 = flag.Int("req-port02", 9898, "what Socket PORT to run at") zmqSock = golzmq.ZmqRequestSocket("127.0.0.1", []int{*request_port01, *request_port02}) result, expected string err error ) // for key-type default func TestDefaultKeyType() { result, err = golzmq.ZmqRequest(zmqSock, "push", "default", "myname", "anon") expected = "" golassert.AssertEqual(result, expected) golassert.AssertEqual(err, nil) result, err = golzmq.ZmqRequest(zmqSock, "read", "default", "myname") expected = "myname,anon" golassert.AssertEqual(result, expected) golassert.AssertEqual(err, nil)
gollog "github.com/abhishekkr/gol/gollog" golzmq "github.com/abhishekkr/gol/golzmq" ) var ( ip_address = flag.String("ip", "0.0.0.0", "IP address of Chaac's Hand") req_port = flag.Int("req-port", 9797, "what Socket PORT to run at") rep_port = flag.Int("rep-port", 9898, "what Socket PORT to run at") put_interval = flag.Int("put-interval", 10, "at what time interval(seconds) to push the results") get_interval = flag.Int("get-interval", 15, "at what time interval(seconds) to pull the configs") host_id = flag.String("host-id", "node", "prefix-ed namespace added to hostnames") logFilename = flag.String("logfile", "", "path to log to") hostname, _ = os.Hostname() hostSignature = fmt.Sprintf("%s:%s", *host_id, hostname) request_socket = golzmq.ZmqRequestSocket(*ip_address, *req_port, *rep_port) LogFile *os.File ) func init() { flag.Parse() fmt.Printf("client ZeroMQ REP/REQ... at %d, %d\n", *req_port, *rep_port) if *logFilename == "" { *logFilename = fmt.Sprintf("%s.log", os.Args[0]) } LogFile = gollog.OpenLogFile(*logFilename) }