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

Event Grid subscription on blob storage with event hub #247

Open
3 tasks
douglaswaights opened this issue Mar 12, 2019 · 2 comments
Open
3 tasks

Event Grid subscription on blob storage with event hub #247

douglaswaights opened this issue Mar 12, 2019 · 2 comments

Comments

@douglaswaights
Copy link

  • bug report
  • [x ] request for new sample
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Hi,

Is there a sample anywhere that shows how to create an event grid subscription on a blob storage account? I would like to then make the end point topic an event hub.

There are samples for event hubs but its complicated to wire up the event subscription on a blob storage account and i just keep getting 400 bad request errors.

Thanks
Doug

@douglaswaights
Copy link
Author

Just to add some further information this is the code i'm using below.

The error i'm getting is an invalid arm id.

I'm confused as the storage account exists (first arm id) and i've also manually created the event hub namespace and hub (2nd arm id is the namespace id)... so both exist...

func getEventSubscriptionsClient() eventgrid.EventSubscriptionsClient {
	eventgridClient := eventgrid.NewEventSubscriptionsClient(subscriptionID)
	eventgridClient.Authorizer, _ = getAuthorizer()
	eventgridClient.AddToUserAgent(userAgent)
	return eventgridClient
}

func createEventSubscription(ctx context.Context) (eventgrid.EventSubscription, error) {
	client := getEventSubscriptionsClient()
	future, err := client.CreateOrUpdate(ctx, "/subscriptions/redacted/resourceGroups/rubbish1/providers/Microsoft.Storage/storageAccounts/abcdefnort", "mysubscription",
		eventgrid.EventSubscription{
			EventSubscriptionProperties: &eventgrid.EventSubscriptionProperties{
				Destination: &eventgrid.EventHubEventSubscriptionDestination{
					EndpointType: eventgrid.EndpointTypeEventHub,
					EventHubEventSubscriptionDestinationProperties: &eventgrid.EventHubEventSubscriptionDestinationProperties{
						ResourceID: to.StringPtr("/subscriptions/redacted/resourceGroups/rubbish1/providers/Microsoft.EventHub/namespaces/douglas"),
					},
				},
			},
		},
	)
	if err != nil {
		//return s, fmt.Errorf(fmt.Sprintf(errorPrefix, err))
	}
	err = future.WaitForCompletionRef(ctx, client.Client)
	if err != nil {
		//return s, fmt.Errorf(fmt.Sprintf(errorPrefix, fmt.Sprintf("cannot get the storage account create future response: %v", err)))
	}
	return future.Result(client)
}

@douglaswaights
Copy link
Author

This is solved. I was using the resource id of the event hub namespace rather than the resource id of the hub itself.

Feel free to close the issue . I still think a sample would be beneficial so i'll leave the issue open for now.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant