Junior — Middle
Which design pattern provides message exchange in synchronous mode using queues?
sobes.tech AI
Answer from AI
The design pattern that facilitates message exchange in synchronous mode using queues is called Message Queue or Message Broker.
In the context of C# and .NET, the Message Queue pattern is often used with synchronous message sending and receiving through queues, for example, using MSMQ (Microsoft Message Queuing).
An example of using a queue for synchronous communication:
// Sending a message to the queue
MessageQueue queue = new MessageQueue(@".\Private$\MyQueue");
queue.Send("Hello, World!");
// Synchronous message receiving
Message msg = queue.Receive();
msg.Formatter = new XmlMessageFormatter(new String[] { "System.String" });
string body = (string)msg.Body;
Console.WriteLine(body);
Thus, the Message Queue pattern allows organizing message exchange with guaranteed delivery and synchronous processing.