Demonstrate how API can be used with Stan.
@@ -5,6 +5,7 @@ import (
"time"
"github.com/nats-io/nats.go"
+ "github.com/nats-io/stan.go"
newrelic "github.com/newrelic/go-agent"
)
@@ -38,3 +39,18 @@ func ExampleStartPublishSegment_defer() {
}
fmt.Println("Received reply message:", string(m.Data))
}
+
+var clusterID, clientID string
+
+// StartPublishSegment can be used with a NATS Streamming Connection as well
+// (https://github.com/nats-io/stan.go). Use the `NatsConn()` method on the
+// `stan.Conn` interface (https://godoc.org/github.com/nats-io/stan#Conn) to
+// access the `nats.Conn` object.
+func ExampleStartPublishSegment_stan() {
+ sc, _ := stan.Connect(clusterID, clientID)
+ txn := currentTransaction()
+ subject := "testing.subject"
+
+ defer StartPublishSegment(txn, sc.NatsConn(), subject).End()
+ sc.Publish(subject, []byte("Hello World"))
+}
