Return-path: <[email protected]>
Received: from [192.168.236.139] (helo=joe.nabble.com)
by joe.nabble.com with esmtp (Exim 4.72)
(envelope-from <[email protected]>)
id 1TwuGS-0000Ah-HO
for [email protected]; Sun, 20 Jan 2013 04:44:44 -0800
Date: Sun, 20 Jan 2013 04:44:44 -0800 (PST)
From: wonderland <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
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: [email protected]
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);
}
}
}