Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azservicebus] Final API changes for beta.3 #16110

Merged
merged 27 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
11fb208
- Use the new Prefetched() API in go-amqp's receiver, which ensures …
richardpark-msft Nov 7, 2021
f226bb7
Removing function that's not quite ready for prime time.
richardpark-msft Nov 7, 2021
0d71b5a
Cleaning up the message a little. It'll become more prescriptive once…
richardpark-msft Nov 7, 2021
ab0edde
Updating example to be simpler - really the important stuff is that t…
richardpark-msft Nov 7, 2021
8c35ba0
Updating migration guide to be accurate against the API surface, upda…
richardpark-msft Nov 7, 2021
c6fce94
moving admin client into a sub-package
richardpark-msft Nov 7, 2021
81cbf4b
- AdminClient moved into it's own sub-package.
richardpark-msft Nov 7, 2021
2b23de8
Move stress into the internal package
richardpark-msft Nov 7, 2021
9edc8ee
Fixing some linting failures, updating the package level comment for …
richardpark-msft Nov 7, 2021
2ca93bc
Adding in getting namespace properties to the admin.Client
richardpark-msft Nov 8, 2021
edc56f1
Used the wrong format for the forwarding entity
richardpark-msft Nov 8, 2021
b4e4392
Update copyright header
richardpark-msft Nov 8, 2021
aaa3517
This is going to be a beta release, so we'll bump the minor revision.
Nov 8, 2021
c5d0d01
Updating tests and options name
Nov 8, 2021
7fe92cc
- propertiesToModify is already a nullable value, no need to make it …
Nov 9, 2021
1af6e79
Troubleshooting flaky test
Nov 9, 2021
fe1e854
Unintended URL inconsistency
Nov 9, 2021
8bc310c
Fixing note to mention 'azservicebus.Client'
Nov 9, 2021
f3bc0f9
Changing 'an Client' to 'a Client'
Nov 9, 2021
02a1e90
NamespaceProperties.RawResult => NamespaceProperties.RawResponse
Nov 9, 2021
5e6f237
Remove unneeded .Sequence comment
Nov 9, 2021
798aecf
Alter our counting to always use maxPageSize as the increment.
Nov 10, 2021
1a33990
Fixing tests
Nov 10, 2021
af06fed
Adding some comments and explanation for a bit that Charles mentioned…
Nov 10, 2021
5ab8104
Remove dead comment about AMQPAnnotatedMessage
Nov 10, 2021
a981633
Updating changelog with a note that we've moved the admin client
Nov 10, 2021
52e7a04
Updating all pagers to match the logic in the .NET client, where if a…
Nov 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sdk/messaging/azservicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# Release History

## 0.2.1 (Unreleased)
## 0.3.0 (Unreleased)

### Features Added

- AbandonMessage and DeferMessage now take an additional `PropertiesToModify` option, allowing
the message properties to be modified when they are settled.

### Breaking Changes

- ReceivedMessage.Body is now a function that returns a ([]byte, error), rather than being a field.
This protects against a potential data-loss scenario where a message is received with a payload
encoded in the sequence or value sections of an AMQP message, which cannot be prpoerly represented
in the .Body. This will now return an error.
- Functions that have options or might have options in the future have an additional *options parameter.
As usual, passing 'nil' ignores the options, and will cause the function to use defaults.
- MessageBatch.Add() has been renamed to MessageBatch.AddMessage(). AddMessage() now returns only an `error`,
with a sentinel error (ErrMessageTooLarge) signaling that the batch cannot fit a new message.
- Sender.SendMessages() has been removed in favor of simplifications made in MessageBatch.

### Bugs Fixed


### Other Changes

## 0.2.0 (2021-11-02)
Expand Down
36 changes: 15 additions & 21 deletions sdk/messaging/azservicebus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
client, err := azservicebus.NewClientFromConnectionString("<Service Bus connection string>")

if err != nil {
log.Fatalf("Failed to create Service Bus Client: %s", err.Error())
panic(err)
}
}
```
Expand All @@ -66,13 +66,13 @@ func main() {
cred, err := azidentity.NewDefaultAzureCredential(nil)

if err != nil {
log.Fatalf("Failed creating DefaultAzureCredential: %s", err.Error())
panic(err)
}

client, err := azservicebus.NewClient("<ex: my-service-bus.servicebus.windows.net>", cred)

if err != nil {
log.Fatalf("Failed to create Service Bus Client: %s", err.Error())
panic(err)
}
}
```
Expand Down Expand Up @@ -112,7 +112,7 @@ NOTE: Creating a `client` is covered in the ["Authenticate the client"](#authent
sender, err := client.NewSender("<queue or topic>")

if err != nil {
log.Fatalf("Failed to create Sender: %s", err.Error())
panic(err)
}

// send a single message
Expand All @@ -129,29 +129,23 @@ You can also send messages in batches, which can be more efficient than sending
messageBatch, err := sender.NewMessageBatch(context.TODO())

if err != nil {
log.Fatalf("Failed to create a message batch: %s", err.Error())
panic(err)
}

// Add a message using TryAdd.
// This can be called multiple times, and will return (false, nil)
// if the message cannot be added because the batch is full.
added, err := messageBatch.TryAdd(&azservicebus.Message{
// Add a message to our message batch. This can be called multiple times.
err := messageBatch.Add(&azservicebus.Message{
Body: []byte(fmt.Sprintf("hello world")),
})

if err != nil {
log.Fatalf("Failed to add message to batch because of an error: %s", err.Error())
}
if err == azservicebus.ErrMessageTooLarge {
fmt.Printf("Message batch is full. We should send it and create a new one.\n")

if !added {
log.Printf("Message batch is full. We should send it and create a new one.")
// send what we have since the batch is full
err := sender.SendMessageBatch(context.TODO(), messageBatch)

if err != nil {
log.Fatalf("Failed to send message batch: %s", err.Error())
}

// add the next message to a new batch and start again.

// Create a new batch, add this message and start again.
} else if err != nil {
panic(err)
}
```

Expand All @@ -172,7 +166,7 @@ receiver, err := client.NewReceiverForQueue(
// client.NewReceiverForSubscription("<topic>", "<subscription>")

if err != nil {
log.Fatalf("Failed to create the receiver: %s", err.Error())
panic(err)
}

// Receive a fixed set of messages. Note that the number of messages
Expand Down
92 changes: 92 additions & 0 deletions sdk/messaging/azservicebus/admin/admin_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package admin

import (
"context"
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/internal"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/internal/atom"
)

// Client allows you to administer resources in a Service Bus Namespace.
// For example, you can create queues, enabling capabilities like partitioning, duplicate detection, etc..
// NOTE: For sending and receiving messages you'll need to use the `Client` type instead.
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
type Client struct {
em atom.EntityManager
}

type ClientOptions struct {
// for future expansion
}

// NewClientFromConnectionString creates an Client authenticating using a connection string.
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error) {
em, err := atom.NewEntityManagerWithConnectionString(connectionString, internal.Version)

if err != nil {
return nil, err
}

return &Client{em: em}, nil
}

// NewClient creates an Client authenticating using a TokenCredential.
func NewClient(fullyQualifiedNamespace string, tokenCredential azcore.TokenCredential, options *ClientOptions) (*Client, error) {
em, err := atom.NewEntityManager(fullyQualifiedNamespace, tokenCredential, internal.Version)

if err != nil {
return nil, err
}

return &Client{em: em}, nil
}

type NamespaceProperties struct {
CreatedTime time.Time
ModifiedTime time.Time

SKU string
MessagingUnits *int64
Name string
}

type GetNamespacePropertiesResult struct {
NamespaceProperties
}

type GetNamespacePropertiesResponse struct {
GetNamespacePropertiesResult
RawResult *http.Response
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
}

type GetNamespacePropertiesOptions struct {
// For future expansion
}

// GetNamespaceProperties gets the properties for the namespace, includings properties like SKU and CreatedTime.
func (ac *Client) GetNamespaceProperties(ctx context.Context, options *GetNamespacePropertiesOptions) (*GetNamespacePropertiesResponse, error) {
var body *atom.NamespaceEntry
resp, err := ac.em.Get(ctx, "/$namespaceinfo", &body)

if err != nil {
return nil, err
}

return &GetNamespacePropertiesResponse{
RawResult: resp,
GetNamespacePropertiesResult: GetNamespacePropertiesResult{
NamespaceProperties: NamespaceProperties{
Name: body.NamespaceInfo.Name,
CreatedTime: body.NamespaceInfo.CreatedTime,
ModifiedTime: body.NamespaceInfo.ModifiedTime,
SKU: body.NamespaceInfo.MessagingSKU,
MessagingUnits: body.NamespaceInfo.MessagingUnits,
},
},
}, nil
}
18 changes: 18 additions & 0 deletions sdk/messaging/azservicebus/admin/admin_client_models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package admin

// EntityStatus represents the current status of the entity.
type EntityStatus string

const (
// EntityStatusActive indicates an entity can be used for sending and receiving.
EntityStatusActive EntityStatus = "Active"
// EntityStatusDisabled indicates an entity cannot be used for sending or receiving.
EntityStatusDisabled EntityStatus = "Disabled"
// EntityStatusSendDisabled indicates that an entity cannot be used for sending.
EntityStatusSendDisabled EntityStatus = "SendDisabled"
// EntityStatusReceiveDisabled indicates that an entity cannot be used for receiving.
EntityStatusReceiveDisabled EntityStatus = "ReceiveDisabled"
)
Loading