0

I'm using some Java code in a JRuby project for connecting to MQ. I'm new in Java and don't know how the following statements of Java can be used in JRuby.

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

java_import javax.jms.QueueConnection
java_import javax.jms.QueueSession

Thanks

1 Answer 1

1

In Java:

  • Variable must declare their type. QueueConnection con = ... means the variable con is of type QueueConnection. Types exists in Ruby too but they are not explicit, so you would simply say con = ....
  • Statements must be ended by semi-colons. They are not required in Ruby.

Additionally, the code you show is not quite correct, as the session variable is used in session.AUTO_ACKNOWLEDGE before it is declared. AUTO_ACKNOWLEDGE is a static field of the QueueSession class, so the code should read QueueSession.AUTO_ACKNOWLEDGE. In JRuby, static fields can be accessed using the :: syntax instead of ..

I would therefore guess that the equivalent JRuby code of your snippet is something like this:

con = factory.createQueueConnection()
session = con.createQueueSession(false, QueueSession::AUTO_ACKNOWLEDGE)
session.start()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.