dmar
05-02-2007, 02:06 PM
I have downloaded Spring.Messaging.Nms (Spring.Messaging.Nms-20070320-1632.zip) and am attempting to use it for messaging between a .NET Windows Forms app and a Java app. I am totally new to JMS and messaging concepts...so I apologize for what are probably newbie questions that I am posting.
I have been successful at sending a message to a topic using NmsTemplate. However, I am not able to set up a listener. I am trying to piece together the code using the ListenerTests.cs contents I found under Spring.Messaging.Nms.Integration.Tests. The relevant code from my form is posted below. Using jconsole, I can see that my listener form makes a connection to ActiveMQ, but when I send messages to my test topic, the listener is not picking them up -- the OnMessage event is not even firing.
One other thing -- the connections that result from me sending messages with NmsTemplate are not being closed - even after I close my sending application. I can see that in jconsole.
I appreciate any thoughts/sugggestions. Also would like to know if there are more complete samples/documentation somewhere. I'm very new to this, and not finding much to go on so far.
Thanks in adavance. Code snippet is below.
private void btnListen_Click(object sender, EventArgs e)
{
txtMessages.AppendText("Setting up Listener...\r\n");
EstablishListenerContainer();
btnListen.Enabled = false;
}
private void EstablishListenerContainer()
{
string serverUrl = "tcp://localhost:61616";
IConnectionFactory factory = new ConnectionFactory(serverUrl);
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer();
container.ConnectionFactory = factory;
container.DestinationName = "TEST.Test1";
container.ConcurrentConsumers = 10;
container.MessageListener = new SimpleListener();
txtMessages.AppendText("Listening to messages...\r\n");
container.AfterPropertiesSet();
//Thread.Sleep(5000);
}
}
internal class SimpleListener : IMessageListener
{
public void OnMessage(IMessage message)
{
String threadId = "[" + Thread.CurrentThread.Name + "]";
ITextMessage tm = message as ITextMessage;
if (tm != null)
{
Console.WriteLine(threadId + ": Received message = " + tm.Text);
}
//Thread.Sleep(100);
}
}
I have been successful at sending a message to a topic using NmsTemplate. However, I am not able to set up a listener. I am trying to piece together the code using the ListenerTests.cs contents I found under Spring.Messaging.Nms.Integration.Tests. The relevant code from my form is posted below. Using jconsole, I can see that my listener form makes a connection to ActiveMQ, but when I send messages to my test topic, the listener is not picking them up -- the OnMessage event is not even firing.
One other thing -- the connections that result from me sending messages with NmsTemplate are not being closed - even after I close my sending application. I can see that in jconsole.
I appreciate any thoughts/sugggestions. Also would like to know if there are more complete samples/documentation somewhere. I'm very new to this, and not finding much to go on so far.
Thanks in adavance. Code snippet is below.
private void btnListen_Click(object sender, EventArgs e)
{
txtMessages.AppendText("Setting up Listener...\r\n");
EstablishListenerContainer();
btnListen.Enabled = false;
}
private void EstablishListenerContainer()
{
string serverUrl = "tcp://localhost:61616";
IConnectionFactory factory = new ConnectionFactory(serverUrl);
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer();
container.ConnectionFactory = factory;
container.DestinationName = "TEST.Test1";
container.ConcurrentConsumers = 10;
container.MessageListener = new SimpleListener();
txtMessages.AppendText("Listening to messages...\r\n");
container.AfterPropertiesSet();
//Thread.Sleep(5000);
}
}
internal class SimpleListener : IMessageListener
{
public void OnMessage(IMessage message)
{
String threadId = "[" + Thread.CurrentThread.Name + "]";
ITextMessage tm = message as ITextMessage;
if (tm != null)
{
Console.WriteLine(threadId + ": Received message = " + tm.Text);
}
//Thread.Sleep(100);
}
}