Service Bus Connection String in Azure function is rejected - azure

Im working through this guide using Azure Functions to commit IoTHub messages to Azure storage. I'm at section 5d, where I need to create a new Service Bus Connection string for my function, but whatever I use, including the format in the guide:
Endpoint=<Event Hub-compatible endpoint>;SharedAccessKeyName=iothubowner;SharedAccessKey=<Primary key>
I get the error:
Not a valid service bus connection string.
I’ve tried using the Event Hub-compatible endpoint from my IoT hub endpoints and also the connection string –- primary key from the access policy for iothubowner but again it rejects it.
I then created a new service bus and used that connection (see my answer below and initial optimism!) but when I tried to edit the function I get a 404 toast notification:
Function ($DeviceDataToStorage) Error: The listener for function
'Functions.DeviceDataToStorage' was unable to start.
Microsoft.ServiceBus: The messaging entity 'Management operation
failed. status-code: 404, status-description: The messaging entity
'sb://{MY SERVICE BUS CONNECTION STRING WHICH WAS
ACCEPTED}/{EVENTHUBNAME}' could not be found..' could not be found.
Can anyone who has used Azure functions before advise what format this needs to be in or more importantly where exactly in the portal I can get this from?

Thought I figured it out, but I hadn't.
Here's what I thought worked, but it didn't
*
Its missing from the tutorial, but you need to manually create a new
service bus endpoint (see
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues)
and copy the CONNECTIONSTRING-PRIMARYKEY from the
RootManageSharedAccessKey policy of Shared Access Policies.
*

According to your description, I checked this issue. As Prepare for IoT Hub connection to read messages states that you need to construct the connection string for your IoT hub endpoint as follows:
Endpoint={Event Hub-compatible endpoint};SharedAccessKeyName=iothubowner;SharedAccessKey={Primary key}
Replace {Event Hub-compatible endpoint} with:
Replace {Primary key} with:
Not a valid service bus connection string.
I assumed that you encounter this error when you creating a new Event Hub connection as follows:
When you add new connection string for your Event Hub, it should look like as follows:
Note: I assumed that you have confused with Service Bus connection string and IoT Hub connection string.
Connection string for Service Bus:
Endpoint=sb://{your-servicebus-name}.servicebus.windows.net/;SharedAccessKeyName={SharedAccessKeyName};SharedAccessKey={SharedAccessKey}

Related

Azure Function Service Bus - Managed Identity - Service Bus account connection string

I've followed the azure guides on setting up a managed identity for Service Bus. I'm running into the following error:
Service Bus account connection string 'ServiceBusConnection' does not exist.
I do have the "connection" in the function.json listed as "ServiceBusConnection"
In the live metrics I get this error when sending from the queue.
Service Bus account connection string 'ServiceBus' does not exist. Make sure that it is a defined App Setting.
I do have in my settings for the function app and locally the following configuration:
"ServiceBusConnection_fullyQualifiedNamespace":"<xxxxx>.servicebus.windows.net"
I've also defined AzureWebJobsStorage__accountName
I seem to be very stuck, followed the azure guides, can't find anything I'm doing wrong.
Wow, this took me too long to figure out, although I'm not sure why it behaves this way.
Looks like the error message I was getting was very telling.
I switched "ServiceBusConnection_fullyQualifiedNamespace" to "ServiceBus_fullyQualifiedNamespace" because it said Service Bus account connection string 'ServiceBus' does not exist.
This did work. I'm still unclear as to why I can't name the connection prefix as I please.
Connection string details here

How to pull Microsoft Azure Event Hub instance details like event hub connection string ,from our application

I am using Microsoft Azure Resource Manager API
https://learn.microsoft.com/en-us/rest/api/resources/resources/listbyresourcegroup
I am able to pull all event hub namespaces under particular
Subscription & resource group . But I am unable to pull event hub instances details like , event hub connection string and name of availabile event hub instances.
Seams that there is no such option in the rest api you mentioned.
You should use the following apis for fetching event hub connection string and name of event hub instances respectively.
For names of event hub instances, use this api, you need to specify the namespce:
GET
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs?api-version=2017-04-01
For connection strings, use this api. You should specify namespace / event hub name / connection string name:
POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}/authorizationRules/{authorizationRuleName}/ListKeys?api-version=2017-04-01
Response for connection string of event hub:
Hope it helps.

Azure Function Triggered by IoT Hub event - the messaging entity could not be found

When developing Azure Function thru Class Library approach (local development) I came across issue when using Even Hub compatible endpoint of IoTHub for triggering my function. This is set thru IoTHubTrigger attribute:
[FunctionName("IoTHubMessageProcessor")]
public static void Run([IoTHubTrigger("messages/events", Connection= "IoTHubReceiveEventsConnectionEndpoint")]EventData message, ILogger log)
When using provided connection string and messages/events endpoint I received error stating that "messaging entity could not be found".
Solution was to alter the connection string and include also Event Hub compatible name in connection string as an entity path so it looks like this:
Endpoint=sb://<Event hub-compatible endpoint>.servicebus.windows.net/;EntityPath=<Event Hub compatible name>;SharedAccessKeyName=<keyName>;SharedAccessKey=<key>"

40400 Endpoint not found-error from Azure service bus (App function)

Im trying to create an "azure app function", that is listening on a Service Bus queue. Im using the quick start-method, so the only writing so far has been inserting the connection string
I have created a service bus instance and a queue and a policy permission (listen). I copied that connection string and removed the last part of it, so I my connection string is connection
Endpoint=sb://bla.servicebus.windows.net/;SharedAccessKeyName=bla-policy-principal-queue-listen;SharedAccessKey=<thekey>
I get error message :
Microsoft.ServiceBus: 40400: Endpoint not found., Resource:sb://bla.servicebus.windows.net/mysbqueue0.
I have seen a couple of similar questions but not for app functions, and the answers didnt make any sense to me. There are no code except the logging that was in the template
Im sending the messages from dynamics 365. Do I have to register the listener somewhere?
All suggestions are welcome, troubleshooting, or anything :)
You need to specify queue name aswell

Azure ioT and Event Hub?

I am trying to read the events that my device is sending. I am using azure npm lib to read the what i think is right.
Ok so first, under my Azure ioT Hub account for that service there is a tab call Messaging. There is something called "Event Hub-compatible name" and "Event Hub-compativle endpoint". Do i have to create a new Event hub with the name of "Event Hub-compatible name" or what? I am a bit confused :D
If not what is the connection string and topic and so on?
Here is how the code is now...
var azure = require('azure');
var serviceBusService = azure.createServiceBusService("Endpoint=XXXXXXXXXX.servicebus.windows.net/");
var isWaiting = false;
function waitForMessages(){
console.log("Checking Queue...");
isWaiting = true;
serviceBusService.receiveQueueMessage("messages","events",function (error, receivedMessage){
console.log(error);
console.log(receivedMessage);
isWaiting = false;
});
}
// Start messages listener
setInterval(function () {
if(!isWaiting){
waitForMessages();
}
}, 200);
The Event Hub-compatible name does not mean that you have to create a Event Hub with the same name.
IOT Hub provides an endpoint that is backward compatible with Event Hub API. I think the actual implementation is a little more complex, but you can think of IOT Hub as inheriting from or at least an implementation of Event Hubs. Use this Event Hub compatible name with any Event Hub SDKs or code examples as part of the connection string.
For explaining the concepts of Event Hub-compatible name & Event Hub-compatible endpoint, you can refer to the section How to read from Event Hubs-compatible endpoints of the offical doc Azure IoT Hub developer guide. You can use the Azure Service Bus SDK for .NET or the Event Hubs - Event Processor Host to read events from IoT Hub in C#.
Otherwise, there are two Azure IoT SDKs for NodeJS using connection string: Azure IoT Service SDK (API Reference) & Azure IoT Device SDK (API Reference).
The connection string that you can find it at the one policy of the tab Shared Access Policies in the All settings, please see the pic below from the doc Tutorial: Get started with Azure IoT Hub.
According to your needs for reading events from IoT Hub, you can follow these samples to code using Azure IoT SDKs for NodeJS.
Using Azure IoT Service SDK to list the deviceIds registed in your IoT Hub, please see the sample https://github.com/Azure/azure-iot-sdks/blob/master/node/service/samples/registry_sample.js.
Using Azure IoT Device SDK to monitor events from IoT Hub, please see the sample https://github.com/Azure/azure-iot-sdks/blob/master/node/device/samples/remote_monitoring.js.
Hope it helps. Any concern, please feel free to let me know.
You can use the Event Hubs SDK for Node.js to see events/messages sent by your device to your IoT Hub:
https://www.npmjs.com/package/azure-event-hubs
The client object of the event hubs SDK can accept an IoT Hub connection string, so you don't need to use the Event Hubs connection string.
If you're just trying to debug your device and want to verify that it's actually sending messages, you can use the tool called iothub-explorer provided with the Azure IoT Hub SDK:
https://github.com/Azure/azure-iot-sdks/tree/master/tools/iothub-explorer
Also a couple of clarifications regarding the previous answer: the Service SDK allows to send messages to devices, and to read the "feedback" message that the device sends, which is used to know if the device accepted or rejected the command message but contains no data. It doesn't help to read data events sent by the device.
Connect to the IoT Hub to receiving the data:
var protocol = 'amqps';
var eventHubHost = '{your event hub-compatible namespace}';
var sasName = 'iothubowner';
var sasKey = '{your iot hub key}';
var eventHubName = '{your event hub-compatible name}';
var numPartitions = 2;
Protocol
var protocol = 'amqps';
It is the Event Hub-compatible endpoint: sb://abcdefnamespace.servicebus.windows.net/
but without the sb:// and .service windows.net/
Like that: abcdefnamespace
var eventHubHost = '{your event hub-compatible namespace}';
Its so OK
var sasName = 'iothubowner';
Primary key, like this: 83wSUdsSdl6iFM4huqiLGFPVI27J2AlAkdCCNvQ==
var sasKey = '{your iot hub key}';
Name like this: iothub-ehub-testsss-12922-ds333s
var eventHubName = '{your event hub-compatible name}';
Its so OK
var numPartitions = 2;
Every Iot Hub instance comes with a built in endpoint that is compatible with Event Hubs. The Event Hub compatible endpoint you see in the Azure portal would be the connection string pointing to the Event Hub instance from where you can read all the messages sent to your Iot Hub instance.
You can use this connection string to the instantiate the EventHubConsumerClient class from the #azure/event-hubs library and read your messages.
In the event of a failover, it is said that this backing built-in endpoint would change. So, you would have to fetch the new connection string and restart the process. Another option is to use the sample code in the azure-iot-samples-node repo to get the Event Hub compatible connection string by passing in the Iot Hub connection string and then use the #azure/event-hubs library to read your messages. See more in Read from the built-in endpoint

Resources