1

Code Snippets:

host.json

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

Function Code:

public class SBFuncTrigger
    {
        private readonly ILogger<Function1> _logger;

        public Function1(ILogger<Function1> log)
        {
            _logger = log;
        }

        [FunctionName("SBFuncTrigger")]
        public void Run([ServiceBusTrigger("sampletopic", "sbtopicsubscription", Connection = "ServiceBusConnStr")]string mySbMsg)
        {
            _logger.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
        }
    }

Output:

For detailed output, run func with --verbose flag.
 Host lock lease acquired by instance ID '<Some_Id>'.
 Executing 'SBFuncTrigger' (Reason='(null)', Id=
<Some_Id>)
 Trigger Details: MessageId: 
<Some_Id>, SequenceNumber: 8, DeliveryCount: 1, EnqueuedTimeUtc: , LockedUntilUtc: , SessionId: (null)
 Executed 'Function1' (Succeeded, Id=
<Some_Id>, Duration=xxxms)

I'm not getting the msg in output:

C# ServiceBus topic trigger function processed message: {mySbMsg}

Details/Implementation:

  1. Created logic app for sending message to topic subscription with content "Hello to Azure Functions Service Bus" enter image description here

  2. Azure Functions Service Bus Topic Trigger - created with a topic and subscription in the Azure Portal Service Bus Namespace.

  3. Logic App Workflow connected to Service Bus Topic Subscription for message transfer.

  4. Connection string of service bus ServiceBusConnStr is defined in local.settings.json

4
  • Does Logic App Workflow read from the same topic? Commented Mar 24, 2023 at 5:59
  • ServiceBusTrigger is normally used for the Function: learn.microsoft.com/en-us/azure/azure-functions/… Commented Mar 24, 2023 at 7:40
  • Yes @MarkusMeyer, Logic App Workflow is designed to the same topic given in the Service Bus Trigger Function Declaration Code. Commented Mar 24, 2023 at 10:32
  • Hello @codebrane, Service Bus Trigger can receive the message from the Logic App designed with When a http request is received (Logic App Runs) > Send a message to Service Bus Topic specified. I have given implementation in the question. Commented Mar 24, 2023 at 10:34

1 Answer 1

2
Answer recommended by Microsoft Azure Collective

You’re missing the ILogger Class in the Function Declaration of the Service Bus Trigger you have provided.

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace KrishSBNet6FunctionApp
{
    public class Function1
    {
        private readonly ILogger<Function1> _logger;
        public Function1(ILogger<Function1> log)
        {
            _logger = log;
        }

        [FunctionName("Function1")]
        public void Run([ServiceBusTrigger("messagetopic", "topicsubsn", Connection = "SBConnection")] string mySbMsg, ILogger _logger)
        {
            _logger.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
        }
    }
}

enter image description here

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

Comments

Your Answer

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