Exemple #1
0
// Example of creating subscriptions with various options.
func ExampleConn_Subscribe_2(c *stomp.Conn) error {
	// Subscribe to queue with automatic acknowledgement
	sub1, err := c.Subscribe("/queue/test-1", stomp.AckAuto)
	if err != nil {
		return err
	}

	// Subscribe to queue with client acknowledgement and a custom header value
	sub2, err := c.Subscribe("/queue/test-2", stomp.AckClient,
		stomp.SubscribeOpt.Header("x-custom-header", "some-value"))
	if err != nil {
		return err
	}

	doSomethingWith(sub1, sub2)

	return nil
}
Exemple #2
0
func Producer(c, quit chan string, conn *stomp.Conn) {
	for {
		select {
		case c <- "msg sent":
			err := conn.Send(
				"/queue/test-1",           // destination
				"text/plain",              // content-type
				[]byte("Test message #1")) // body
			if err != nil {
				fmt.Println(err)
				return
			}
		case <-quit:
			fmt.Println("finish")
			return
		}
	}
}
Exemple #3
0
func ExampleConn_Send(c *stomp.Conn) error {
	// send with receipt and an optional header
	err := c.Send(
		"/queue/test-1",            // destination
		"text/plain",               // content-type
		[]byte("Message number 1"), // body
		stomp.SendOpt.Receipt,
		stomp.SendOpt.Header("expires", "2049-12-31 23:59:59"))
	if err != nil {
		return err
	}

	// send with no receipt and no optional headers
	err = c.Send("/queue/test-2", "application/xml",
		[]byte("<message>hello</message>"))
	if err != nil {
		return err
	}

	return nil
}