« Azure Service Bus » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
(→Code) |
||
Ligne 9 : | Ligne 9 : | ||
= Code = | = Code = | ||
Nuget {{boxx|Azure.Messaging.ServiceBus}} | Add Nuget package {{boxx|Azure.Messaging.ServiceBus}} | ||
<filebox fn='Sender/program.cs'> | |||
private const string ConnectionString = "get it from Azure Portal → Service Bus Namespace → Shared access policy → Primary Connection String"; | |||
private const string QueueName = "myqueue"; | |||
static async Task Main(string[] args) | |||
{ | |||
var client = new ServiceBusClient(ConnectionString); | |||
var sender = client.CreateSender(QueueName); | |||
var message = new ServiceBusMessage("Hello!"); | |||
await sender.SendMessageAsync(message); | |||
} | |||
</filebox> |
Version du 15 décembre 2021 à 16:18
Description
It is a message broker with message queues and publish-subscribe topics.
Configure the service bus on Azure
- Azure portal → Service Bus → Add
- Create namespace: the namespace will be the url use by the service bus
- Once deployed, go to the newly create service bus namespace → add queue
Code
Add Nuget package Azure.Messaging.ServiceBus
Sender/program.cs |
private const string ConnectionString = "get it from Azure Portal → Service Bus Namespace → Shared access policy → Primary Connection String"; private const string QueueName = "myqueue"; static async Task Main(string[] args) { var client = new ServiceBusClient(ConnectionString); var sender = client.CreateSender(QueueName); var message = new ServiceBusMessage("Hello!"); await sender.SendMessageAsync(message); } |