Skip to content

Commit

Permalink
Merge pull request #60 from Azure/mgmt-opts
Browse files Browse the repository at this point in the history
move to mgmt options
  • Loading branch information
devigned committed Sep 4, 2018
2 parents ddcba0c + e6fdb91 commit ae13e76
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
38 changes: 13 additions & 25 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[[constraint]]
name = "github.com/Azure/azure-amqp-common-go"
version = "0.7"
version = "1.0.1"

[[constraint]]
name = "github.com/Azure/azure-storage-blob-go"
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Change Log

## `head`

## `v1.0.0`
- change from OpenTracing to OpenCensus
- add more documentation for EPH
- variadic mgmt options

## `v0.4.0`
- add partition key to received event [#43](https://github.com/Azure/azure-event-hubs-go/pull/43)
Expand Down
35 changes: 31 additions & 4 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
rootUserAgent = "/golang-event-hubs"

// Version is the semantic version number
Version = "0.4.0"
Version = "1.0.0"
)

type (
Expand Down Expand Up @@ -88,7 +88,8 @@ type (
GetPartitionInformation(context.Context, string) (HubPartitionRuntimeInformation, error)
}

// HubOption provides structure for configuring new Event Hub instances
// HubOption provides structure for configuring new Event Hub clients. For building new Event Hubs, see
// HubManagementOption.
HubOption func(h *Hub) error

// HubManager provides CRUD functionality for Event Hubs
Expand Down Expand Up @@ -134,6 +135,9 @@ type (
EntityAvailabilityStatus *string `xml:"EntityAvailabilityStatus,omitempty"`
BaseEntityDescription
}

// HubManagementOption provides structure for configuring new Event Hubs
HubManagementOption func(description *HubDescription) error
)

// NewHubManagerFromConnectionString builds a HubManager from an Event Hub connection string
Expand Down Expand Up @@ -171,11 +175,34 @@ func (hm *HubManager) Delete(ctx context.Context, name string) error {
return err
}

// HubWithMessageRetentionInDays configures an Event Hub to retain messages for that number of days
func HubWithMessageRetentionInDays(days int32) HubManagementOption {
return func(hd *HubDescription) error {
hd.MessageRetentionInDays = &days
return nil
}
}

// HubWithPartitionCount configures an Event Hub to have the specified number of partitions. More partitions == more throughput
func HubWithPartitionCount(count int32) HubManagementOption {
return func(hd *HubDescription) error {
hd.PartitionCount = &count
return nil
}
}

// Put creates or updates an Event Hubs Hub
func (hm *HubManager) Put(ctx context.Context, name string, hd HubDescription) (*HubEntity, error) {
func (hm *HubManager) Put(ctx context.Context, name string, opts ...HubManagementOption) (*HubEntity, error) {
span, ctx := hm.startSpanFromContext(ctx, "eh.HubManager.Put")
defer span.End()

hd := new(HubDescription)
for _, opt := range opts {
if err := opt(hd); err != nil {
return nil, err
}
}

hd.ServiceBusSchema = to.StringPtr(serviceBusSchema)

he := &hubEntry{
Expand All @@ -184,7 +211,7 @@ func (hm *HubManager) Put(ctx context.Context, name string, hd HubDescription) (
},
Content: &hubContent{
Type: applicationXML,
HubDescription: hd,
HubDescription: *hd,
},
}

Expand Down
4 changes: 2 additions & 2 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (suite *eventHubSuite) TestHubManagementWrites() {
}

func testPutHub(ctx context.Context, t *testing.T, hm *HubManager, name string) {
hd, err := hm.Put(ctx, name, HubDescription{})
hd, err := hm.Put(ctx, name)
require.NoError(t, err)
require.NotNil(t, hd.PartitionCount)
assert.Equal(t, int32(4), *hd.PartitionCount)
Expand All @@ -186,7 +186,7 @@ func (suite *eventHubSuite) TestHubManagementReads() {

names := []string{suite.randEntityName(), suite.randEntityName()}
for _, name := range names {
if _, err := hm.Put(ctx, name, HubDescription{}); err != nil {
if _, err := hm.Put(ctx, name); err != nil {
suite.Require().NoError(err)
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (suite *BaseSuite) RandomHub(opts ...HubMgmtOption) (*mgmt.Model, func()) {
name := suite.RandomName("goehtest", 6)
model, err := suite.ensureEventHub(ctx, name, opts...)
suite.Require().NoError(err)
suite.Require().NotNil(model)
suite.Require().NotNil(model.PartitionIds)
suite.Require().Len(*model.PartitionIds, 4)
return model, func() {
Expand Down

0 comments on commit ae13e76

Please sign in to comment.