Messaging with .NET and ActiveMQ
You’ve probably heard of Java Message Service (JMS). It’s a standard Java API for creating, sending, receiving and reading messages. ActiveMQ, an Apache project, is an open source message broker that supports JMS 1.1. In addition to supporting JMS, it supports other protocols that allow clients to be written in a variety of languages. Look at this page for more information. Sounds good, doesn’t it? Let’s try it out using .NET, C# and Visual Studio 2005.
Download and install the JDK
ActiveMQ is written in Java, so you’ll need a Java Runtime Environment (JRE) to be able to run it. The Java Development Kit (JDK) comes with extra utilities that you’ll find useful later on. I used the Java Development Kit SE 6 update 1, which you can find here.
Download and install ActiveMQ
Get the latest release of ActiveMQ from the downloads section. I used version 4.1.1. Once you have downloaded the zip file, extract the contents to a suitable folder. To test the installation, open a command prompt and use the cd command to set the current folder to be the installation folder (in which you extracted the ActiveMQ files.) Then type the following command:
bin\activemq
All being well, you should see a number of lines of information – the last of which should be something like:
INFO ActiveMQ JMS Message Broker (localhost, ID:your-PC-51222-1140729837569-0:0) has started
The installation notes on the ActiveMQ site point out that there are working directories that get created relative to the current working folder. This means that for ActiveMQ to work correctly, you must start it from the installation folder. To double check, start a new command prompt and type the following command:
netstat -an|find "61616"
The response should be something like the following:
TCP 0.0.0.0:61616 0.0.0.0:0 LISTENING
When you want to stop ActiveMQ, enter <CTRL+C>. For now leave it running.
Download Spring.Messaging.NMS
NMS is the .NET Messaging API. Spring .NET has a messaging library built on NMS. It’s under development, but you can get it here. I used version 20070320-1632. Extract the files from the zip file to somewhere sensible.
The Listener
Create a new console application. I called mine ListenerConsole. You need to add 4 references:
- Spring.Core
- ActiveMQ
- NMS
- Spring.Messaging.NMS
These dlls can all be found in the bin\net\2.0\debug folder of Spring.Messaging.NMS. Here’s the code for the Program class in the listener console:
using System; using System.Collections.Generic; using System.Text; using System.Threading; using ActiveMQ; using Spring.Messaging.Nms; using Spring.Messaging.Nms.Listener; namespace ListenerConsole { class Program { private const string URI = "tcp://localhost:61616"; private const string DESTINATION = "test.queue"; static void Main(string[] args) { try { ConnectionFactory connectionFactory = new ConnectionFactory(URI); using (SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer()) { listenerContainer.ConnectionFactory = connectionFactory; listenerContainer.DestinationName = DESTINATION; listenerContainer.MessageListener = new Listener(); listenerContainer.AfterPropertiesSet(); Console.WriteLine("Listener started."); Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine("Press <ENTER> to exit."); Console.Read(); } } } }
The interesting part of the code is the creation and set up of the SimpleMessageListenerContainer. ConnectionFactory is from the ActiveMQ namespace and implements the IConnectionFactory interface defined in NMS. The Uri of the message broker is passed to the constructor. SimpleMessageListenerContainer is part of Spring.Messaging.NMS (in the Listener namespace.) Note that SimpleMessageListenerContainer implements IDisposable. The missing part of this puzzle is the Listener class. Create a new class in the project, call it Listener and insert the following code:
using System; using Spring.Messaging.Nms;
using NMS;
namespace ListenerConsole { class Listener : IMessageListener { public Listener() { Console.WriteLine("Listener created.rn"); }
#region IMessageListener Members public void OnMessage(NMS.IMessage message) { ITextMessage textMessage = message as ITextMessage; Console.WriteLine(textMessage.Text); } #endregion } }
IMessageListener is defined in Spring.Messaging.NMS. Build and run the console.
Start jconsole
The JDK comes with a utility called jconsole. You’ll find it in the bin folder. So, launch a command prompt and cd to the bin folder of the JDK. Then type:
jconsole
This will launch the Java Monitoring & Management Console. To connect to the running instance of ActiveMQ, select Remote Process as shown below:
Enter the following in the Remote Process text box: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi It’s easier to work out what to enter here than you might think. If you go back to the command prompt in which you launched ActiveMQ and look towards the top of the output, you’ll find a line that reads:
INFO ManagementContext - JMX consoles can connect to service:jmx:ri:///jndi/rmi://localhost:1099/jmxrmi
Click Connect. Select the MBeans tab. Navigate to org.apache.activemq->localhost->Queue->test.queue->Operations->sendTextMessage as shown below:
In the text box next to the sendTextMessage button, enter some text. I entered (somewhat unimaginatively) “Hello”. Now, click sendTextMessage. In the .NET console window for the listener, you should see the text you entered. So what just happened? jconsole put a message on the queue using JMS and our console application read it using NMS. Why not send yourself a couple more messages?
The Sender
To complete our foray into messaging with ActiveMQ, let’s create an application that can send messages. Create another Console Application. I called mine SenderConsole. You may have started to notice a pattern in my naming conventions. Add the same references you added to the listener console. Here’s the code for the sender console:
using System; using System.Collections.Generic; using System.Text; using ActiveMQ; using Spring.Messaging.Nms; namespace SenderConsole { class Program { private const string URI = "tcp://localhost:61616"; private const string DESTINATION = "test.queue"; static void Main(string[] args) { ConnectionFactory connectionFactory = new ConnectionFactory(URI); NmsTemplate template = new NmsTemplate(connectionFactory); template.ConvertAndSend(DESTINATION, "Hello from the sender."); } } }
Run the sender console and you should find that the message “Hello from the sender.” has appeared in the console window of the listener.
Conclusion
Sending and receiving messages using ActiveMQ is enabled by NMS and Spring.Messaging.NMS. We’ve seen how to create a simple set up using .NET that can be extended for real-world needs. JMS is no longer the preserve of Java developers.
Excellent! In this age of blogs galore, where nothing is checked, I was thrilled to see that this example actually runs! I cannot find the words to express my appreciation.
Cheers!
e
erik scheirer
June 6, 2007 at 1:55 am
Super job! Everything worked perfect! Thanks!
drain
June 15, 2007 at 10:02 pm
The example is accurate.
#1. Console.WriteLine(“Press any key to exit.”);
The above line will not continue by pressing “any key”. The client needs to supply a carriage return.
#2. Console.WriteLine(“Press any key to exit.”);
After supplying a carriage return to the above prompt, the client hangs. The client is not coded properly as to avoid the hanging, the following step must take place to properly release the client from the queue/topic…
listenerContainer.Shutdown();
connection.Stop();
connection.Dispose();
In order to accomplish this, the client must be coded in a different manner where listener container and connection are not local variables.
evil drain
June 19, 2007 at 4:24 pm
Thanks drain. I’ve updated the code sample accordingly. SimpleMessageListenerContainer implements IDisposable, so I’ve wrapped it in a using block (I used Reflector to ensure the Dispose method calls Shutdown.)
remark
June 19, 2007 at 9:42 pm
I tried as written above, the code was built successfully, but a run time error indicates that it can not load the type “ConnectionFactory”, I tried other types in ActiveMQ, none of them can be initialized. I double checked the reference, the ActiveMQ.dll was there, could you give me clue?
Tao
August 6, 2007 at 7:22 pm
This was very useful, thanks for the example!
derek
August 9, 2007 at 12:26 am
Hi,
I tried running the samples. The Listener works perfect with jconsole sending messages. When I tried to execute the Sender, I get a java.io.IOException: The volume for a file has been externally altered so that the opened file is no longer valid” ACtiveMQ.BrokerException at the template.ConvertAndSend() line.
Any thoughts?
Thanks, Suma.
Suma
August 16, 2007 at 5:51 pm
Suma,
I’ve not seen this problem. Might be worth logging the issue on the ActiveMq User Forum.
remark
August 20, 2007 at 9:46 pm
Great article! I followed the mentioned steps and everything worked perfectly as expected.
Quick question: is there a way (or an article) to get similar notifications on a web (.aspx) page rather than console window?
Thanks in advance.
dash
November 14, 2007 at 12:53 am
Dash,
Thanks for the feedback. I haven’t tried to use a web page instead of a console, but there’s a couple of things you could try. The first is the ActiveMQ WebConsole. It works with ActiveMQ 5 and above. The other thing to try would be Ajax – ActiveMQ exposes a RESTful interface that you could call from client-side JavaScript. What you want to avoid is having page-related code server side that is waiting around for messages. Of course, having server-side code listening for messages that the pages interact with differently (e.g. Ajax again) would work. Hope this helps.
remark
November 22, 2007 at 8:54 am
LS,
I tried compiling the example on both VS2005 and VS2008 but keep getting the errormessage : The type or namespace name ‘Listener’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Herman\Local Settings\Application Data\Temporary Projects\ListenerConsole\Program.cs 27 61 ListenerConsole
I am using activemq 5.0 and the SpringNMS version mentioned in the article.
I am not experienced in c# programming. Did anyone experience the same or knows a solution for this ?
Herman
Herman
February 27, 2008 at 3:29 pm
To compile the Program class, you need to have the Listener class in the same namespace. So, check to see that you have added a Listener class to the ListenerConsole project.
remark
February 27, 2008 at 10:51 pm
Thanks a lot. Working now as expected.
Great article.
Herman
Herman
February 27, 2008 at 11:17 pm
Great example!
The sender program does not exit properly after sending the message.
isaac
March 28, 2008 at 3:16 am
isaac,
Thanks for the feedback. Do you have any more information about how it’s not exitting properly?
remark
March 28, 2008 at 11:33 am
This is a fantastic example! Very useful.
I have the same problem as Isaac. The sender program doesn’t terminate after the message is sent. Cntl C is required to stop the Sender program.
Mark
April 2, 2008 at 4:15 am
I don’t know how long ago this snippet-example was posted by you, but THANKS regardless. I have one question though. After compiling, ran, and performed some testing with .NET and Java environment altogether (ie sending-receiving from different platform), I noticed that in your example, ActiveMQ-NMS doesn’t provide “Topic” as a destination (in comparison with ActiveMQ-JMS). It only provides “Queue”. Is this true?
Gerald
April 11, 2008 at 7:55 am
Gerald,
ActiveMQ topics can be used via NMS. I posted an article about publish-subscribe using NMS and ActiveMQ that shows topics being used. Click here to read the full article.
remark
April 11, 2008 at 10:04 am
[…] ActiveMQ via .NET Messaging Overview […]
ActiveMQ and NMS (via Spring.NET) Resources « HSI Developer Blog
April 15, 2008 at 8:09 pm
This Documentation is Excellent. gives me good knowledge.
I tried and everything is working even i m sending and receiving message. but when i tried to connect through jconsole i want be able to se that MBeans settings with this “service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi” ad connect. could u please tell this portion… would be help me else all is fine. the way explain is strong very good written ideas also.
thanks,
help the developer like me
Kpatel
June 3, 2008 at 12:05 am
I implemented the examle, and am having one issue I would like to get some feedback on.
Here is how to reproduce
Start ActiveMQ
Start the C# Listener
Shutdown ActiveMQ
Startup ActiveMQ
The C# listner does not re-attach the connection. Any suggestions on how to approach this?
Marty
June 13, 2008 at 1:06 am
KPatel, I am using ActiveMQ 5.1.0 on Windows XP (JDK 1.6.0r05). This version of ActiveMQ doesn’t appear to launch a management interface as per the article (or perhaps it’s because I don’t have J2EE installed). In any case, when I run ActiveMQ you can see that there is no message like “INFO ManagementContext – JMX consoles, etc.”. However if the ActiveMQ instance is running locally, you can connect to it as a Local Process using JCconsole. You should see a line saying “C:\Program Files\activemq…/bin/run.jar” or equivalent in the Local Process panel in the JConsole ‘New connection’ window. Simply select this and click ‘Connect’ instead.
Ben
July 9, 2008 at 2:03 am
Marty, I ran into the same issue as you.
The feature you are looking for is called failover but unfortunately it’s not supported in the .net version of the API and an enhancement request has been logged against it for quite some time now.
https://issues.apache.org/activemq/browse/AMQNET-26
The solution I will attempt to write will basically use retries with exponential backoff to reconnect on network and broker errors. This is the same approach that JMS is using.
Alex
July 17, 2008 at 1:34 am
Hi Ben
In ActiveMQ 5.1.0 management is turned off by default in configuration file confi/activemq.xml in managementContext node. Turn it on by setting attribute “createConnector=true” and resstart activemq. Hope u will get the required message.
Regards
Danish
Danish Ahmed
July 24, 2008 at 2:01 pm
Hi, I am having a problem running this example, the listener is not receiving all the messages, am I missing some kind of configuration?
thanks for your help
David Kepes
August 5, 2008 at 1:20 am
Hello everybody,
this is a very nice introduction in the activeMQ.
i’ve tested it with the Apache 5.1.0 version and it works 🙂
Thanks in Advance for this information 🙂
best regards from germany
Jan Bludau
Jan Bludau
August 5, 2008 at 3:13 pm
Thanks for the code.
Any samples of how to set the expiration (TTL) of a message? NMSExpiration doesn’t seem to work for me.
I’ve tried:
this.producer.Send(textMessage, false, 1, new TimeSpan(10000000));
and
TimeSpan mytime = new TimeSpan(0,0,10);
textMessage.NMSExpiration= mytime;
this.producer.Send(textMessage);
mark
August 25, 2008 at 8:02 pm
Thanks for the code. However I tried compiling the example on and VS2008 but keep getting the errormessage :
‘ListenerConsole.Listener’ does not implement interface member ‘Spring.Messaging.Listener.IMessageListener.OnMessage(System.Messaging.Message)’ C:\Users\feno\Documents\Visual Studio 2008\Projects\NMS\NMS\Listener.cs
I am using activemq 5.1.0 and the SpringNMS 1.2.0 M1.
I am not experienced in C# programming.
Did anyone experience the same or knows a solution for this ?
feno
September 16, 2008 at 11:13 pm
in found the solution in the Spring.Net reference :
for the class listerner, just add :
using Spring.Messaging.Nms.Core;
using Apache.NMS;
that all !
for info, in main program, i have
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Spring.Messaging.Nms;
using Spring.Messaging.Nms.Listener;
feno
September 17, 2008 at 8:56 am
Excellent
Pradeep Nair
September 25, 2008 at 11:34 am
Thank for the code.
I have already test the code and its working. But my problem is I want to list all the queues in active MQ.
JuliusR
October 13, 2008 at 10:38 am
hi,
this code is pretty useful. But i want to have the ListenerConsole
as a windows service with auto startup. Can you please help me, how to do it?
Thanks in advance
Prasad
November 14, 2008 at 2:52 pm
Hi there,
I have listeners which are spawn by a windows service (consumers are defined in xml config and spawn by spring framework).
if I want to update the windows service with new exe I have to stop the service, update, and then start the service again.
To do so I need the existing listeners to finish processing the messages that are already in process but not listen to any new messages (like draining in IIS).
Is it possible to turn of listeners? If so, how can it be done?
Many thanks
N
NZorn
November 24, 2008 at 12:37 pm
Great stuff!
I’ve added a link to the Articles section of the ActiveMQ website…
http://cwiki.apache.org/ACTIVEMQ/articles.html
James Strachan
December 16, 2008 at 11:45 am
Thank you, very useful article. Having trouble with listener, it doesn’t receive messages.
A first chance exception of type ‘Spring.Messaging.Nms.Listener.MessageRejectedWhileStoppingException’ occurred in Spring.Messaging.Nms.dll
A first chance exception of type ‘System.IO.EndOfStreamException’ occurred in mscorlib.dll
Still looking for solution.
Gleb
January 5, 2009 at 3:11 pm
sorry, my fault. Moved occasionally Console.Read from using block.
Thank you very much one more time.
Gleb
January 5, 2009 at 4:08 pm
[…] are some examples using the Spring framework (same as […]
Getting started with ActiveMQ « Ben Biddington
February 4, 2009 at 4:24 pm
Hello,
The sender does not work for me! I receive the following error.
Do I have to create a config file ? I’m new to Spring.
Thank you very much for your help.
at Apache.NMS.ActiveMQ.Transport.ResponseCorrelator.Request(Command command, TimeSpan timeout)
at Apache.NMS.ActiveMQ.Connection.SyncRequest(Command command, TimeSpan requestTimeout)
at Apache.NMS.ActiveMQ.Connection.SyncRequest(Command command)
at Apache.NMS.ActiveMQ.Connection.CheckConnected()
at Apache.NMS.ActiveMQ.Connection.SyncRequest(Command command, TimeSpan requestTimeout)
at Apache.NMS.ActiveMQ.Connection.CreateSession(AcknowledgementMode sessionAcknowledgementMode)
at Spring.Messaging.Nms.Support.NmsAccessor.CreateSession(IConnection con)
at Spring.Messaging.Nms.Core.NmsTemplate.Execute(ISessionCallback action, Boolean startConnection)
at Spring.Messaging.Nms.Core.NmsTemplate.Send(String destinationName, IMessageCreator messageCreator)
at Spring.Messaging.Nms.Core.NmsTemplate.ConvertAndSend(String destinationName, Object message)
Rod
February 21, 2009 at 7:16 pm
Sorry, this was the stacktrace, the excpetion message is :
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at Apache.NMS.ActiveMQ.OpenWire.StringPackageSplitter.StringPackageSplitterEnumerator.System.Collections.IEnumerator.get_Current()
at Apache.NMS.ActiveMQ.OpenWire.OpenWireBinaryWriter.Write(String text)
at Apache.NMS.ActiveMQ.OpenWire.BaseDataStreamMarshaller.LooseMarshalString(String value, BinaryWriter dataOut)
at Apache.NMS.ActiveMQ.OpenWire.V2.ConnectionIdMarshaller.LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut)
at Apache.NMS.ActiveMQ.OpenWire.OpenWireFormat.LooseMarshalNestedObject(DataStructure o, BinaryWriter dataOut)
at Apache.NMS.ActiveMQ.OpenWire.BaseDataStreamMarshaller.LooseMarshalCachedObject(OpenWireFormat wireFormat, DataStructure o, BinaryWriter dataOut)
at Apache.NMS.ActiveMQ.OpenWire.V2.ConnectionInfoMarshaller.LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut)
at Apache.NMS.ActiveMQ.OpenWire.OpenWireFormat.Marshal(Object o, BinaryWriter ds)
at Apache.NMS.ActiveMQ.Transport.Tcp.TcpTransport.Oneway(Command command) : Transport connection error: Index and length must refer to a location within the string.
Parameter name: length
Rod
February 21, 2009 at 7:18 pm
Hi,
If anybody would know how to get the messages from the topic. By using the above example I easily got the queue mesages. But i donno how to retrieve the messages from the TOPIC, If anybody can guide me or give me some samples for the same. I would really apperciate and thankful to them.
Thanks and Cheers…
Karthikeyan Manickam.
Karthikeyan Manickam.
February 24, 2009 at 9:47 am
To Rod: Got same problem after getting newer 1.1.0.0 snapshot from svn, but fortunately I still have working older version. NMS 1.1 seems to be bit unstable through the time. Like ActiveMQ…
Anthavio Lenz
March 3, 2009 at 2:14 pm
With .Net and ActiveMQ, is there any possible way to send/receive messages via port with security protocol? I am looking the way for a long time. Thank you.
David
March 27, 2009 at 8:19 am
A while back I had built (on a XP box) a C# client using this example as a starter. When I ported that program to a Vista PC recently, it stopped working. The program was connecting via a forwarded port (127.0.0.1:61616) to a MQ running on a remote host.
Has anyone run into a similar issue on vista? I do suspect his to be an issue with vista and have tried changing security settings etc. but no luck so far.
Thanks.
Sam
April 26, 2009 at 6:17 am
Should have mentioned, the error is: “unable to connect…machine actively refused connection….{IPv6 of localhost}:61616
Sam
April 26, 2009 at 6:19 am
I have a stomp html page connected to ws://localhost:8001/activemq and subscribed to /topic/stock
right now when i run stock.start.bat, i can see messages in the stomp html page.
what i want to do is, i want to generate messages from c# win form application and want to see those messages in stomp html page.
i tried using “The Sender” part discussed above using “template.ConvertAndSend(DESTINATION, “Hello from the sender.”);” by setting destination as topic.stock but could not get message appear in html stomp page.
can any one has an idea how to do this ?
thanks,
viral
viral
April 28, 2009 at 7:49 pm
I have a stomp html page connected to ws://localhost:8001/activemq and subscribed to /topic/stock
right now when i run stock.start.bat, i can see messages in the stomp html page.
what i want to do is, i want to generate messages from c# win form application and want to see those messages in stomp html page.
i tried using “The Sender” part discussed above using “template.ConvertAndSend(DESTINATION, “Hello from the sender.”);” by setting destination as topic.stock but could not get message appear in html stomp page.
can any one has an idea how to do this ?
thanks,
viral
viral
April 28, 2009 at 7:50 pm
Thank you, very useful article.
But I am Having trouble with listener, it doesn’t receive messages.
I checked send queue is ok..
Can anyone help for me?
Thanks in advance..
robin
June 17, 2009 at 3:42 am
Sorry.. I solved it.. I didn’t change any program source… Thanks
robin
June 18, 2009 at 2:58 am
works very well…except that you need to get the ActiveMQ and NMS from Spring.NET-1.3.0-RC1\lib\Net\2.0 and change the it to …
using Apache.NMS.ActiveMQ;
using Spring.Messaging.Nms;
Kash
August 25, 2009 at 8:48 pm
Hi, first of all, thank you very much for this example it is really usefull.
I have to implement this in a Mobile application, and I am having lots of problems with the references, I replaced the cf references with the references not cf, but it throws an error on the System reference (apparently System.Uri has some differences in cf) I’ve tried to add a reference to System.dll from not cf Framework and, of course, it didn’t work.
I’m stacked and I can’t seem to move on. This happens with the main(). I’ll go on with the rest, but it won’t work unless I solve (or you help me sove) this issue.
Greatings.
Jose.
Jose
September 16, 2009 at 3:22 pm
I had to recompile all the libraries that I use, in order to use then with compact framework, but it’s working.
Thanks again for the example.
Greatings
Jose
Jose
September 17, 2009 at 9:32 pm
Jose could you help me? I am trying to rebuild the libraries in orer to be able to use ActiveMq on CF but I am able to build it only for .net 2.0/3.5 (I don’t understand why), how ever I found the Apache.Nms.dll for .net cf-2.0 and now I am trying to solve the System.Uri problem, but with no sucess. Can you tell me how you did it (adyc(_at_)email.cz)?
Andrei
November 26, 2009 at 9:58 am
My project requires me to connect to a Websphere JMS queue. I have not included the spring libraries yet (will do that in the morning). I have been successful connecting to a local WAS-CE queue, but all kinds of errors conneting to a full Websphere installation on a SuSe 9 box.
First question: Is it even possible to use this article for connecting to Websphere ?
Second: Any hints or URLs with more information ?
Thanks in Advance…
Jerry
December 11, 2009 at 5:04 am
Do you have any samples of doing a Send and Receive using NMSTemplates.
I was looking for examples where in my client would make a request and then call receive to get the response [not using an update stream]
Amjad K
January 19, 2010 at 7:45 pm
Do you have Apache.NMS.ActiveMQ.dll and Apache.NMS.dll compiled for compact framework.net.
I’m trying to rebuild alla but i have still problem…..
stefano
January 21, 2010 at 7:18 pm
Hi,
I already had a working AMQ, but with a Java listener. That setup works fine. If I use the same AMQ, but with a c# listener, it doesn’t receive any messages at all.
I used the listener and sender examples from above. When I launch the listener, I can see in the AMQ admin that I have a new consumer. When I send a message with the sender (or thru jconsole), I can see that a message is received and sent again. But the listener doesn’t even come into the OnMessage() method.
I am using the same host/port for the AMQ in both the listener and the sender, as well as the same destination string.
Any ideas what can be wrong?
Thanks in advance,
Mark
Mark
January 22, 2010 at 5:27 pm
I have the exact same problem, did u get this resolved?
Thanks,
Ricky
Ricky
March 5, 2010 at 8:07 pm
just got this working so not sure , but i think i had to create the “test” queue ( or was it already there? ) on http://localhost:8161/admin/queues.jsp
seems to fail silently with a non existand queue atleast with activemq 5.3 ( new to this so dont know if that is correct or not )
Morten
March 9, 2010 at 6:51 pm
If you have this problem, please make sure that you add an assembly reference to Spring.Data. That solved it for me.
phw
June 21, 2010 at 7:33 pm
Hi,
This one works fine but are there examples showing how to implement mulithreading using activeMQ.
Thanks in Advance,
Solomon
solomon
March 2, 2010 at 7:17 am
Hi, I tried to build a example as yours by using VB.NET. and I have some questions for you. Please kind help me if you’ve experienced these issues in C#.
1. The listener got the excepetions as the followings when retrieved a message from a queue and the event didn’t be raised.
‘System.ArgumentException’ occurred in Spring.Core.dll
‘Spring.Messaging.Nms.Listener.Adapter.ListenerExecutionFailedException’ occurred in Spring.Messaging.Nms.dll
2. I can make it to send a message to ActiveMQ, however I don’t know how to specify the message header. Any idea about how to do this?
Thanks in Advance for your kind help.
Jim
Jim
April 16, 2010 at 7:54 am
Thanks for the very helpful posts about using ActiveMQ with NMS and Spring.NET. I find that there are so many wonderful products from Apache, and they are sometimes just out of reach for .NET users. In this case both NMS and Spring.NET NMS support have really scored a home run. I created a quick POC, and I used Camel routes to follow some basic EIPs, given that Camel runs inside the broker – Load balancing for free!
Any thoughts or recommendations on best practices for message type definition?
@solomon: if you are trying to have many threads consume from a queue and assuming you only want each message to be consumed by one consumer, you would simply start another instance of your listener – ActiveMQ automatically distributes messages to only one consumer. If you want many listeners of the same type to receive the message (this is a much rarer case), you can use the multicast EIP defined in Camel.
Once again, thanks for the brilliant tutorials!
Chet
Chet
April 19, 2010 at 6:29 pm
Hi,
I get exception error when i’m running Sender
Cannot access a disposed object.
Object name: ‘System.Net.Sockets.NetworkStream’.
wee
June 29, 2010 at 4:10 am
[…] Home NMS Download ActiveMQ n .NET Request Response with NMS Publish n Subscribe with NMS Transactional Messaging with […]
Getting started with ActiveMQ « The Extremist Programmer
July 12, 2010 at 3:38 pm
This example works fine and I’m having success sending a text message from C# to ActiveMQ. In turn I’m receiving the message on a Java client.
Great!
Now I want to send an object and ultimately an array of objects. For now I have a simple “stock” object (name, symbol, high, low, volume).
….
Stock stock = new Stock();
stock.Name = “International Business Machines”;
stock.Symbol = “IBM”;
stock.high = 167.55m;
stock.low = 144.55m;
stock.volume = 12345;
IObjectMessage omsg = prod.CreateObjectMessage(stock);
prod.Send(omsg, MsgDeliveryMode.NonPersistent, MsgPriority.High, TimeSpan.MinValue);
….
The message is sent and I do recieve it on the java client, however the body is null. I am wondering if you or anyone have any suggestions.
Regards …
Bob Tierney
July 15, 2010 at 5:12 pm
Where do I find a reference to ActiveMQ dll?
I tried to look in Spring .Net 1.3 framework and also in Apache.NMS-1.3.0-bin but could not find it. Please let me know. Thanks
Nikhil
August 29, 2010 at 12:45 am
never mind found it,
It can be downloaded from here:http://mirrors.axint.net/apache/activemq/apache-nms/1.3.0/
Nikhil
August 29, 2010 at 12:52 am
no it cannot be downloaded from there. none of those downloads have an ActiveMQ.dll in them!
vince
December 21, 2010 at 7:36 pm
Is it possible to get in C# the list of all topics on the broker? Exactly what does DestinationSource in java
http://activemq.apache.org/how-can-i-get-a-list-of-the-topics-and-queues-in-a-broker.html
Roxy
September 3, 2010 at 9:57 am
I cannot find the ActiveMQ.dll nor can I find the NMS.dll. These DLL’s are not found in the bin\net\2.0\debug folder of Spring.NET. None of the Spring.NET versions have these. I really need some help here. I am missing something here. the “using ActiveMQ;” reference in the code will not resolve without the proper DLL. Please help.
vince
December 21, 2010 at 7:31 pm
Vince,
to overcome these problems add Apache.NMS.dll and Apache.NMS.ActiveMQ.dll which can be found at the folder lib\net\”your version”
Afterwards type in for the program class the using directives
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Spring.Messaging.Nms;
using Spring.Messaging.Nms.Listener;
and for the listener-class:
using Spring.Messaging.Nms.Core;
using Apache.NMS
and rename NMS.IMessage at the listener class to Apache.NMS.IMessage
This did it for me (used the most up-to-date ActiveMQ and Spring.NET)
Tyrex
February 10, 2011 at 1:07 pm
I cannot find activemq.dll and nms.dll in bin folder of the zip..
simmy
March 10, 2011 at 11:58 am
Hello, i try to run this code in my network, i run Listener in my win2008 ane sender in my win7, i try do this in the Sender:
private const string Uri = “tcp://192.168.4.29:61616”;
But its crash, how i do to communicate in my network?
Marcio Althmann
April 29, 2011 at 9:44 pm
Hello 🙂 i solve the problem in my last comment :).
But i have one more doubt.
I need the Listener send one message to sender, a response message, and the Sender execute one event when recieve the response.
Its possible?
Marcio Althmann
May 2, 2011 at 3:09 pm
i have an application that sends smses using AT commands in vb.net via a 3g modem.the application works fine but when i send bulk smses it fails. someone told me to use queues so that the modem is not overwhelmed.how can i use ActiveMQ queues to send messages to the 3g modem on a com port.
Ignatius
June 2, 2011 at 3:43 pm
Hi, I am novice to Messaging Q…. i tried this with C# working great. But I need this to work in VB.Net and I tried to do the above exact code with VB.Net…and unfortunately the console cant display what he had listened but then the ActiveMQ host had showed that it had dequeued the message.
Kindly help me where could possibly wrong. Thanks
Highly appreciate it.
Malini
Malini
December 12, 2012 at 11:40 am
Malini, I have exactly the same problem as you.
In a console application works perfect. But I have to move to a WinForms application.
Someone who can help?
Thanks,
Alejandro.
Alejandro
February 1, 2013 at 12:30 pm
Hi tried that “The Listener” part in Winform. Can any one help me.
Rashad
Rashad
March 30, 2013 at 2:56 am
Thanx for so excelent example. It worked like a charm.
Carlos Daniel
January 7, 2014 at 6:50 pm
Hi Brady,
i have created demo as you explained in this article, i have installed and started ActiveMQ when i’m sending queue from publisher application that time i getting this error:
“Channel was inactive for too long: tcp://localhost:8161/” can you help me to figure out what i’m missing.
And when i opened listener application, it showing me error as:
System.IO.Exception: The operation is not allowed on non-connected sockets.
Amit Parashar
June 22, 2015 at 3:42 pm
Hi Amit, try tcp://localhost:61616 as defined in the activemq/conf/activemq.xml. port 8161 is the web console.
Jeff Blumenthal
December 9, 2016 at 3:46 pm
Good article
Uthen Boonla
July 18, 2017 at 4:13 am
Problems with c# windows service using Spring.Messaging.Nms.Core;
using Apache.NMS;
using Spring.Messaging.Nms.Core;
class GenericMessageListener : IMessageListener
{
public void OnMessage(IMessage message)
{
try
{
ITextMessage textMessage = message as ITextMessage;
//Console.WriteLine(textMessage.Text);
}
catch
{
}
}
}
InstallUtil.exe error
Carlos Agusto Callupe Cervantes
March 16, 2021 at 3:30 am