【问题标题】:Apache ActiveMQ access without Spring.NET没有 Spring.NET 的 Apache ActiveMQ 访问
【发布时间】:2010-09-22 10:42:55
【问题描述】:

我希望这里的某个人能够帮助我解决从 C# 与 ActiveMQ 集成的难题。这是我到目前为止所做的:

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();
    }
  }
}

非常基本的东西:只需创建一个连接工厂,然后使用它来创建连接并最后创建一个会话。现在,当我执行此代码时,这是被抛出的异常:

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

有人知道发生了什么吗?我正在使用 Apache ActiveMQ 5.2.0 版(从他们的网站上全新下载)。

【问题讨论】:

    标签: c# apache activemq


    【解决方案1】:

    我尝试了与您在这里完全相同的方法,它似乎有效。内部网络上的某个人回复了您在 Nabble 上的请求,说有一个错误(在哪里?)已修复。也许下载最新版本的 Apache.NMS/Apache.NMS.ActiveMQ 再试一次。

    Apache.NMS 附带Spring.NET - 这可能是获取 Apache.NMS 的最佳和最简单的方法。

    【讨论】:

    • 感谢您的洞察力,但正如问题标题中所述,我想在没有 Spring.NET 的情况下使用它。使用大小超过 25MB 的框架来发送和接收来自/到消息队列的消息似乎有点过头了。反正我会用spring自带的libs版本试试。
    • 酷,我很高兴这有效。我应该更清楚一点,我的意思是您可以从 Spring.NET 中获取 Apache.NMS,而无需其他部分。我在从 apache 下载和构建 activemq-dotnet 的东西时遇到了类似的问题。 Spring.NET 似乎做对了。
    • Uggg..问题是没有 Spring 的 ActiveMQ,答案是 Spring。
    • 我认为本次交流中的某些 cmets 可能已被删除或什么的。当我重新阅读它时,我的回答并不完全有意义。我想我想说的是你可以从 Spring 发行版中获取 Apache NMS 文件,但你不必使用 Spring。不过这是很久以前的事了,所以不确定事情是否发生了变化。
    【解决方案2】:

    好了,问题解决了。花了一段时间,但在 Andy White 发送的帖子的帮助下,我能够按照我想要的方式启动并运行它。

    当然,问题在于 http://svn.apache.org/viewvc/activemq/activemq-dotnet/ 上当前可用的那些库完全损坏并且根本无法工作。

    谢谢安迪!

    【讨论】:

    • 仅供参考:您不必使用整个 spring 框架来使用 ActiveMQ 连接。碰巧 Spring.NET 附带了这些库的编译版本。
    • 嗯,Apache 的二进制文件有什么问题?我在他们的 SVN 中使用了 tags/1.0.0/deploy/net-3.5/ 路径中的副本(参见上面的链接),它们对我来说工作得很好。
    【解决方案3】:

    只是为了回应评论“使用大小超过 25MB 的框架来发送和接收消息队列中的消息似乎有点过头了。”

    我当然同意,这确实是一个打包问题,我们包含针对 .NET 1.1 到 3.0(使用 .pdbs 进行调试和发布构建)参考文档、示例应用程序等的编译二进制文件。如果您查看创建基于 ActiveMQ NMS 的 Spring.NET 应用程序所需的 .dll 大小,它是

    Common.Logging 28KB、Spring.Aop 152KB、Spring.Core 744KB、Spring.Data 340KB 和 Spring.Messaging.Nns 104KB,总计约 1.4MB。

    标记

    【讨论】:

    • 嗯,...这当然更好,但访问 AtiveMQ 的依赖项数量仍然是多余的。例如,如果我正在使用其他一些 DI 框架(此时 Ninject 是我的个人偏好),包括 Spring.Aop 和 Spring.Core 有点味道。
    • 我知道将所有东西都放在 Spring 保护伞下是设计决定。我喜欢保持紧密联系在一起的事物。如果 Spring.Data 或 Spring.Aop 接近 Spring.Messaging.Nns 是一个品味问题 - 这肯定不是最令人惊讶的选择。
    • 我最喜欢的一个选项是让 Apache ActiveMQ 的人发布一些东西,比如 Apache.ActiveMQ.Client.dll,这将为我提供从这个源发送/接收消息所需的一切并且会低于 100k(这在当今是完全可以实现的)。
    • 只是把所有东西都放在一个线程下...activemq.apache.org/nms 是我现在使用 ActiveMQ 的首选方式。二进制权重 73728 字节。如果您将其与 ~1.4MB 进行比较,您就会明白我的意思。
    猜你喜欢
    • 1970-01-01
    • 2021-05-12
    • 2013-03-28
    • 2012-09-24
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    相关资源
    最近更新 更多