コード例 #1
0
ファイル: receiver1.go プロジェクト: ra/go-samp
func recMessages(c *stompngo.Connection, q string) {

	var error error

	fmt.Printf("Start for q: %s\n", q)
	// Receive phase
	headers := stompngo.Headers{"destination", q}
	fmt.Printf("qhdrs: %v\n", headers)
	_, error = c.Subscribe(headers)
	if error != nil {
		// Handle error properly
		log.Fatalf("sub error: %v\n", error)
	}
	for input := range c.MessageData {
		inmsg := input.Message.BodyString()
		if printMsgs {
			fmt.Println("queue:", q, "Next Receive: ", inmsg)
		}
		incrCtl.Lock()
		numRecv++
		incrCtl.Unlock()
		if strings.HasPrefix(inmsg, "***EOF***") {
			fmt.Printf("goteof: %v %v\n", q, inmsg)
			break
		}
	}
	wg.Done()
}
コード例 #2
0
ファイル: receiver1.go プロジェクト: gmallard/go-samp
func recMessages(c *stompngo.Connection, q string) {

	var error error

	fmt.Printf("Start for q: %s\n", q)
	// Receive phase
	headers := stompngo.Headers{"destination", q}
	fmt.Printf("qhdrs: %v\n", headers)
	sc, error := c.Subscribe(headers)
	if error != nil {
		// Handle error properly
		log.Fatalf("sub error: %v\n", error)
	}
	var md stompngo.MessageData
	var inmsg string
	for {
		select {
		case md = <-c.MessageData:
			log.Fatalf("unexpected message: %v\n", md)
		case md = <-sc:
			inmsg = md.Message.BodyString()
		}
		if printMsgs {
			fmt.Println("queue:", q, "Next Receive: ", inmsg)
		}
		incrCtl.Lock()
		numRecv++
		incrCtl.Unlock()
		if strings.HasPrefix(inmsg, "***EOF***") {
			fmt.Printf("goteof: %v %v\n", q, inmsg)
			break
		}
	}
	wg.Done()
}
コード例 #3
0
ファイル: noPMod1.go プロジェクト: gmallard/stompngo_examples
// Handle a subscribe for the different protocol levels.
func doSubscribe(c *stompngo.Connection, d, id, a string, h stompngo.Headers) <-chan stompngo.MessageData {
	h = h.Add("destination", d).Add("ack", a)
	//
	switch c.Protocol() {
	case stompngo.SPL_12:
		// Add required id header
		h = h.Add("id", id)
	case stompngo.SPL_11:
		// Add required id header
		h = h.Add("id", id)
	case stompngo.SPL_10:
		// Nothing else to do here
	default:
		ll.Fatalf("v1:%v\n", "subscribe invalid protocol level, should not happen")
	}
	//
	r, e := c.Subscribe(h)
	if e != nil {
		ll.Fatalf("subscribe failed err:[%v]\n", e)
	}
	return r
}
コード例 #4
0
ファイル: sendrcv.go プロジェクト: ra/go-samp
func recMessages(c *stompngo.Connection, q string, k int) {

	var error error
	ks := fmt.Sprintf("%d", k)

	// Receive phase
	headers := stompngo.Headers{"destination", q}
	sh := headers.Add("id", q)
	//
	log.Println("start subscribe", q)
	sc, error := c.Subscribe(sh)
	log.Println("end subscribe", q)
	if error != nil {
		log.Fatal(error)
	}
	for input := range sc {
		inmsg := input.Message.BodyString()
		if printMsgs {
			log.Println("Receive:", q, " / ", inmsg)
		}
		if inmsg == "***EOF***" {
			break
		}
		if !strings.HasPrefix(inmsg, ks) {
			log.Printf("bad prefix: [%v], [%v], [%v]\n", q, inmsg, ks)
			log.Fatal("bad prefix ....")
		}
		//
		d := time.Duration(getStagger(1e9/10, 1e9/5))
		time.Sleep(d)
	}
	log.Println("quit for", q)
	error = c.Unsubscribe(headers)
	log.Println("end unsubscribe", q)
	if error != nil {
		log.Fatal(error)
	}
	wgrecv.Done()
}
コード例 #5
0
// Handle a subscribe for the different protocol levels.
func HandleSubscribe(c *stompngo.Connection, d, i, a string) <-chan stompngo.MessageData {
	h := stompngo.Headers{"destination", d, "ack", a}
	//
	switch c.Protocol() {
	case stompngo.SPL_12:
		// Add required id header
		h = h.Add("id", i)
	case stompngo.SPL_11:
		// Add required id header
		h = h.Add("id", i)
	case stompngo.SPL_10:
		// Nothing else to do here
	default:
		llu.Fatalf("v1:%v v2:%v\n", "subscribe invalid protocol level, should not happen")
	}
	//
	r, e := c.Subscribe(h)
	if e != nil {
		llu.Fatalf("v1:%v v2:%v\n", "subscribe failed", e)
	}
	return r
}
コード例 #6
0
ファイル: receivernid.go プロジェクト: ra/go-samp
func recMessages(c *stompngo.Connection, q string) {

	var error error

	fmt.Printf("Start for q: %s\n", q)

	// Receive phase
	headers := stompngo.Headers{"destination", q} // no ID here.  1.1 library should provide
	fmt.Printf("qhdrs: %v\n", headers)
	sc, error := c.Subscribe(headers)
	if error != nil {
		// Handle error properly
		fmt.Printf("sub error: %v\n", error)
	}
	first := true
	firstSub := ""
	for input := range sc {
		inmsg := string(input.Message.Body)
		if printHdrs {
			fmt.Println("queue:", q, "Next Receive: ", input.Message.Headers)
		}
		if printMsgs {
			fmt.Println("queue:", q, "Next Receive: ", inmsg)
		}

		firstSub = input.Message.Headers.Value("subscription")
		if first {
			if firstSub == "" {
				panic("first subscription header is empty")
			}
			fmt.Println("queue:", q, "FirstSub: ", firstSub)
			first = false
		} else {
			if firstSub != input.Message.Headers.Value("subscription") {
				panic(firstSub + " / " + input.Message.Headers.Value("subscription"))
			}
		}
		time.Sleep(1e9 / 100) // Crudely simulate message processing
		incrCtl.Lock()
		numRecv++
		incrCtl.Unlock()
		if strings.HasPrefix(inmsg, "***EOF***") {
			fmt.Println("queue:", q, "FirstSub:", firstSub, "goteof")
			break
		}
		if !strings.HasPrefix(inmsg, q) {
			fmt.Printf("bad prefix: %v, %v\n", q, inmsg)
			panic("bad prefix ....")
		}
		// Poll for adhoc errors
		select {
		case v := <-c.MessageData:
			fmt.Printf("frameError: %v\n", v.Message)
			fmt.Printf("frameError: [%v] [%v]\n", q, firstSub)
		default:
			fmt.Println("Nothing to show")
		}
	}
	uh := stompngo.Headers{"id", firstSub,
		"destination", q}
	error = c.Unsubscribe(uh)
	if error != nil {
		log.Fatalf("unsub error: %v\n", error)
	}
	wg.Done()
}