I am using .NET Isolated Functions
I need to send multiple messages to a queue
So I am using the code below
[Function("process-duplicates")]
public async Task<DispatchedMessages> ProcessDataAsync([Microsoft.Azure.Functions.Worker.HttpTrigger(AuthorizationLevel.Anonymous,
"post", Route = "myroute")]
HttpRequest req,
IAsyncCollector<string> asyncCollector)
{
await _passfortDataService.ProcessDataAsync();
return new DispatchedMessages
{
Messages = myService.MessagesToBeSent.Select(x => x.ToJson()),
Status = new OkObjectResult("Processed Data")
};
}
Where DispatchedMessages is
public class DispatchedMessages
{
[JsonIgnore]
[ServiceBusOutput("QueueName", Connection = "event-bus-connection")]
public IEnumerable<string> Messages { get; set; }
public IActionResult Status { get; set; }
}
This works fine for a normal queue
However, I now need to get this work on a session based queue so I need to provide a value for the sessionId
var messages = new List<ServiceBusMessage>();
_myServices.MessagesToBeSent.ForEach(x =>
{
var message = new ServiceBusMessage(x.ToJson())
{
SessionId = "Test"
};
messages.Add(message);
});
var result = new DispatchedMessages
{
Messages = messages.Select(x => x.ToJson()),
Status = new OkObjectResult("Processed Data")
};
But this doesnt work
How can I do this?
Paul