diff --git a/changelog.md b/changelog.md index 3cb39fb..877afaf 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ ## `head` +## `v0.5.0` +- add support for websockets + ## `v0.4.1` - fix issue with sender when SB returns a different receiver disposition [#119](https://github.com/Azure/azure-service-bus-go/issues/119) diff --git a/namespace.go b/namespace.go index ae61db7..29c8d8e 100644 --- a/namespace.go +++ b/namespace.go @@ -47,7 +47,7 @@ const ( //` // Version is the semantic version number - Version = "0.4.1" + Version = "0.5.0" rootUserAgent = "/golang-service-bus" ) diff --git a/namespace_websocket_example_test.go b/namespace_websocket_example_test.go new file mode 100644 index 0000000..de47ebf --- /dev/null +++ b/namespace_websocket_example_test.go @@ -0,0 +1,59 @@ +package servicebus_test + +import ( + "context" + "fmt" + "os" + "time" + + servicebus "github.com/Azure/azure-service-bus-go" +) + +func ExampleNamespaceWithWebSocket() { + const queueName = "wssQueue" + + connStr := os.Getenv("SERVICEBUS_CONNECTION_STRING") + if connStr == "" { + fmt.Println("FATAL: expected environment variable SERVICEBUS_CONNECTION_STRING not set") + return + } + + // Create a Service Bus Namespace using a connection string over wss:// on port 443 + ns, err := servicebus.NewNamespace( + servicebus.NamespaceWithConnectionString(connStr), + servicebus.NamespaceWithWebSocket(), + ) + if err != nil { + fmt.Println(err) + return + } + + // Create a context to limit how long we will try to send, then push the message over the wire. + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + qm := ns.NewQueueManager() + if _, err := ensureQueue(ctx, qm, queueName); err != nil { + fmt.Println(err) + return + } + + client, err := ns.NewQueue(queueName) + if err != nil { + fmt.Println(err) + return + } + + // Send a message to the queue + if err := client.Send(ctx, servicebus.NewMessageFromString("Hello World!!!")); err != nil { + fmt.Println(err) + } + + // Receive the message from the queue + if err := client.ReceiveOne(ctx, MessagePrinter{}); err != nil { + fmt.Println(err) + } + + // Output: Hello World!!! +} +