简体   繁体   中英

how to push a message onto azure service bus and trigger an azure function to log it sees the message

I'm experimenting with Azure and Azure Service Bus. I just want to push messages onto a queue and then have my C# azure function log that is sees the message. I'm struggling to get it working. I've created an azure account, created a resource group, created a service bus, downloaded storage explorer. I have the shared access policy 'RootManageSharedAccessKey' which has the 'managed' option checked in the portal.

So guessing what I do next? I've gone to azure functions and created a function, shown below, in the azure portal. When I open up storage explorer I'm not sure what option to use to connect to my azure instance with?

Any help? Thank you!

azure function

using System;
using System.Threading.Tasks;

public static void Run(string myQueueItem, ILogger log)
{
    log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}

Using Service Bus Explorer you can connect to Azure Service Bus and administer messaging entities. You can download the tool here . 在此处输入图片说明

Once you download the tool you run “ServiceBusExplorer.exe” In the Service Bus Explorer go to File Connect

Enter Connection string which you can find on in

Azure portal Dashboard --> Service Bus --> Shared access policies

在此处输入图片说明

After connected Successfully you will be able to see all the topics/queues in the connected servicebus select the Queue that you wanted Access

and then click on Send Messages as follows it will populate message box then you have to write the content of your message in required format(json, xml etc) and send it. 在此处输入图片说明

Don't confuse Azure Service Bus Queues with Azure Storage Queues. You can use Azure Storage Explorer to see Azure Storage Queues, but not Azure Service Bus Queues. To access Azure Service Bus Queues, download Azure Service Bus Explorer here To my knowledge, there is no binary distribution and you're going to need to build it yourself after cloning the repo. Once you run it and connect to your Service Bus Namespace, you can create a queue and insert messages into it.

Next, you'll need to define a ServiceBusTrigger on your Azure Function. This is an attribute that will monitor the specified Service Bus Queue and poll for new messages. When it finds one, it'll call your function. Assuming you're using Azure Functions v2, here's a Microsoft tutorial to do this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM