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?
Is it possible to send simultaneous requests using the same session?
Configuring sendRequest() to execute a blocking send causes the entire session to wait for the current sendRequest() to complete before another sendRequest() can be initiated.
The best way to do this is to set sendRequest() to non-blocking and have your thread wait for the message receive callback to be triggered. You can use features such as the CorrelationId property on the messages to help correlate the requests with the replies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With