[英]Converting Java code to JRuby
I'm using some Java code in a JRuby project for connecting to MQ. 我在JRuby项目中使用一些Java代码来连接到MQ。 I'm new in Java and don't know how the following statements of Java can be used in JRuby.
我是Java的新手,不知道如何在JRuby中使用以下Java语句。
QueueConnection con = factory.createQueueConnection();
QueueSession session = con.createQueueSession(false, session.AUTO_ACKNOWLEDGE);
session.start();
Where QueueConnection and QueueSession are Java classes that are imported on top 其中QueueConnection和QueueSession是在顶部导入的Java类
java_import javax.jms.QueueConnection
java_import javax.jms.QueueSession
Thanks 谢谢
In Java: 在Java中:
QueueConnection con = ...
means the variable con
is of type QueueConnection
. QueueConnection con = ...
表示变量con
为QueueConnection
类型。 Types exists in Ruby too but they are not explicit, so you would simply say con = ...
. con = ...
。 Additionally, the code you show is not quite correct, as the session
variable is used in session.AUTO_ACKNOWLEDGE
before it is declared. 此外,您显示的代码不是很正确,因为在声明
session
之前, session.AUTO_ACKNOWLEDGE
使用了session
变量。 AUTO_ACKNOWLEDGE
is a static field of the QueueSession
class, so the code should read QueueSession.AUTO_ACKNOWLEDGE
. AUTO_ACKNOWLEDGE
是QueueSession
类的静态字段,因此代码应读取QueueSession.AUTO_ACKNOWLEDGE
。 In JRuby, static fields can be accessed using the ::
syntax instead of .
在JRuby中,可以使用
::
语法代替来访问静态字段.
. 。
I would therefore guess that the equivalent JRuby code of your snippet is something like this: 因此,我想您的片段的等效JRuby代码是这样的:
con = factory.createQueueConnection()
session = con.createQueueSession(false, QueueSession::AUTO_ACKNOWLEDGE)
session.start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.