Example #1
0
func main() {
	scamp.Initialize()

	service, err := scamp.NewService(":30100")
	if err != nil {
		scamp.Error.Fatalf("error creating new service: `%s`", err)
	}
	service.Register("helloworld.hello", func(req scamp.Request, sess *scamp.Session) {
		if len(req.Blob) > 0 {
			scamp.Info.Printf("helloworld had data: %s", req.Blob)
		} else {
			scamp.Trace.Printf("helloworld was called without data")
		}

		err = sess.SendReply(scamp.Reply{
			Blob: famous_words,
		})
		if err != nil {
			scamp.Error.Printf("error while sending reply: `%s`. continuing.", err)
			return
		}
		scamp.Trace.Printf("successfully responded to hello world")
	})

	service.Run()
}
Example #2
0
func main() {
	scamp.Initialize()

	conn, err := scamp.Connect("127.0.0.1:30100")
	defer conn.Close()

	if err != nil {
		scamp.Error.Fatalf("could not connect! `%s`\n", err)
	}

	var sess *scamp.Session

	sess, err = conn.Send(scamp.Request{
		Action:         "sup.dude",
		EnvelopeFormat: scamp.ENVELOPE_JSON,
		Version:        1,
	})
	if err != nil {
		scamp.Error.Fatalf("error initiating session: `%s`", err)
	}

	reply, err := sess.RecvReply()
	if err != nil {
		scamp.Error.Fatalf("error receiving: `%s`", err)
	}
	scamp.Info.Printf("Got reply! `%s`", reply.Blob)
}
Example #3
0
func main() {
	scamp.Initialize("/etc/SCAMP/soa.conf")

	service, err := scamp.NewService(":30100", "staticdev")
	if err != nil {
		scamp.Error.Fatalf("error creating new service: `%s`", err)
	}

	// rename Register -> RegisterAction
	service.Register("Logger.log", func(req *scamp.Message, client *scamp.Client) {
		scamp.Info.Printf("received msg len: %d", len(req.Bytes()))

		reply := scamp.NewMessage()
		reply.SetMessageType(scamp.MESSAGE_TYPE_REPLY)
		reply.SetEnvelope(scamp.ENVELOPE_JSON)
		reply.SetRequestId(req.RequestId)
		reply.Write([]byte("{}"))

		_, err = client.Send(reply)
		if err != nil {
			scamp.Error.Printf("could not reply to message: `%s`", err)
			return
		}
	})

	serviceDone := make(chan bool)
	go func() {
		service.Run()
		serviceDone <- true
	}()

	sigUsr1 := make(chan os.Signal)
	signal.Notify(sigUsr1, syscall.SIGUSR1)
	select {
	case <-sigUsr1:
		scamp.Info.Printf("shutdown requested")
		service.Stop()
	}

	select {
	case <-serviceDone:
		scamp.Info.Printf("service exiting gracefully")
	}

	scamp.Info.Printf("going to timeout so you can send a SIGQUIT and dump the goroutines...")
	select {
	case <-time.After(time.Duration(1) * time.Minute):
		scamp.Info.Printf("1 minute timeout achieved")
	}
}
Example #4
0
func oldmain() {
	bigMsg := make([]byte, 256)
	scamp.Initialize("/etc/SCAMP/soa.conf")

	client, err := scamp.Dial("127.0.0.1:30100")
	defer client.Close()
	if err != nil {
		scamp.Error.Fatalf("could not connect! `%s`\n", err)
		return
	}

	i := 0
	for i = 0; i < len(bigMsg); i++ {
		bigMsg[i] = 'f'
	}

	message := scamp.NewMessage()
	message.SetRequestId(1234)
	message.SetAction("Logger.log")
	message.SetEnvelope(scamp.ENVELOPE_JSON)
	message.SetVersion(1)
	message.SetMessageType(scamp.MESSAGE_TYPE_REQUEST)
	// message.Write([]byte(`hey logger`))
	message.Write(bigMsg)

	recvChan, err := client.Send(message)
	if err != nil {
		scamp.Error.Fatalf("could not send message: `%s`\n", err)
		return
	}

	select {
	case response, ok := <-recvChan:
		if !ok {
			scamp.Error.Printf("recvChan was closed. exiting.")
		} else {
			scamp.Info.Printf("got reply: %s", response.Bytes())
		}
	case <-time.After(timeout):
		scamp.Error.Fatalf("failed to get reply before timeout")
	}

	select {
	case <-time.After(timeout):
		scamp.Info.Printf("done waiting")
	}

	client.Close()
}
Example #5
0
func main() {
	scamp.Initialize("/etc/SCAMP/soa.conf")
	client, err := scamp.Dial("127.0.0.1:30100")
	defer client.Close()
	if err != nil {
		scamp.Error.Fatalf("could not connect! `%s`\n", err)
		return
	}

	for i := 0; i < 10; i++ {
		message := scamp.NewMessage()
		message.SetRequestId(i + 1)
		message.SetAction("Logger.log")
		message.SetEnvelope(scamp.ENVELOPE_JSON)
		message.SetVersion(1)
		message.SetMessageType(scamp.MESSAGE_TYPE_REQUEST)
		// message.Write([]byte(`hey logger`))
		msgBytes := []byte(fmt.Sprintf("TEST MESSAGE %d\n", i))
		message.Write(msgBytes)

		recvChan, err := client.Send(message)
		if err != nil {
			scamp.Error.Fatalf("could not send message: `%s`\n", err)
			return
		}

		select {
		case response, ok := <-recvChan:
			if !ok {
				scamp.Error.Printf("recvChan was closed. exiting.")
			} else {
				scamp.Info.Printf("got reply: %s", response.Bytes())
			}
		case <-time.After(timeout):
			scamp.Error.Fatalf("failed to get reply before timeout")
		}

		time.Sleep(time.Duration(500) * time.Millisecond)

	}

	select {
	case <-time.After(timeout):
		scamp.Info.Printf("done waiting")
	}
}
Example #6
0
func main() {
	scamp.Initialize()

	conn, err := scamp.Connect("127.0.0.1:30101")
	defer conn.Close()

	if err != nil {
		scamp.Error.Fatalf("could not connect! `%s`\n", err)
	}

	var sess *scamp.Session

	inflight := make(chan bool, 500)

	for {
		inflight <- true

		go func() {
			sess, err = conn.Send(scamp.Request{
				Action:         "helloworld.hello",
				EnvelopeFormat: scamp.ENVELOPE_JSON,
				Version:        1,
			})
			if err != nil {
				scamp.Error.Fatalf("error initiating session: `%s`", err)
			}

			reply, err := sess.RecvReply()
			if err != nil {
				scamp.Error.Fatalf("error receiving: `%s`", err)
			}
			scamp.Info.Printf("Got reply! `%s`", reply.Blob)

			<-inflight
		}()
	}
}
Example #7
0
func main() {
	scamp.Initialize()
	scamp.NewConfig()
}