views:

934

answers:

3

I'm hoping someone here will be able to aid me with my struggles with integration with ActiveMQ from C#. Here's what I did so far:

using Apache.NMS;
using Apache.NMS.ActiveMQ;
namespace JMSTest {
  class Program {
    static void Main(string[] args) {
      IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");
      IConnection connection = factory.CreateConnection();
      ISession session = connection.CreateSession();
    }
  }
}

Pretty basic stuff: just create a connection factory, then use it to create the connection and at the end create a session. Now when I execute this code this is the exception that's being thrown:

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

Does anyone has any idea what's going on? I'm using Apache ActiveMQ version 5.2.0 (fresh download from their web site).

+4  A: 

I tried the exact same thing you have here and it seemed to work. Someone on the intraweb responded to your request on Nabble that there was a bug (where?) that was fixed. Maybe download the latest version of Apache.NMS/Apache.NMS.ActiveMQ and try again.

Apache.NMS comes with Spring.NET - that's probably the best and easiest way to get Apache.NMS.

Andy White
Thanks for the insight, but as stated in the question's title I'd like to use it without Spring.NET. It seems an overkill to use a framework that's over 25MB in size just to send and receive messages from/to a message queue.Anyways, I'll try it out with the version of libs that comes with spring.
Matthias Hryniszak
Cool, I'm glad that worked. I should have been more clear that I meant you could just grab Apache.NMS from Spring.NET w/out the rest of it. I've had similar problems with downloading and builidng the activemq-dotnet stuff from apache. Spring.NET seems to have gotten it right.
Andy White
A: 

Well, the problem is solved. It took a while but with the help of the post that Andy White sent I was able to get it up and running just the way I wanted.

The problem was of course that those libraries currently available at http://svn.apache.org/viewvc/activemq/activemq-dotnet/ are simply broken and don't work at all.

Thank you Andy!

Matthias Hryniszak
FYI: you don't have to use the whole spring framework to use ActiveMQ connectivity. It just so happens that Spring.NET ships with a compiled version of those libraries.
Matthias Hryniszak
Hm, what's wrong with the binaries from Apache? I used the copies from the tags/1.0.0/deploy/net-3.5/ path in their SVN (see link above), and they work just fine for me.
markus
A: 

Just to respond to the comment "It seems an overkill to use a framework that's over 25MB in size just to send and receive messages from/to a message queue."

I certainly agree and it is really a packaging issue, we include compiled binaries for .NET 1.1 through 3.0 (debug and release builds with .pdbs) reference docs, sample apps, and so on. If you look at the size the .dlls you need to create an ActiveMQ NMS based Spring.NET app it is

Common.Logging 28KB, Spring.Aop 152KB, Spring.Core 744KB, Spring.Data 340KB, and Spring.Messaging.Nns 104KB for a total of ~1.4MB.

Mark

Mark Pollack
Well,... It's certainly better but still the amount of dependencies just to access AtiveMQ is an overkill. For example if I'm using some other DI framework (Ninject being my personal preference at this point) including Spring.Aop and Spring.Core smells a bit.
Matthias Hryniszak
I understand it's the design decision to put everything under the Spring umbrella. I like to keep close things that come together. If Spring.Data or Spring.Aop is close to Spring.Messaging.Nns is a matter of taste - it's certainly not the least surprising option ever.
Matthias Hryniszak
An option that I'd like best would be to have something released by Apache ActiveMQ guys like Apache.ActiveMQ.Client.dll which would provide me with everything I need to send/receive messages from this source and would be below 100k (which is completely achievable these days).
Matthias Hryniszak
Just to have everything under one thread... http://activemq.apache.org/nms is my preferred way these days of working with ActiveMQ now. the binary weights 73728 bytes. If you compare this with ~1.4MB you'll know what I mean.
Matthias Hryniszak