【发布时间】:2012-03-06 04:39:03
【问题描述】:
我有一个混合 Web 应用程序,它在同一个 Tomcat 中运行一个 Java WAR 文件和一个 JRuby WAR 文件。
我们决定使用 (JRuby) Resque 作为我们的作业队列。排队作业的调用如下所示:
Resque.enqueue(FooWorker, 111)
其中 FooWorker 是在 JRuby 端定义和使用的工作类(并包含在 JRuby WAR 文件中),它由 JRuby Resque rake 任务在处理队列中的作业时调用。
我想让 Java 代码能够将任务排入 Resque 队列以由 JRuby FooWorker 类处理。
我在https://github.com/tc/call-jruby-from-java-example查看了Tommy Cheng的代码。
//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
我怀疑我的代码看起来像:
//ResqueInterfaceExample.java
interface ResqueInterfaceExample{
int resque_enqueue_foojob(int a);
}
#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 类以正确编译代码?
【问题讨论】:
标签: ruby jruby resque jrubyonrails jruby-java-interop