azure-event-hubs-go icon indicating copy to clipboard operation
azure-event-hubs-go copied to clipboard

Unable to listen to the event hub in hello world example .

Open pikvik opened this issue 6 years ago • 5 comments

Expected Behavior

I am listening response to be received on pinging Event hub . Response should be : I m Listening

Actual Behavior

azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to https://management.azure.com/subscriptions/******/resourceGroups//providers/Microsoft.EventHub/namespaces//eventhubs/?api-version=2017-04-01: StatusCode=0 -- Original Error: adal:Failed to execute the refresh request. Error = 'Get http:///metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F: dial tcp 169.254.169.254:80: i/o timeout' exit status 1

Environment

  • OS: Mac OsX
  • Go version: go1.12.4 darwin/amd64
  • Version of Library:

pikvik avatar May 16 '19 08:05 pikvik

This appears to be error when trying to dial the Managed Identity provider on Azure virtual machine. Are you running this on an Azure VM with Managed Identity enabled? For more information on Managed Identities: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview.

Also, can you provide the code used to construct your Event Hub client?

devigned avatar May 21 '19 16:05 devigned

We are not trying on VM we are running on local and providing all the credentials and connection string as well . And I am just simply running the example script provided .

pikvik avatar May 24 '19 09:05 pikvik

I'm not clear why the thumbs down?

The error you are providing is from the Azure Active Directory token provider when it tries to probe for managed identities. It does this as the last resort when it doesn't find Service Principal Credentials AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET env variables. Be aware, you will have to have RBAC rights to interact with the Event Hub entity.

provider, aadErr := aad.NewJWTProvider(aad.JWTProviderWithEnvironmentVars())
NewHub(namespace, hubName, provider, opts...)

If you are using a connection string, then you would be using a Signed Access Signature (SAS) token provider. Below is an example of using a Service Bus connection string. You can find many examples of this in the go docs (like: https://godoc.org/github.com/Azure/azure-event-hubs-go#example-Hub--HelloWorld). Also see the go docs for the SAS token provider.

connStr := os.Getenv("EVENTHUB_CONNECTION_STRING")
if connStr == "" {
    fmt.Println("FATAL: expected environment variable EVENTHUB_CONNECTION_STRING not set")
    return
}

// within this construction helper, a connection string is used to build a sas.TokenProviderWithKey
hub, err := eventhub.NewHubFromConnectionString(connStr + ";EntityPath=MyHub")
if err != nil {
    fmt.Println(err)
    return
}

My guess, without seeing your code, is that you are using: https://godoc.org/github.com/Azure/azure-event-hubs-go#NewHubFromEnvironment. If so, I would verify environment variables described in the documentation are properly set.

If you are still having issues getting this running after evaluating this guidance, please provide a code example replicating the issue.

devigned avatar May 24 '19 17:05 devigned

We are not pulling from .env file but hard coding . Everywhere we have hard coded . credential.go :

func AADSASCredentialWithEnvironmentVars() AADSASCredentialOption { return func(config aad.TokenProviderConfiguration) error { config.TenantID = " ******************************* " config.ClientID = " ******************************* " config.ClientSecret = "**************************" // config.CertificatePath = os.Getenv("AZURE_CERTIFICATE_PATH") // config.CertificatePassword = os.Getenv("AZURE_CERTIFICATE_PASSWORD") .

func ExampleHub_helloWorld() { ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second) defer cancel()

connStr := "Endpoint=sb://xyz-dev-eventhub.servicebus.windows.net/;SharedAccessKeyName=owner;SharedAccessKey=****************************=;EntityPath=xyz-device-remoteaccess"
if connStr == "" {
	fmt.Println("FATAL: expected environment variable EVENTHUB_CONNECTION_STRING not set")
	return

pikvik avatar May 27 '19 09:05 pikvik

If you have a connection string, just use:

connStr := "Endpoint=sb://xyz-dev-eventhub.servicebus.windows.net/;SharedAccessKeyName=owner;SharedAccessKey=****************************=;EntityPath=xyz-device-remoteaccess"
hub, err := eventhub.NewHubFromConnectionString(connStr)
if err != nil {
	fmt.Println(err)
	return
}

I don't understand why you are using both Azure Active Directory (AAD) auth and a connection string at the same time. They are two separate, but equal, ways of authenticating.

devigned avatar May 30 '19 22:05 devigned