Reputation: 2299
I created a Function App which is triggered via Http. The function app should publish a message to Azure Service Bus Topic. I am not getting any message published in the topic for some reasons. I have the function app successfully triggered. I am not sure what I am doing wrong here. Below is my code.
[FunctionName("MessageProcessorFunction")]
[return: ServiceBus("mytopic", Connection = "Endpoint=sb://abcsb.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=wBCZ4ssssssohbg1ZUYKw4q8cpKaoZLIG9NR28ZoUDhBG8=")]
public async Task<string> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "sms")] HttpRequest req,
ILogger log)
{
log.LogInformation("HTTP trigger function processed a request.");
return "hello World";
}
However, the console app below successfully published a message to service bus topic. Here is the code
TopicClient _topicClient = new TopicClient("Endpoint=sb://abcsb.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=wBCZ4ssssssohbg1ZUYKw4q8cpKaoZLIG9NR28ZoUDhBG8=", "whispir");
string data = JsonConvert.SerializeObject("Hello world");
Message message = new Message(Encoding.UTF8.GetBytes(data));
try
{
await _topicClient.SendAsync(message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ServiceBusConnectionString": "Endpoint=sb://abcsb.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=wBCZ4okoohbg1ZUYKw4q8cpKaoZLIG9NR28ZoUDhBG8="
}
Any idea?
-Alan-
Upvotes: 0
Views: 339
Reputation: 702
The Connection
property should receive a settings key, not the actual connection string.
If you want to try it locally, you'll have to change the local.settings.json
file and add the connection string to a specific key:
{
"Values": {
"ServiceBusConnectionString": "Endpoint=sb://abcsb.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=wBCZ4ssssssohbg1ZUYKw4q8cpKaoZLIG9NR28ZoUDhBG8="
}
}
Then, use it in your function like this:
[FunctionName("MessageProcessorFunction")]
[return: ServiceBus("mytopic", Connection = "ServiceBusConnectionString")]
public async Task<string> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "sms")] HttpRequest req,
ILogger log)
{
log.LogInformation("HTTP trigger function processed a request.");
return "hello World";
}
Should be working.
Let me know if not. :)
Upvotes: 3