- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在其他人的项目中使用 RabbitMQ,但在出队和丢失数据方面遇到了问题。
当我发布时,数据都以字符串的形式存在,并且也正确地存在于 RabbitMQ 队列中。当我关闭数据时,数据的一部分像用户 ID 一样存在,但其余部分都消失了。我查看了整个代码,我相当肯定它在 RabbitMQ 上发生了一些事情,并且在我出队时发生了。任何帮助将不胜感激。谢谢。这是发布前的代码。
private bool sendJobToMQ(EncodeJobModel job, string p_correlation_id, string p_request_routing_key)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
StringBuilder sb_job = new StringBuilder();
ser.Serialize(job, sb_job);
string rpc_reply_queue;
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = HOST_NAME;
factory.VirtualHost = VHOST_NAME;
factory.UserName = USERNAME;
factory.Password = PASSWORD;
IConnection rabconn = factory.CreateConnection();
IModel sender_channel = rabconn.CreateModel();
try
{
sender_channel.ExchangeDeclare(EXCHANGE_NAME, ExchangeType.Direct, true, false, null);
}
catch (Exception err)
{
logger.Error("Error Declaring Exchange " + EXCHANGE_NAME + ": " + err.ToString());
return false;
}
try
{
sender_channel.QueueDeclare(REQUEST_QUEUE, true, false, false, null);
}
catch (Exception err)
{
logger.Error("Error QueueDeclare (" + REQUEST_QUEUE + " true, false, false, null): " + err.ToString());
return false;
}
try
{
sender_channel.QueueBind(REQUEST_QUEUE, EXCHANGE_NAME, REQUEST_ROUTING_KEY, null);
}
catch (Exception err)
{
logger.Error("Error QueueBind (" + REQUEST_QUEUE + " -> " + EXCHANGE_NAME + " " + REQUEST_ROUTING_KEY + ", null): " + err.ToString());
return false;
}
//rpc_reply_queue = sender_channel.QueueDeclare("rq_" + job.encodejob_id.ToString(), false, false, true, null);
//////bind the rpc reply queue to the exchange via a routing key (I appended _routingkey to signify this)
//sender_channel.QueueBind(rpc_reply_queue, EXCHANGE_NAME, rpc_reply_queue + "_routingkey");
//// Not sure what the props object is for yet but you can try to pass null in the mean time - Steve "Apeshit" Han
BasicProperties props = new BasicProperties();
props.CorrelationId = p_correlation_id;
//props.ReplyTo = rpc_reply_queue;
try
{
sender_channel.BasicPublish(EXCHANGE_NAME, REQUEST_ROUTING_KEY, props, Encoding.UTF8.GetBytes(sb_job.ToString()));
}
以及出队的代码。
QueueingBasicConsumer consumer = new QueueingBasicConsumer(p_channel);
string consumerTag = p_channel.BasicConsume(p_queue, false, consumer);
if (_is_console && Environment.UserInteractive)
Console.WriteLine("Listening...");
while (m_Listen)
{
try
{
//get the properties of the message, including the ReplyTo queue, to which we can append '_routingkey' (designated by me), to reply with messages
BasicDeliverEventArgs e;
Object message;
if (!consumer.Queue.Dequeue(4000, out message)) {
// we do not wait to indefinitely block on waiting for the queue
// if nothing in queue continue loop iteration and wait again
continue;
}
// cast as necessary back to BasicDeliverEventArgs
e = (BasicDeliverEventArgs)message;
IBasicProperties props = e.BasicProperties;
//get the Correlation ID sent by the client to track the job
string client_correlation_id = props.CorrelationId;
// I left out the reply_to field in the wizard, it can be set back in ApiEncodeServiceDefault - Steve "Smurfing Smurf" Han
//string reply_to = props.ReplyTo;
//get the body of the request
byte[] body = e.Body;
string body_result = Encoding.UTF8.GetString(body);
bool redelivered = e.Redelivered;
e.Body 字符串缺少数据。
最佳答案
如果你没有任何消息,为什么要继续最好在收到消息之前阻塞,否则该过程不有趣(没有数据工作?)像这样尝试
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queueName, null, consumer);
while (m_Listen) {
try {
RabbitMQ.Client.Events.BasicDeliverEventArgs e =
(RabbitMQ.Client.Events.BasicDeliverEventArgs)
consumer.Queue.Dequeue();
IBasicProperties props = e.BasicProperties;
byte[] body = e.Body;
// ... process the message
channel.BasicAck(e.DeliveryTag, false);
} catch (OperationInterruptedException ex) {
// The consumer was removed, either through
// channel or connection closure, or through the
// action of IModel.BasicCancel().
break;
}
关于c# - 出列后 RabbitMQ 正文中缺少数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12014775/
我正在使用示例中提到的ajaxQueue Queueing something like Ajax Calls : // jQuery on an empty object, we are going
我有自定义的 tableView header ,但是我指定 header 文本颜色和分隔线的代码仅在 header 出列时才有效,当我将它们滚动到屏幕外时。只有这样他们才会返回白色文本颜色和可见的分
第一次尝试 Collection View 并遇到此错误: Terminating app due to uncaught exception 'NSInternalInconsistencyExce
我正在从 PL/SQL 程序调用 DBMS_AQ.DEQUEUE。我不想永远等待,但如果在再次尝试出队之前队列中没有数据,我会定期超时。 Oracle documentation DEQUEUE 过程
我有 UICollectionView,但似乎我设置的一切都正确。但是我得到了错误: 'could not dequeue a view of kind: UICollectionElementKin
我目前正在运行 sidekiq 4.1.2。我从来没有设法同时运行过几个作业。最近,我似乎遇到了 Sidekiq 的故障排除 WIKI 中描述的一个名为 Too many connections to
我有两个 Collection View ,第一个 Collection View 没有第二个 Collection View ,效果很好。但是当我添加第二个 Collection View 时,我收
我正在 Swift3 中构建一个键盘扩展。 我的键盘第一次启动时,没问题,我的收藏 View 显示得很好,一切正常。 当我的键盘进入后台并在前台再次返回时,会出现此错误。例如,我启动 iMessage
切换到 Windows 8 后,我的应用程序停止工作。我花了几个小时调试问题,发现 IOCP 的行为在 Windows 8 和以前的版本之间有所不同。我提取了必要的代码来演示和重现问题。 SOCKET
我是一名优秀的程序员,十分优秀!