`
fsword
  • 浏览: 165238 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ruby 与 activemq 集成初探

阅读更多
(今天一天就这么些结果,唉,真没效率......)

这个事情起因于公司的一个短信产品,老实说,我们这些门外汉做的实在不怎么样,加上进度控制的不好,前前后后又把人调来调去,现在是一个外包的哥们帮我一起擦屁股。

东西好改,不过web层面的jsp实在是太乱了,struts2也用的不好,中间我又要求加入了一些比较复杂的动态能力,现在jsp已经快要人见人厌了。

这个软件骨子里是一个消息为中心的产品,java当然是jms,不过前一阵研究activemq时发现它可以通过stomp支持ruby,这可是让人高兴的事情,一直觉得ruby/rails适合前端,如果用消息系统进行解耦,那就完美了,于是研究一下

ruby自己的stomp库挺简单的,但是与jms集成就没什么参考文章了,activemq网站推荐用activemessaging这个插件来封装,于是试了一下,一开始挺简单,但是有个错误:
adapter wmq not loaded: no such file to load -- wmq/wmq


查了一下,有个老外说是load顺序问题,解决办法是注释掉 poller.rb 中的
require 'activemessaging'


然后就可以用了,不过发现这样拿不到MapMessage对象的数据,把传给on_message的对象打出来看看:
  def on_message(message)
    p "HelloProcessor received: " + message.inspect
  end

发现是个空字符串,奇怪,就算没有对应的对象,JMS本身的信息为什么也没有?

读代码,原来被封装掉了,参见activemessaging的processor.rb :
      @message = message
      return on_message(message.body)

详细看看,原来stomp和jms的对应还有些问题,TextMessage和BytesMessage的处理是用Content-Length来区分的:

引用
ActiveMQ uses the content-length header to determine if a Stomp message should be mapped to a JMS TextMessage or a BytesMessage (http://activemq.apache.org/stomp.html) - if a Stomp message contains a content-length header field it will be converted to a BytesMessage otherwise it will be converted to a TextMessage.


看来activemessaging是一个比较脱离JMS技术细节的封装,可是我要充分利用它本身的特性,看来此路不通,需要直接搞stomp才行。

另外还有个遗留问题,不知道有没有人了解情况:
activemessaging的输出日志有这么一段话:
引用

#<MissingSourceFile: no such file to load -- Win32API>
*** below you find all exception objects found in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***
#<NoMemoryError: failed to allocate memory>
#<SystemStackError: stack level too deep>
#<fatal: exception reentered>
#<Errno::ENOENT: No such file or directory - /home/john/NetBeansProjects/amq/tmp/poller0.pid>
#<ActiveMessaging::StopProcessingException: Time to stop.>

感觉很诡异,为什么ubuntu上会要求Win32API呢?

0
0
分享到:
评论
1 楼 fsword 2009-07-29  
考虑看看amqp了,这个玩意不错,erlang做broker,ruby、java都有client,不知道api的设计是否够简洁。

相关推荐

Global site tag (gtag.js) - Google Analytics