I have created an Azure Functions project and am testing it locally. Below is my code that creates a cloud queue. It then adds id returned from my CarComponent.
[FunctionName("CarDiscovery")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
var connectionString = "UseDevelopmentStorage=true";
// Parse the connection string and return a reference to the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("discovery-queue");
// Create the queue if it doesn't already exist
queue.CreateIfNotExists();
CarComponent cars = new CarComponent();
var carList = cars.GetActiveCars();
foreach (var car in carList)
{
byte[] toAdd = BitConverter.GetBytes(car.Id);
CloudQueueMessage message = new CloudQueueMessage(toAdd); // <-- Put the ID of each metro in the message
queue.AddMessage(message);
}
}
When I start the function using the azure storage emulator it runs successfully.
I would like to create a another azure function that runs with a Queue trigger that I can test locally.
(1) Where do I go to view the current messages that have been added to development storage?
(2) What do I specify as the connection when creating the Azure function with the queue trigger? (see below)
Where messages in queue can be found
According to this article:
Therefore, you need to:
http://127.0.0.1:10001/<account-name>/<resource-path>
In the worst case, you can bind your local function to real Azure Storage Queue.
Queue connection string
In few words: install VS Tools for Azure Functions; add local settings; add
QueueTrigger
attribute to your function method parameter.Visual Studio Tools for Azure Functions.
Once you create a new Function project, add
local.settings.json
file to the root of your solution with the similar content:Add
QueueTrigger
attribute. Your Azure Function entry point should be like:1) To view the messages in your queue, you can use the Azure Storage Explorer: https://azure.microsoft.com/en-us/features/storage-explorer/
2) To have your function connect to the queue, you will need the storage account's key. You can get this by following this SO answer: https://stackoverflow.com/a/43219736/84395
Once you have the key, add a new value in the
local.settings.json
:So to answer your second question: You would specify MyStorageAccountConnection as the name of the connection.