I want to send a message to a service bus queue and receive it's ID.
The sdk examples seems to provide a solution.
string connectionString = "<connection_string>";
string queueName = "<queue_name>";
// since ServiceBusClient implements IAsyncDisposable we create it with "await using"
await using var client = new ServiceBusClient(connectionString);
// create the sender
ServiceBusSender sender = client.CreateSender(queueName);
// create a message that we can send. UTF-8 encoding is used when providing a string.
ServiceBusMessage message = new ServiceBusMessage("Hello world!");
// send the message
await sender.SendMessageAsync(message);
// create a receiver that we can use to receive the message
ServiceBusReceiver receiver = client.CreateReceiver(queueName);
// the received message is a different type as it contains some service set properties
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
string id = receivedMessage.Id
The ReceiveMessageAsync() will return the first item in the queue, so how can I be sure that another message won't arrive to the queue (from another client) between sending the message
await sender.SendMessageAsync(message);
and receiving it
await receiver.ReceiveMessageAsync();