- 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/
我想读取 RabbitMQ 队列中未确认消息的负载或 messageId。这可能吗? 我想这样做的原因是我尝试使用 RabbitMQ 死信功能来构建一个循环以定期自动生成消息。简而言之,创建两个队列
除了 vFabric 由 VMWare 提供商业支持之外,vFabric RabbitMQ 和 RabbitMQ 之间的主要区别是什么? 最佳答案 来自 source : We also produc
RabbitMQ 集群中有如下三个节点。 在 RabbitMQ 中,有两个队列,q1 和 q2。 q1 和q2 的主副本分布在不同的节点上。两个队列都被其他节点镜像。 三个节点前面有一个负载均衡器。
我希望在谷歌计算引擎上实现 rabbitmq 来处理我的 android 和 ios 消息传递应用程序上的消息。我听说 rabbitmq 可能非常耗电,所以我想知道解决这个问题的最佳解决方案是什么?我
是否可以在 RabbitMQ 服务器(管理插件 View )中查看连接单元的主机名,而不仅仅是 IP/端口?我们使用动态连接位置,这样更容易识别客户...... 最佳答案 不,没有这样的内置功能。 作
我正在阅读 RabbitMQ in Action 书,仍在第 2 章中,但作者说的一件事让我感到困惑。您设置了一个交换并发送了一条消息,两个订阅者正在监听队列。当第一条消息进来时,第一个订阅者得到它,
我正在使用 RabbitMQ 将所有消息排队,并将消息作为 SMS 发送给各个消费者。我正在使用直接交换,并且我已经正确地创建了一个到带有路由键的队列的绑定(bind)。问题是,当我尝试发布消息时,我
我们正在使用微服务架构在 nodejs 中实现 Web-API。每个服务都会公开 HTTP 端点,以便应用程序/网站可以与其交互。为了同步不同的数据库,我们目前使用 RabbitMQ。微服务可以在扇出
我计划在 RabbitMQ 消息头中存储堆栈跟踪。消息 header 是否有大小限制? 最佳答案 RabbitMQ 默认使用 AMQP 版本 0.9.1。根据AMQP protocol specifi
无法理解 exclusive queue 和 exclusive consumer 之间的区别,想知道我是否理解正确。 假设我有一个 queue、consumer1 和 consumer2。 我的理解
发布到 RabbitMQ 队列(发布/订阅模型)时消息的最大大小是多少? 我在文档中看不到任何明确的限制,但我认为有一些指导方针。 提前致谢。 最佳答案 我在做比较亚马逊队列服务和 RabbitMQ
我可以使用 Publish/Subscribe 创建扇出交换RabbitMQ Java 教程,任何连接的消费者都会收到一条消息的副本。我不想以动态/编程方式声明交换和绑定(bind),而是想在连接任何
java的 native rabbitmq客户端允许在连接设置上设置心跳,例如: import com.rabbitmq.client.ConnectionFactory; ... Connectio
我开始着手一个新项目,我们被要求将系统构建为一系列微服务,使用 RabbitMQ 作为它们之间的通信层。 在开发 REST API 时,我倾向于使用接受 HTTP header 来控制版本控制,我看到
在 Rabbit MQ 中使用集群时,我计划使用竞争订阅者模式。 Producer : 1 Exchange : 1 direct Queue : 1 Consumers : n (multiple)
是否可以实现 aggregator pattern在 RabbitMQ 中? 我有 A … N在发送到另一个队列之前我需要等待/聚合的消息 X . 所以我想我会有一些 唯一 ID 确保消息被路由 独家
我正在使用RabbitMQ向用户发送通知。用户可以随时读取其队列。 我面临的问题是,队列在夜间充满了很多通知,而当用户在早上返回时,他必须顺序处理这些消息。这些通知中有很多甚至是重复的。 我认为在发布
是否可以延迟通过 RabbitMQ 发送消息? 例如,我想在 30 分钟后使客户端 session 过期,并且我发送了一条将在 30 分钟后处理的消息。 最佳答案 您可以尝试两种方法: 旧方法:在每个
RabbitMQ 在单个服务器上可以处理的最大队列数是多少? 这取决于内存吗?它取决于 erlang 进程吗? 最佳答案 RabbitMQ 代理内部没有任何硬编码限制。代理将利用所有可用资源(除非您对
RabbitMQ Server 使用或需要在防火墙上为节点集群打开哪些端口? 我的 /usr/lib/rabbitmq/bin/rabbitmq-env 设置如下,我假设需要 (35197)。 SER
我是一名优秀的程序员,十分优秀!