Azure.Messaging.EventHubs: The connection string used for an Event Hub client must specify the Event Hubs namespace host, and either a Shared Access Key (both the name and value) or Shared Access Signature to be valid.

Sharma, Yashaswi 1 Reputation point
2022-07-26T08:31:59.423+00:00

Please suggest What i am doing wrong in this ?
I am getting below error:-
Azure.Messaging.EventHubs: The connection string used for an Event Hub client must specify the Event Hubs namespace host, and either a Shared Access Key (both the name and value) or Shared Access Signature to be valid. The path to an Event Hub must be included in the connection string or specified separately. (Parameter 'connectionString').
Value cannot be null. (Parameter 'provider')
Failed to run function CLI command from staging folder(azure-functions7552209040795671955)

java function:-

@FunctionName("CustomEventTrigger")
public void run(
@EventHubTrigger(name = "message", eventHubName = "custom001",
connection = "AzureWebJobsStorage",
consumerGroup = "$Default",
cardinality = Cardinality.MANY) String message,
final ExecutionContext context
) {
context.getLogger().info("Java Event Hub trigger function executed.");
context.getLogger().info("Length:" + message);
// message.forEach(singleMessage -> context.getLogger().info(singleMessage));
}
}

local.settings.json

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};EntityPath={entityPath}",
"FUNCTIONS_WORKER_RUNTIME": "Java",
"JAVA_HOME": "C:\Program Files\Java\jdk1.8.0_331",
"EventHubConnectionString":"Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};EntityPath={entityPath}",
"eventHubName" : "custom001",
"cardinality" : "MANY"
},
"ConnectionStrings": {
"EventHubConnectionString":"Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};EntityPath={entityPath}"
}
}

host.json

{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
637 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Bruno Lucas 4,431 Reputation points MVP
    2022-07-26T11:01:46.177+00:00

    Hi @Sharma, Yashaswi

    Look like you are passing the storage connection string instead of the hub connection string

    Here you need to add the real hub connection string:

    "EventHubConnectionString":"Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};EntityPath={entityPath}",]

    the azure hub (not the hub namespace) can be found here:

    224778-image.png

    https://video2.skills-academy.com/en-us/azure/event-hubs/event-hubs-get-connection-string

    under #1, replace "AzureWebJobsStorage" with "EventHubConnectionString"

    you may need to remove the last bit of the connection string (EntityPath={entityPath}

    The value for that will be in #2

    224866-image.png

    It should look like:

    @EventHubTrigger(name = "message", eventHubName = "custom001",  
                  connection = "EventHubConnectionString",  
    

    try running with that. make sure "EventHubConnectionString" has the real connection string values.

    I use C# and the latest libraries now expect the connection string to don't include the entity path

    case you get some error asking to remove the entity path from connection string, change this:

    "EventHubConnectionString":"Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};EntityPath={entityPath}"

    to this:

    "EventHubConnectionString":"Endpoint={endpoint};SharedAccessKeyName={keyName};SharedAccessKey={accessKey};"

    and make sure the value for EntityPath={entityPath} (that is the hub name) is added to the "eventhubname" parameter

    To run/test in Visual Studio, add the real connection strings to your local.settings.json:

    225107-image.png

    to run in the cloud, you can manually add. if you add to local.settings.json and deploy with Visual studio, most of the time it will create that for you:

    225078-image.png

    Please don't forget to click on "Accept Answer" or the vote button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer.

    1 person found this answer helpful.

  2. Bruno Lucas 4,431 Reputation points MVP
    2022-07-27T08:37:23.507+00:00

    Hi @Sharma, Yashaswi

    I also noticed you have duplicated the "EventHubConnectionString"

    225231-image.png

    It must be only one like this:

    225149-image.png

    Please don't forget to click on "Accept Answer" or the vote button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer.


  3. Bharsakale, Aniket (he/him) 0 Reputation points
    2023-11-25T22:42:32.17+00:00

    I'm kind of lost after reading sufficient documentation on azure functions, bindings, eventhub triggers, eventhubs etc. & the development related to it.

    Specifically when working with "System assigned" managed identity where we do not want to store a EventHub's connection string in our code/configuration & that's where I get the below error:

    Azure.Messaging.EventHubs: The connection string could not be parsed; either it was malformed or contains no well-known tokens

    Context: I have an Azure subscription(az-nonprd-sub) which I used to create a resource group(nonprd-rg), in which I've created an Azure Function app(NodeJS v18 - WindowsOS, CentralUS region) which in turn contains a EventHub trigger. Task is pretty simple, my EventTrigger must be invoked whenever a eventhub receives a JSON/Text message. the EventHub is owned by a different team to which I do not have any control. But I do have it's namespace name & the eventhubname which I'm told I can use to connect to it. I've seen many YT clips & blogs using the connection string which is simple & unsecure. Im told to use the managed identity pathway which improves security & neither am I using the Azure Key Value way.

    Now,

    Since we are working our way through the "Managed Identity" pathway - In my configuration app settings, I've added the fully qualified name of their namespace which contains the EventHub. Following is the app settings stored my function app's - Configuration tab's Application settings:

    Ex1: "connection" : "DemoEventHubNameSpace.servicebus.windows.net"

    Ex2: "eventhub-name" : "json-summary-eventhub"

    Earlier, I enabled the System assigned identity for my Azure Function app & shared this ID with the EventHub team, they told me they provided the READ access to my function app via this managed identity which enables my FunctionApp to consume their eventhub data. So there's no connection string or a key vault reference involved!!

    I have a function.json which contains the trigger bindings & a index.js which contains the payload/function thats required to be executed once the eventhub receives an event/message.

    How do I resolve the above error for "connection"

    index.js

    module.exports = function (context, eventHubMessage) {
        context.log(` ********* SummaryEventHubTrigger INVOKED!!! ********* `);     
        context.log(' ********* Function triggered to process a message = ', eventHubMessage);
        
        context.log(' ********* EnqueuedTimeUtc = ', context.bindingData.enqueuedTimeUtc);
        context.log(' ********* SequenceNumber = ', context.bindingData.sequenceNumber);
        context.log(' ********* Offset = ', context.bindingData.offset);      
    };
    

    function.json

    {
      "bindings": [
        {
          "type": "eventHubTrigger",
          "name": "eventHubMessage",
          "direction": "in",
          "eventHubName": "%eventhub-name%",
          "connection": "%connection%",
          "cardinality": "one",
          "consumerGroup": "customConsumerGroup",
          "dataType": "string"
        }
      ]
    }
    

    Note: since I have a contributor role. Also I have not assigned any Azure assignment to anything so far.
    Also, I'm not able run my function via Azure portal & from VS Code I tried but I cannot import my function created via portal into VS code. Following just gives me 500 internal error & no logs are populated in monitor section/app insights.User's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.