Hi,
Looks like you are using Spring.NET, so the Spring.NET forum for messaging
would be a better place to ask the question.
http://forum.springframework.net/forumdisplay.php?f=18
(Perhaps the issue is putting the listener container inside the using block,
thus asking it to shutdown, is the issue)
Cheers,
Mark
(Spring.NET project lead)
> -----Original Message-----
> From: ajsri77 [mailto:ajsri77@gmail.com]
> Sent: Friday, November 21, 2008 9:11 AM
> To: dev@activemq.apache.org
> Subject: Writing a Listener Windows Service .NET for Active MQ
>
>
> hi all.,
>
> I'm trying to write a Windows Service in C#, which can create a
> consumer and
> listen for the specified Active Message Queue.
>
> I'm using the SimpleMessageListenerContainer to create the connection
> to the
> activemq.
>
> All i'm getting is the Listener Class (Consumer) is getting created
> successfully and displayed in the Topics of my activeMQ admin web
> console.
>
> But the OnMessage function is fired when i receive any message. I dont
> know
> where i'm doing wrong.
>
> Can you please help me sort out this problem.
>
> the coding is as below.
>
> private void InitListener()
> {
> try
> {
> ConnectionFactory connectionFactory = new
> ConnectionFactory(URI);
>
> using (SimpleMessageListenerContainer listenerContainer
> =
> new SimpleMessageListenerContainer())
> {
> listenerContainer.ConnectionFactory =
> connectionFactory;
> listenerContainer.DestinationName = DESTINATION;
> listenerContainer.MessageListener = new Listener();
> listenerContainer.AfterPropertiesSet();
> DAL.WriteToLog("Listener Properties set at " +
> DateTime.Now.ToString() + Environment.NewLine);
> }
> }
> catch (Exception ex)
> {
> DAL.WriteToLog("Error occured at " +
> DateTime.Now.ToString()
> + Environment.NewLine);
> DAL.WriteToLog(ex.Message + " " +
> DateTime.Now.ToString() +
> Environment.NewLine);
> }
> }
>
> This function i'm calling in OnStartup Method of the Service.
>
> And my Listener class is as follows.
>
> class Listener : IMessageListener
> {
> public Listener()
> {
> DAL.WriteToLog("Listener created at " +
> DateTime.Now.ToString()
> + Environment.NewLine);
> }
>
> #region IMessageListener Members
>
> public void OnMessage(Apache.NMS.IMessage message)
> {
> DAL.WriteToLog("Message Received " +
> DateTime.Now.ToString() +
> Environment.NewLine);
>
> LogMessage mq;
>
> IObjectMessage objMessage = message as IObjectMessage;
>
> // Deserialize the Log Message Object
>
> MemoryStream myStream = (MemoryStream)objMessage.Body;
>
> BinaryFormatter formatter = new BinaryFormatter();
>
> myStream.Position = 0;
>
> mq = (LogMessage)formatter.Deserialize(myStream);
>
> DAL.WriteToLog("Message Deserialized at " +
> DateTime.Now.ToString() + Environment.NewLine);
>
> myStream.Close();
>
> DAL.WriteToLog("Inserting Log : " + mq.ErrorLevel + " - " +
> mq.ErrorDate + Environment.NewLine);
>
> DAL.Insert(mq);
>
> DAL.WriteToLog("Done" + Environment.NewLine);
> }
>
> #endregion
> }
>
> Can anyone point out me where and what i'm doing wrong. it is driving
> me
> crazy. Because the same code if i put in a console application is
> working
> very well... i donna what to do?
>
> Thanks in advance for helping.
> --
> View this message in context: http://www.nabble.com/Writing-a-Listener-
> Windows-Service-.NET-for-Active-MQ-tp20621820p20621820.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
|