Skip to content

justcla/AzureFunctionsDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Functions Demo

This walk-through shows how to use Visual Studio to create and run an Azure Functions project.

The sample project includes two different types of Azure Functions and demonstrates:

  • how to trigger a function when an item shows up in a Queue (using a Queue Trigger)
  • how to trigger a function when a user posts an HTTP request (using an HTTP Trigger)
  • how to configure a local storage queue for testing (using Windows Storage Emulator)
  • how to locally debug an Azure Function

The major steps in the tutorial are:

  1. Setup Functions Project inside Visual Studio
  2. Setup Queue (for Queue Trigger)
  3. Test/Debug the Queue Trigger (Locally)
  4. Test the Http Trigger (Locally)

Setup Functions Project inside Visual Studio

Option 1: Fetch source from GitHub

Option 2: Setup Project from Scratch

Create New Azure Functions Project (AzureFunctionsDemo)
  • File -> New -> Project
    • Visual C# -> Cloud -> Azure Functions
      • Name: "AzureFunctionsDemo"
Create New Function - Http Trigger (HttpTriggerFunction.cs)
  • Project -> Add New Item…
    • Visual C# Items -> Azure Function
      • Name: "HttpTriggerFunction.cs"
Create New Function - Queue Trigger (QueueTriggerFunction.cs)
  • Project -> Add New Item…
    • Visual C# Items -> Azure Function
      • Name: "QueueTriggerFunction.cs"
      • Connection: "AzureWebJobsStorage"
  • Update local.settings.json
    • "AzureWebJobsStorage": "UseDevelopmentStorage=true"

Setup Queue (for Queue Trigger)

  • Start Azure Storage Emulator

    • From Windows Status bar
      Start Storage Emulator
  • Open Cloud Explorer in Visual Studio

    • View->Cloud Explorer
  • Add queue to local storage account

    • Expand: (Local) -> Storage Accounts -> (Development) -> Queues
    • Create Queue: "myqueue-items"
      Cloud Explorer - Local Queues

Test/Debug the Queue Trigger (Locally)

Run Project (in Debug mode)

  • Debug -> Start Debugging (F5)
    Functions Terminal Window will start
    Functions Terminal Window

  • Set breakpoint in QueueTriggerFunction.cs (line 12)
    Queue Trigger Breakpoint

Add a message to the queue: "Test message 1"

  • Open queue: myqueue-items (from Cloud Explorer)
    MyQueue-Items - No messages

  • Use the "Add Message" icon - 3rd from the right on queue toolbar

  • Enter text into message box: "Test message 1"
    Add Message Textbox
    Message appears in queue explorer window in Visual Studio
    MyQueue-Items - With message

Step through code in Visual Studio

  • [Wait 10 seconds]
    Program will break on line 12
    QueueTrigger Hits Breakpoint

  • Debug -> Step Over (F10)
    New messages printed in Functions Terminal Window
    Message printed in Functions Terminal Window
    Note: "Test message 1" appears printed on the console.

  • Debug -> Continue (F5)
    Execution completes.

  • Debug -> Stop Debugging (Shift+F5)

Test the Http Trigger (Locally)

About

Demo project for Azure Functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages