W/o Durability
package main import "github.com/jjeffery/stomp" func main() { conn, _ := stomp.Dial("tcp", "localhost:61613", &stomp.Options {}) sub, _ := conn.Subscribe("/topic/SampleTopic", stomp.AckAuto) msg := <- sub.C println(string(msg.Body)) conn.Disconnect() }
W/ Durability
package main import ( "fmt" "github.com/jjeffery/stomp" ) func main() { conn, _ := stomp.Dial("tcp", "localhost:61613", &stomp.Options { NonStandard: stomp.NewHeader("client-id", "SampleClient") }) sub, _ := conn.SubscribeWithHeaders("/topic/SampleTopic", stomp.AckAuto, stomp.NewHeader("activemq.subscriptionName", "SampleSubscription")) msg := <- sub.C fmt.Printf("%v\n", msg.Body) conn.Disconnect() }
I can’t use your code because everytime gives me this error
cannot use stomp.Options literal (type *stomp.Options) as type stomp.Options in argument to stomp.Dial
You may want to report the issue to the client library project instead, please.
In case anyone else runs into this issue, the signature for the Dial is:
func Dial(network, addr string, opts Options)
So it’s not a pointer. Remove the “&” from “stomp.Options” i.e.
conn, _ := stomp.Dial(“tcp”, “localhost:61613”, stomp.Options{})
Thanks for the correction. I am guessing it is a difference from the time I wrote the post. I haven’t updated it in a long time.