activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtsafas <gtsa...@rblt.com>
Subject c# NMS message not writing to file
Date Wed, 18 Nov 2009 22:20:40 GMT

I am not understanding why this isn't writing to file

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Apache.NMS.ActiveMQ;
using Apache.NMS;
using Apache.NMS.Util;
using System.Threading;

namespace WindowsAuthenticator
{
    class Authenticator
    {
        protected static ITextMessage message = null;
        protected static string message2 = null;

        static void Main(string[] args)
        {

            Console.WriteLine("Enter Server");
            string server = Console.ReadLine();
            Console.WriteLine("Enter Port");
            string port = Console.ReadLine();
            Console.WriteLine("Q or T IE: queue://gt.test or
topic://gt.test");
            string qort = Console.ReadLine();

            Authenticator authen = new Authenticator(server, port, qort);

        }

        Authenticator(string uri, string port, string qt)
        {
            try
            {
                Uri connecturi = new Uri("tcp://" + uri + ":" + port +
"?wireFormat=openwire");
                Apache.NMS.ActiveMQ.ConnectionFactory factory = new
ConnectionFactory(connecturi);
                IConnection connection = factory.CreateConnection();
                ISession session = connection.CreateSession();

                IDestination destination =
SessionUtil.GetDestination(session, qt);
                Console.WriteLine("Using destination: " + destination);

                IMessageConsumer consumer =
session.CreateConsumer(destination);
                connection.Start();
                consumer.Listener += new MessageListener(OnMessage);

                Thread.Sleep(100000);
            }

            catch (Apache.NMS.NMSConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }

        protected static void OnMessage(IMessage receivedMsg)
        {
          
            string filename =
"C:\\"+DateTime.Now.Year+DateTime.Now.Month+"_AMQSESSION.log";
            StreamWriter writeFile = new StreamWriter(filename, true);
            
            message = receivedMsg as ITextMessage;
            Console.WriteLine(message.Text);
            writeFile.Write(message.Text);
        }
    }
}


-- 
View this message in context: http://old.nabble.com/c--NMS-message-not-writing-to-file-tp26416818p26416818.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message