1

I am trying to run Azure Function(C#) with service bus trigger and using DAPR to publish message to another queue in VS Code. But I am getting below error when I try to run the code: "No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.)."

Below is my Azure Function code

using System;
using System.Collections.Generic;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.WindowsAzure.Storage.Blob;
using Dapr.Client;
namespace Company.ERM
{

public class erman
{
    [FunctionName("erman")]
    public void Run([ServiceBusTrigger("erman", Connection = "CON_SERVICEBUS")]string myQueueItem, ILogger log)
    {
        log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
         using var client = new DaprClientBuilder().Build();

        client.PublishEventAsync("orderpubsub", "orders", "test");
    }
}
}

The yaml file in Component folder that I am using is as given below

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: orderpubsub
spec:
  type: pubsub.redis
  version: v1
  metadata:
  - name: redisHost
    value: localhost:6379
  - name: redisPassword
    value: ""

Below is the command that I am running to run the function using DAPR in VS code:

dapr run --app-id checkout --resources-path ./component/  -- func start --no-build --verbose

Please suggest if I am missing something .

4
  • "If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.)." => Do you register the ServiceBus? Commented Sep 26, 2023 at 6:46
  • I'd also suggest following C#/.Net naming conventions. Commented Sep 26, 2023 at 6:47
  • This is a Azure Function project and I don't have startup.cs file. Also when I run in debug mode it works the issue is only when I am trying to run using DAPR and dapr command. Commented Sep 26, 2023 at 12:13
  • You don't have a startup.cs but you still need to configure your DI. That's probably going to be in a Program.cs .... Commented Sep 26, 2023 at 14:31

1 Answer 1

2

@fildor, Thanks for the insights. I created a service bus namespace in Azure Portal and added queues by navigating Entities>Queues>+Add.

enter image description here

I created an Azure Function app with a Service Bus Queue trigger in VS Code. dotnet add package Dapr.AspNetCore Package has been installed.

Function code:

using System;
using Microsoft.Azure.WebJobs;
using Dapr.Client;
using Microsoft.Azure.WebJobs.Host;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace MyFunctionApp
{
    public class daprfunc
    {
        [FunctionName("daprfunc")]
        public async Task RunAsync([ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
              using var client = new DaprClientBuilder().Build();
              await client.PublishEventAsync("pubsub", "topic", "Hello, Dapr!");
        }
    }
}

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "ServiceBusConnection":"Your-servicebus-connectionstring"
    }
}

function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-4.1.1",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "connection": "ServiceBusConnection",
      "queueName": "myqueue",
      "direction": "in",
      "isSessionsEnabled": false,
      "autoComplete": true,
      "name": "myQueueItem"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/MyFunctionApp.dll",
  "entryPoint": "MyFunctionApp.daprfunc.RunAsync"
}

pubsub.yaml:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.redis
  version: v1
  metadata:
  - name: redisHost
    value: localhost:6379
  - name: redisPassword
    value: ""

My function was successfully triggered by using the above code. Check below:

enter image description here

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

@Pavan...please let me know what command you ran on VS code to run it locally.
@Piyush, I used func start command to start the function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.