Example #1
0
func main() {
	agent, _ := zap.NewZapAgent()
	go agent.Run(&zap.OpenAccess{})
	defer agent.Destroy()

	broker_endpoint := "inproc://fancy-req"
	service := "echo"

	server_cert := czmq.NewCert()

	b, err := mdp.NewBroker(broker_endpoint)
	if err != nil {
		log.Fatalf("NewBroker(%s) failed: %s", broker_endpoint, err)
	}
	b.CurveCertificate = server_cert
	b.Bind("inproc://fancy-dealer")
	port, err := b.Bind("tcp://*:*")
	log.Printf("Broker available at binding: tcp://127.0.0.1:%d", port)
	go b.Run()

	// Start a worker.
	local_endpoint := fmt.Sprintf("tcp://127.0.0.1:%d", port)
	w := mdp.NewWorker(local_endpoint, service)
	w.CurveServerPublicKey = server_cert.PublicText()
	go w.Run(&echoWorker{})

	RunHTTP(":8111", "/zws/1.0")
}
Example #2
0
func main() {
	var settings Settings
	_, err := flags.Parse(&settings)
	if err != nil {
		switch err.(*flags.Error).Type {
		case flags.ErrHelp:
			os.Exit(0)
		default:
			log.Error(err.Error())
			os.Exit(1)
		}
	}

	broker_endpoint := "inproc://fancy-req"
	server_cert, err := czmq.NewCertFromFile(settings.ServerCertificatePath)
	if err != nil {
		log.Error(err.Error())
		os.Exit(1)
	}

	agent, _ := zap.NewZapAgent()
	// TODO(sissel): Gate access to prevent untrusted connections.
	go agent.Run(zap.NewRestrictedAccess())
	defer agent.Destroy()

	b, err := mdp.NewBroker(broker_endpoint)
	if err != nil {
		log.Fatalf("NewBroker(%s) failed: %s", broker_endpoint, err)
	}
	b.CurveCertificate = server_cert
	b.Bind("inproc://fancy-dealer")
	port, err := b.Bind("tcp://*:*")
	log.WithFields(log.Fields{"address": fmt.Sprintf("tcp://*:%d", port)}).Info("Broker available")
	go RunHTTP(":8111", "/zws/1.0")
	b.Run()
}