如何让SimpleRpcClient.Call()成为阻塞调用,实现与RabbitMQ的同步通信?
在 RabbitMQ 的 .NET 版本 (2.4.1) 中,RabbitMQ.Client.MessagePatterns.SimpleRpcClient 有一个具有以下签名的 Call() 方法:
public virtual object[] Call(params object[] args);
public virtual byte[] Call(byte[] body);
public virtual byte[] Call(IBasicProperties requestProperties, byte[] body, out IBasicProperties replyProperties);
问题:
经过各种尝试,该方法仍然继续不阻止我期望的情况,因此它无法处理响应。
问题:
我是否在SimpleRpcClient的设置中遗漏了一些明显的东西,或者之前的IModel,< em>IConnection,甚至PublicationAddress?
更多信息:
我也尝试了 QueueDeclare() 方法的各种参数配置,但没有成功。
string QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary arguments);
我的设置的更多参考代码:
IConnection conn = new ConnectionFactory{Address = "127.0.0.1"}.CreateConnection());
using (IModel ch = conn.CreateModel())
{
var client = new SimpleRpcClient(ch, queueName);
var queueName = ch.QueueDeclare("t.qid", true, true, true, null);
ch.QueueBind(queueName, "exch", "", null);
//HERE: does not block?
var replyMessageBytes = client.Call(prop, msgToSend, out replyProp);
}
在其他地方寻找
或者我的“服务器端”代码是否可能存在问题?无论是否使用 BasicAck(),客户端似乎都已继续执行。
In the .NET version (2.4.1) of RabbitMQ the RabbitMQ.Client.MessagePatterns.SimpleRpcClient has a Call() method with these signatures:
public virtual object[] Call(params object[] args);
public virtual byte[] Call(byte[] body);
public virtual byte[] Call(IBasicProperties requestProperties, byte[] body, out IBasicProperties replyProperties);
The problem:
With various attempts, the method still continues to not block where I expect it to, so it's unable ever handle the response.
The Question:
Am I missing something obvious in the setup of the SimpleRpcClient, or earlier with the IModel, IConnection, or even PublicationAddress?
More Info:
I've also tried various paramater configurations of the QueueDeclare() method too with no luck.
string QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary arguments);
Some more reference code of my setup of these:
IConnection conn = new ConnectionFactory{Address = "127.0.0.1"}.CreateConnection());
using (IModel ch = conn.CreateModel())
{
var client = new SimpleRpcClient(ch, queueName);
var queueName = ch.QueueDeclare("t.qid", true, true, true, null);
ch.QueueBind(queueName, "exch", "", null);
//HERE: does not block?
var replyMessageBytes = client.Call(prop, msgToSend, out replyProp);
}
Looking elsewhere:
Or is it likely there's an issue in my "server side" code? With and without the use of BasicAck() it appears the client has already continued execution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
--简短回答--
“你做错了”的一点......
如果您偶然发现这个问题,那么您要么采取了错误的方法就像我一样,并且可能犯了类似的错误,错误地操作了 IBasicProperties,从而损害了 SimpleRpcServer 正确运行的能力。
--长答案--
.NET 工作示例:
在 BitBucket 上找到我的工作示例:
或者这是一个快速示例...
客户端:
服务器端:
共享:
--SHORT ANSWER--
Bit of the "You're doing it wrong"...
If you stumble upon this question, you've either taken the wrong approach as I have, and possibly if made a similar mistake of manipulating IBasicProperties incorectly thereby hurting the ability of SimpleRpcServer to function correctly.
--LONG ANSWER--
Working Sample for .NET:
Find my working example up on BitBucket here:
Or here's a quick sample...
Client side:
Server side:
Shared: