我有一个混合的Web应用程序,它在同一个Tomcat中运行Java WAR文件和JRuby WAR文件。Java到JRuby到Resque
我们决定使用(JRuby)Resque作为我们的工作队列。入队工作的调用看起来是这样的:
Resque.enqueue(FooWorker, 111)
其中FooWorker是定义和使用JRuby的侧(与包含在JRuby的WAR文件)工人类,它是由JRuby的Resque rake任务调用当它从队列中处理作业时。
我想给Java代码赋予Resque队列任务的能力,以便由JRuby FooWorker类处理。
我看了一下Tommy Cheng的代码https://github.com/tc/call-jruby-from-java-example。 Java文件
//JavaInterfaceExample.java
interface JavaInterfaceExample{
int add(int a, int b);
}
和红宝石文件
#JrubyAdderImpl.rb
require 'java'
class JrubyAdderImpl
include Java::JavaInterfaceExample
java_signature 'int add(int, int)'
def add(a, b)
a+b
end
end
我怀疑我的代码是这样: Java文件
//ResqueInterfaceExample.java
interface ResqueInterfaceExample{
int resque_enqueue_foojob(int a);
}
ruby文件
#JrubyResqueImpl.rb
require 'java'
require 'resque'
class JrubyResqueImpl
include Java::ResqueInterfaceExample
java_signature 'int resque_enqueue_foojob(int)'
def resque_enqueue_foojob(a)
Resque.enqueue(FooWorker, a)
end
end
我的FooWorker是一个类,它位于rails应用程序的分解的war文件目录中,并且该文件是app/workers/foo_worker.rb
我需要做些什么来确保jruby编译器可以同时访问FooWorker和Resque JRuby类能够正确地编译代码?
优秀!感谢您指出jesque – 2013-06-14 23:26:39