0

My function is like

    [FunctionName("MyFunctionName")]
    [return: ServiceBus("mytopic", Connection = "ServiceBusConnectionString")]
    public static async Task<string> MyFunctionAsync([QueueTrigger("my-input-queue")] string msgIn, TraceWriter log)
    {

My local.settings.json has

{
  "IsEncrypted": false,
  "Values": {
    "ServiceBusConnectionString": "[my connection string]"
  }
}

where [my connection string] is copy-pasted from a Primary Connecting String under one of the Shared access policies with a Send claim.

This just silently fails: Messages get stuck in my-input-queue and no errors are written to log streaming. However I'm 100% sure the attribute is the issue because I've deployed 100 different combinations of this to try and make it work :).

Any ideas?

See Sharp
  • 379
  • 1
  • 4
  • 11

2 Answers2

1

Based on my test,it should work with servicebus attribute. The following is my test code.

[return: ServiceBus("topicName",Connection = "ServiceBusConnectionString", EntityType = EntityType.Topic)]
public static async Task<string>Run([QueueTrigger("queueName")]string myQueueItem, TraceWriter log)
{
   ...
   return myQueueItem; // write to the Topic.
}

local.settings.json

{
 "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "xxxxxx",
    "AzureWebJobsDashboard": "xxxxxxxx",
    "ServiceBusConnectionString": "xxxxxx"
  }
}

You could get more information about Azure Service Bus output binding from this tutorial. You also could do that with follwoing way

[FunctionName("ServiceBusOutput")]
public static void Run([[QueueTrigger("queueName")]string myQueueItem,
                       TraceWriter log,
                       [ServiceBus("topicName",Connection = "ServiceBusConnectionString", EntityType = EntityType.Topic)]out string queueMessage)
{
    log.Info("Azure Function Demo - Azure Service Bus Queue Topic");

    queueMessage = myQueueItem;
}
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
0

You are missing the required settings for your QueueTrigger, so your function isn't triggering on new items in the queue. You should have values for AzureWebJobsStorage and AzureWebJobsDashboard, and your QueueTrigger should have a value for the Connection field.

For more information about how to wire up QueueTriggers and test locally, see this answer.

Connor McMahon
  • 1,318
  • 7
  • 15
  • No, that is not the problem. For example, if I change the return value to `Task` and get rid of the `[return: ..]` attribute, it picks up the messages in the queue. – See Sharp Jul 12 '18 at 17:42
  • So your function application is executing. Do you see logs about the function failing? – Connor McMahon Jul 12 '18 at 19:06