I'm trying to send multiple concurrent requests using the same session instance, and it looks like the session sends them one by one instead of sending them in parallel. It awaits for a reply before sending the next message.
using (var client = new SolaceClient())
{
for (int i = 0; i < 10; i++)
Task.Factory.StartNew((s) => SendRequest(TOPIC, $"Hello Solace! + {s}", s), i);
Console.ReadLine();
}
...
public void SendRequest(string topic, string content, object index)
{
using (IMessage message = ContextFactory.Instance.CreateMessage())
{
message.Destination = ContextFactory.Instance.CreateTopic(topic);
message.BinaryAttachment = Encoding.ASCII.GetBytes(content);
message.DeliveryMode = MessageDeliveryMode.Direct;
IMessage replyMessage = null;
Console.WriteLine($"Sending message....{index}");
ReturnCode returnCode = _session.SendRequest(message, out replyMessage, 4000);
if (returnCode == ReturnCode.SOLCLIENT_OK)
Console.WriteLine(Encoding.ASCII.GetString(replyMessage.BinaryAttachment));
else
Console.WriteLine("Request failed, return code: {0}", returnCode);
}
}
If i set the timeout to 0 (async) then it works as expected, but i need the requests to be synchronous within the same thread.
Is it possible to send simultaneous requests using the same session?