Below is my code to call MessageListener, it fails to call OnMessage. Thread
is getting aborted. Native approach without listener works fine. Please
suggest if iam missing anything.
using System;
using System.Configuration;
using System.Reflection;
using Apache.NMS;
using log4net;
using Apache.NMS.ActiveMQ;
using Apache.NMS.Policies;
using Spring.Messaging.Nms.Listener;
namespace BIS.JX.QueueManager.QueueManager
{
public class QueueConnector
{
private static readonly ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly string _uri;
private readonly string _destination;
private readonly string _uriusername;
private readonly string _uripassword;
public QueueConnector()
{
_uri = ConfigurationManager.AppSettings["Uri"];
_uriusername = ConfigurationManager.AppSettings["Uriusername"];
_uripassword = ConfigurationManager.AppSettings["Uripassword"];
_destination = ConfigurationManager.AppSettings["Queuename"];
}
public void ProcessMessage()
{
try
{
ConnectionFactory connectionFactory = new
ConnectionFactory(_uri);
RedeliveryPolicy redeliverypolicy = new RedeliveryPolicy {
MaximumRedeliveries = 0 };
connectionFactory.RedeliveryPolicy = redeliverypolicy;
connectionFactory.UserName = _uriusername;
connectionFactory.Password = _uripassword;
using (SimpleMessageListenerContainer queuelistener = new
SimpleMessageListenerContainer())
{
queuelistener.ConnectionFactory = connectionFactory;
queuelistener.DestinationName = _destination;
queuelistener.ConcurrentConsumers = 1;
queuelistener.SessionAcknowledgeMode =
AcknowledgementMode.Transactional;
queuelistener.ErrorHandler = new JhaErrorHandler();
queuelistener.ExceptionListener = new
JhaExceptionListener();
queuelistener.MessageListener = new
JhaMessageListener();
queuelistener.AfterPropertiesSet();
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
}
public class JhaMessageListener : IMessageListener
{
private static readonly ILog Log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public void OnMessage(IMessage message)
{
try
{
Log.Info(message.NMSMessageId + DateTime.Now);
ITextMessage textmessage = message as ITextMessage;
if (textmessage != null) Log.Info(textmessage.Text);
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
}
}
--
View this message in context:
http://activemq.2283324.n4.nabble.com/Spring-Net-MessageListener-onMessage-does-not-get-called-tp4723954.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.