activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ishitori <Ishit...@bk.ru>
Subject Emailing sender - advice required
Date Fri, 07 Oct 2011 15:17:17 GMT
Hi. I am developing a mail server which is responsible for sending emails.
Prepared emails are delivered to my server via ActiveMQ. I would like to
organize the code in the best way, so it would meet the following
requirements:

* Every email that is read from the queue should be delivered to the
recipient. If the delivery is not possible due to SMTP problems, then the
message should be marked as not acknowledged and redelivered later by
ActiveMQ. I want to process every message individually.
* Maximum possible throughput is guaranteed.
* Duplicated emails should not be send

The best decision I found so far is to create N threads that executes the
following code:

public void WorkerMethod() 
{
    var queueConnection = connectionFactory.CreateConnection();
    var queueSession =
queueConnection.CreateSession(Apache.NMS.AcknowledgementMode.Transactional);
    var consumer = session.CreateConsumer(destination);

    while (!this.resetProcessingEvent.WaitOne(0))
    {
        try
        {
            var message = consumer.Receive(10);

            if (message != null)
            {
                this.ProcessMessage(message);
                message.Acknowledge();
                session.Commit();
            }
        }
        catch (Exception exc)
        {
            session.Rollback();
        }
    }

    // dispose consumer, session and connection
}

So, the idea is to have N threads which are doing the same things in
syncronous way. Each thread has it's own connection and session, so I can
commit each message individually. There also a contoller thread, that is
going to constantly check if every thread is working fine and restart the
thread if anything goes wrong.

What I am concerned about is how many underlying connections to the broker
will be made? Is it the same as a number of threads? Or they will share the
same underlying transport channel? Can I create one connection and share it
between threads while creating multiple sessions, so I still will be able to
acknowledge messages individually?

Is there better solution that meets my requirements? Or how can I optimize
performance of the described solution? Maybe I should play with prefetch
limit or turn off alwaysSessionAsync flag?

--
View this message in context: http://activemq.2283324.n4.nabble.com/Emailing-sender-advice-required-tp3882570p3882570.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message