move to mgmt options
This commit is contained in:
Родитель
ddcba0cfa9
Коммит
6b8068f8b3
33
hub.go
33
hub.go
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -184,7 +211,7 @@ func (hm *HubManager) Put(ctx context.Context, name string, hd HubDescription) (
|
|||
},
|
||||
Content: &hubContent{
|
||||
Type: applicationXML,
|
||||
HubDescription: hd,
|
||||
HubDescription: *hd,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче