[rabbitmq-discuss] How to setup dead-letter queue in C# ?
Johan Klijn
johanklijn_nl at hotmail.com
Mon Dec 10 16:11:55 GMT 2012
I changed the code at some places, without any luck.
static void Main(string[] args)
{
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.HostName = "10.57.244.205";
IConnection connection = connectionFactory.CreateConnection();
IModel channel = connection.CreateModel();
//Declare default exchange
channel.ExchangeDeclare("MessageQueueExchange", ExchangeType.Direct);
Hashtable arguments = new Hashtable()
{
{"x-dead-letter-exchange", "amq.fanout"}
};
channel.QueueDeclare("MessageQueue", true, false, false, arguments);
channel.QueueBind("MessageQueue", "MessageQueueExchange",
"MessageQueue", null);
//Queue message
byte[] messageBody;
MyMessage message = new MyMessage("ID-1");
DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof (MyMessage));
using (MemoryStream memoryStream = new MemoryStream())
{
serializer.WriteObject(memoryStream, message);
messageBody = memoryStream.ToArray();
}
IBasicProperties basicProperties = channel.CreateBasicProperties();
basicProperties.ContentType = "application/json";
basicProperties.DeliveryMode = 2;
channel.BasicPublish("MessageQueueExchange", "MessageQueue",
basicProperties, messageBody);
//DeQueue
BasicGetResult result = channel.BasicGet("MessageQueue", false);
//Negative Acknowledge
channel.BasicNack(result.DeliveryTag, false, false);
}
Attached some screenshots with the exchanges/queues.
amq.fanout_Exchange.png
<http://rabbitmq.1065348.n5.nabble.com/file/n23944/amq.fanout_Exchange.png>
CustomQueue1_Queue.png
<http://rabbitmq.1065348.n5.nabble.com/file/n23944/CustomQueue1_Queue.png>
MessageQueue_Exchange.png
<http://rabbitmq.1065348.n5.nabble.com/file/n23944/MessageQueue_Exchange.png>
MessageQueue_Queue.png
<http://rabbitmq.1065348.n5.nabble.com/file/n23944/MessageQueue_Queue.png>
--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/How-to-setup-dead-letter-queue-in-C-tp23913p23944.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss
mailing list