activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rasitha <rasitha.wijesin...@gmail.com>
Subject Re: Dead Letter Queue
Date Tue, 31 May 2011 20:42:45 GMT
I'm not having any luck even with Auto Ack. I'm using Apache.NMS framework
though.

Messages do get to ProcessMessage method but when the exception is thrown,
they don't get to DLQ. 

Do you know what I'm doing wrong here?


    class DeadLetterQueueTest
    {

        static void Main(string[] args)
        {
            Run();
        }

        private static void Run()
        {
            var uri = "failover:tcp://server1:10280";
            var user = "amq";
            var pass = "amq";
            var queue = "dlqtest";
            CreateTestMessage(uri, user, pass, queue);
            StartConsumer(uri, user, pass, queue);
            new ManualResetEvent(false).WaitOne();
        }
        

        private static void StartConsumer(string uri, string user, string
pass, string queue)
        {
            var session = GetSession(uri, user, pass);
            var consumer = session.CreateConsumer(new ActiveMQQueue(queue));
            consumer.Listener += ProcessMessage;
        }

        private static void ProcessMessage(IMessage message)
        {
            Console.WriteLine(message);
            throw new ApplicationException();
        }

        private static void CreateTestMessage(string uri, string user,
string pass, string queue)
        {
            using (var session = GetSession(uri, user, pass))
            {
                using (var producer = session.CreateProducer(new
ActiveMQQueue(queue)))
                {
                    var msg = producer.CreateTextMessage("Hello");
                    producer.Send(msg);
                }
            }
        }

        private static ISession GetSession(string uri, string user, string
pass)
        {
            var factory = new ConnectionFactory(uri);
            var conn = factory.CreateConnection(user, pass);
            IRedeliveryPolicy policy = conn.RedeliveryPolicy;
            policy.InitialRedeliveryDelay = 100;
            policy.UseExponentialBackOff = false;
            policy.MaximumRedeliveries = 0;
            conn.Start();
            conn.RedeliveryPolicy = policy;
            return conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
        }
    }

--
View this message in context: http://activemq.2283324.n4.nabble.com/Dead-Letter-Queue-tp2356685p3564283.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message