Hello All,
I am newbie to use ActiveMQ MOM in my asp.net (C#) project. I am in trouble
with the following question 2 days, so I open this thread here to find you
to figure it out. Thanks in advance :)
My Question:
I have topic publisher and multiple topic subscribers. If I write the
consumer program in console application, it works really fantastic. But,
after recoded in asp.net application, it does not work. (I mean, when I sent
a topic by publisher, no responses on subscriber side.)
Here's my entire code.
//This is publisher
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
IConnectionFactory connFactory = new
ConnectionFactory("tcp://localhost:61616");
using (IConnection connection =
connFactory.CreateConnection())
{
using (ISession session = connection.CreateSession())
{
IMessageProducer producer = session.CreateProducer(
new ActiveMQTopic("Distribution test"));
ITextMessage msg = producer.CreateTextMessage();
msg.Text = this.txtName.Text;
producer.Send(msg);
}
}
}
catch (Exception ex)
{
//TODO:
}
}
===================================================================
//This is consumer
public delegate void ReceivedMessageDelegate(string message);
public partial class _Default : System.Web.UI.Page
{
public event ReceivedMessageDelegate OnMessageReceived;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
IConnectionFactory connFactory = new
ConnectionFactory("tcp://localhost:61616");
using (IConnection connection =
connFactory.CreateConnection())
{
connection.ClientId = "testing listener";
connection.Start();
using (ISession session =
connection.CreateSession())
{
IMessageConsumer consumer =
session.CreateDurableConsumer(new ActiveMQTopic("Distribution test"),
"testing listener", null, false);
consumer.Listener += (message =>
{
var msg = message as ITextMessage;
if (msg == null) throw new
InvalidCastException();
if(OnMessageReceived != null)
{
this.OnMessageReceived(msg.Text);
}
});
}
}
}
catch (Exception ex)
{ //TODO: }
}
}
}
}
Cup,
--
View this message in context:
http://activemq.2283324.n4.nabble.com/how-to-achieve-OnMessage-event-in-asp-net-app-to-automatically-fetch-receives-tp4671879.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.