activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chenyuancun <chenyuan...@hotmail.com>
Subject How can I use ActiveMQ in webapplicaiton/ASP.NET project
Date Sun, 20 Jan 2013 13:17:00 GMT

Return-path: <powerwonderland@126.com>
Received: from [192.168.236.139] (helo=joe.nabble.com)
	by joe.nabble.com with esmtp (Exim 4.72)
	(envelope-from <powerwonderland@126.com>)
	id 1TwuGS-0000Ah-HO
	for dev@activemq.apache.org; Sun, 20 Jan 2013 04:44:44 -0800
Date: Sun, 20 Jan 2013 04:44:44 -0800 (PST)
From: wonderland <powerwonderland@126.com>
To: dev@activemq.apache.org
Message-ID: <1358685884499-4661974.post@n4.nabble.com>
Subject: How can I use ActiveMQ in webapplicaiton/ASP.NET project
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-SA-Exim-Connect-IP: 192.168.236.139
X-SA-Exim-Mail-From: powerwonderland@126.com
X-SA-Exim-Scanned: No (on joe.nabble.com); SAEximRunCond expanded to false

Hi,everyone
   I have sucessful using using Apache.NMS and Apache.NMS.ActiveMQ in C#Form
project;but when I want to use ActiveMQ on webapplicaiton/ASP.NET projcet, I
meet a problem. 
   webapplicaiton receives message from ActiveMQ's producer,but it doesn't
work. When program run the ' ITextMessage msg = (ITextMessage)message;'
throws an exception; what's wrong? I couldn't find out the problem because I
am a green hand.
   I would appreciate any advice that you could give me.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Apache.NMS;
using Apache.NMS.ActiveMQ;

namespace WebActiveMQ
{
    public partial class _Default : Page
    {

        private MQ m_mq;
        private IMessageConsumer m_consumer;
        private delegate void ShowNoteMsgDelegate(string msg);


        private void consumer_listener(IMessage message)
        {
            string strMsg;

            try
            {
                Label.Text = "1";
                ITextMessage msg = (ITextMessage)message;
                Label.Text = "2";
                Label.Text = msg.Text;
                strMsg = msg.Text;
                ShowMessage(strMsg);

            }
            catch (System.Exception ex)
            {
                m_consumer.Close();
            }
        }

        private void ShowMessage(string msg)
        {
            string strText = "[" + DateTime.Now.ToString("yyyy/MM/dd
HH:mm:ss.fff") + "]:" + msg + "\r\n" + TextBox.Text;
            if (strText.Length > 10000)
            {
                TextBox.Text = strText.Substring(0, 10000);
            }
            else
            {
                TextBox.Text = strText;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                m_mq = new MQ();

                m_mq.uri = "tcp://127.0.0.1:61616/";
              

                m_mq.Start();
            }
            catch (System.Exception ex)
            {
            }

            m_consumer = m_mq.CreateConsumer(true, "Hello,World");

            m_consumer.Listener += new MessageListener(consumer_listener);

        }
    }


}
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message