Reputation: 4260
The following code snippet has been taken from this Microsoft document:
[Function("SignalRFunction")]
[SignalROutput(HubName = "chat", ConnectionStringSetting = "SignalRConnectionString")]
public static MyMessage Run([SignalRTrigger("SignalRTest", "messages", "SendMessage", parameterNames: new string[] { "message" },
ConnectionStringSetting = "SignalRConnectionString")] string item,
[SignalRConnectionInfoInput(HubName = "chat")] MyConnectionInfo connectionInfo,
FunctionContext context)
{
var logger = context.GetLogger("SignalRFunction");
logger.LogInformation(item);
logger.LogInformation($"Connection URL = {connectionInfo.Url}");
var message = $"Output message created at {DateTime.Now}";
return new MyMessage()
{
Target = "newMessage",
Arguments = new[] { message }
};
}
public class MyMessage
{
public string Target { get; set; }
public object[] Arguments { get; set; }
}
What I'd like to do is to return multiple instances of MyMessage
simultaneously to send a message to different targets. Also, I'd like to return a JSON payload from Run
function comprising some other info e.g. a database record, etc.
How can the Run
function be augmented to support such a case?
Upvotes: 1
Views: 291
Reputation: 2069
You can return multiple instances of a class as a list of objects. For that you will have to change the data type of the Run
to the list of objects.
Here I have used an HTTP trigger, but the concept should also work of SignalIr trigger as well. Where we would add List<TestCLass>
as a data type of the Run
function where TestClass
is the class those instances we are returning.
public class TestClass
{
public string Target { get; set; }
}
public static List<TestClass> Run()
{
List<TestClass> tests = new List<TestClass>();
TestClass t = new TestClass();
TestClass q = new TestClass();
t.Target = "Hello World";
q.Target = "Another Hello World";
tests.Add(t);
tests.Add(q);
return tests;
}
output of the HTTP trigger:
ServieBusClient
to connect to azure service Bus. Similarly, you can find clients for other azure services as wellUpvotes: 0