- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在研究 Rabbit-Mq,并试图实现一个“死信”队列,一个用于失败消息的队列。我一直在阅读兔子文档:https://www.rabbitmq.com/dlx.html .
并想出了这个例子:
internal class Program
{
private const string WorkerExchange = "work.exchange";
private const string RetryExchange = "retry.exchange";
public const string WorkerQueue = "work.queue";
private const string RetryQueue = "retry.queue";
static void Main(string[] args)
{
var factory = new ConnectionFactory { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.ExchangeDeclare(WorkerExchange, "direct");
channel.QueueDeclare
(
WorkerQueue, true, false, false,
new Dictionary<string, object>
{
{"x-dead-letter-exchange", RetryExchange},
// I have tried with and without this next key
{"x-dead-letter-routing-key", RetryQueue}
}
);
channel.QueueBind(WorkerQueue, WorkerExchange, string.Empty, null);
channel.ExchangeDeclare(RetryExchange, "direct");
channel.QueueDeclare
(
RetryQueue, true, false, false,
new Dictionary<string, object> {
{ "x-dead-letter-exchange", WorkerExchange },
{ "x-message-ttl", 30000 },
}
);
channel.QueueBind(RetryQueue, RetryExchange, string.Empty, null);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0}", message);
Thread.Sleep(1000);
Console.WriteLine("Rejected message");
// also tried channel.BasicNack(ea.DeliveryTag, false, false);
channel.BasicReject(ea.DeliveryTag, false);
};
channel.BasicConsume(WorkerQueue, false, consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
}
}
我觉得好像遗漏了一些小细节,但似乎无法找到它们是什么。
提前致谢
最佳答案
您应该将死信交换定义为fanout
。
我们开始了:channel.ExchangeDeclare(RetryExchange, "fanout");
If your dead letter exchange is setup as DIRECT you must specify a dead letter routing key. If you just want all your NACKed message to go into a dead letter bucket for later investigation (as I do) then your dead letter exchange should be setup as a FANOUT.
关于c# - Rabbit-Mq在被拒绝后没有路由到死信队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48583893/
我正在创建一个死信 channel 错误处理程序,如下所示 errorHandler(deadLetterChannel("direct:myDLC").useOriginalMessage().ma
以下是我的 Camel 路线代码 .errorHandler(deadLetterChannel("jmstx:queue:ErrorHandler") .useOriginalMessage()
我正在尝试跨不同的集群系统进行分布式发布-订阅,但无论我尝试什么,它都不起作用。 我想做的就是创建一个简单的示例。 1)我创建一个主题,说“内容”。 2) 假设 jvm A 中的一个节点创建主题、订阅
我是一名优秀的程序员,十分优秀!